List of usage examples for org.springframework.data.mongodb.core MongoTemplate findAll
@Override
public <T> List<T> findAll(Class<T> entityClass, String collectionName)
From source file:eu.trentorise.smartcampus.mobility.util.GamificationHelper.java
public static void main(String[] args) throws UnknownHostException, MongoException, SecurityException, RemoteException { MongoTemplate mg = new MongoTemplate(new Mongo("127.0.0.1", 37017), "mobility-logging"); List<Map> findAll = mg.findAll(Map.class, "forgamification"); for (Map m : findAll) { m.remove("_id"); RemoteConnector.postJSON("http://localhost:8900", "/execute", JsonUtils.toJSON(m), null); }/*from w ww. j av a2s . c o m*/ }
From source file:com.comcast.video.dawg.service.pound.DawgPoundMongoServiceTest.java
@Test public void testListAllDevicesReturnsEmptyList() { MongoTemplate mockMongoTemplate = EasyMock.createMock(MongoTemplate.class); DawgPoundMongoService dawgPoundService = new DawgPoundMongoService(); ReflectionTestUtils.setField(dawgPoundService, "mongoTemplate", mockMongoTemplate); List<PersistableDevice> devices = new ArrayList<PersistableDevice>(); EasyMock.expect(mockMongoTemplate.findAll(PersistableDevice.class, TestConstants.COLLECTION_NAME)) .andReturn(devices);// w w w . j av a2 s .co m EasyMock.replay(mockMongoTemplate); Assert.assertEquals(dawgPoundService.list().length, 0); EasyMock.verify(mockMongoTemplate); }
From source file:com.avanza.ymer.YmerInitialLoadIntegrationTest.java
@Test public void migratesOldDocumentOnInitialLoad() throws Exception { BasicDBObject spaceObjectV1 = new BasicDBObject(); spaceObjectV1.put("_id", "id_v1"); spaceObjectV1.put("message", "Msg_V1"); BasicDBObject spaceObjectV2 = new BasicDBObject(); spaceObjectV2.put("_id", "id_v2"); spaceObjectV2.put("message", "Msg_V2"); spaceObjectV2.put(MirroredObject.DOCUMENT_FORMAT_VERSION_PROPERTY, 2); BasicDBObject spaceOtherObject = new BasicDBObject(); spaceOtherObject.put("_id", "otherId"); spaceOtherObject.put("message", "Msg_V1"); MongoTemplate mongoTemplate = mirrorEnv.getMongoTemplate(); mongoTemplate.getCollection(mirroredObject.getCollectionName()).insert(spaceObjectV1); mongoTemplate.getCollection(mirroredObject.getCollectionName()).insert(spaceObjectV2); mongoTemplate.getCollection(mirroredOtherDocument.getCollectionName()).insert(spaceOtherObject); pu.start();//from w w w . ja va 2 s . c o m // Verify SpaceObject GigaSpace gigaSpace = pu.getClusteredGigaSpace(); assertEquals(2, gigaSpace.count(new TestSpaceObject())); TestSpaceObject testSpaceObject = gigaSpace.readById(TestSpaceObject.class, "id_v1"); assertEquals("patched_Msg_V1", testSpaceObject.getMessage()); List<BasicDBObject> allDocs = mongoTemplate.findAll(BasicDBObject.class, mirroredObject.getCollectionName()); assertEquals(2, allDocs.size()); assertEquals(2, mirroredObject.getDocumentVersion(allDocs.get(0))); assertEquals(2, mirroredObject.getDocumentVersion(allDocs.get(1))); // Verify SpaceOtherObject assertEquals(1, gigaSpace.count(new TestSpaceOtherObject())); TestSpaceOtherObject testSpaceOtherObject = gigaSpace.readById(TestSpaceOtherObject.class, "otherId"); assertEquals("patched_Msg_V1", testSpaceOtherObject.getMessage()); List<BasicDBObject> allOtherDocs = mongoTemplate.findAll(BasicDBObject.class, mirroredOtherDocument.getCollectionName()); assertEquals(1, allOtherDocs.size()); assertEquals(1, mirroredOtherDocument.getDocumentVersion(allOtherDocs.get(0))); }
From source file:com.comcast.video.dawg.service.pound.DawgPoundMongoServiceTest.java
@Test public void testListAllDevices() { MongoTemplate mockMongoTemplate = EasyMock.createMock(MongoTemplate.class); DawgPoundMongoService dawgPoundService = new DawgPoundMongoService(); ReflectionTestUtils.setField(dawgPoundService, "mongoTemplate", mockMongoTemplate); List<PersistableDevice> devices = new ArrayList<PersistableDevice>(); PersistableDevice device1 = EasyMock.createMock(PersistableDevice.class); PersistableDevice device2 = EasyMock.createMock(PersistableDevice.class); Map<String, Object> dev1Map = new HashMap<String, Object>(); Map<String, Object> dev2Map = new HashMap<String, Object>(); devices.add(device1);/* ww w . j ava 2 s . c o m*/ devices.add(device2); dev1Map.put("id", TestConstants.DEVICE_ID); dev2Map.put("id", "000000682A48"); EasyMock.expect(mockMongoTemplate.findAll(PersistableDevice.class, TestConstants.COLLECTION_NAME)) .andReturn(devices); EasyMock.expect(device1.getData()).andReturn(dev1Map); EasyMock.expect(device2.getData()).andReturn(dev2Map); EasyMock.replay(mockMongoTemplate, device1, device2); Map<String, Object>[] list = dawgPoundService.list(); Assert.assertEquals(list.length, 2); Assert.assertEquals(list[0].get("id"), TestConstants.DEVICE_ID); Assert.assertEquals(list[1].get("id"), "000000682A48"); EasyMock.verify(mockMongoTemplate, device1, device2); }