List of usage examples for org.springframework.data.mongodb.core.mapping DetectedCollectionWithIndex DetectedCollectionWithIndex
public DetectedCollectionWithIndex(String name)
From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java
@Test public void testIndexesCreatedInRightCollection() { CustomCollectionWithIndex ccwi = new CustomCollectionWithIndex("test"); template.insert(ccwi);/* w w w. j av a 2 s . c o m*/ assertTrue(template.execute("foobar", new CollectionCallback<Boolean>() { public Boolean doInCollection(DBCollection collection) throws MongoException, DataAccessException { List<DBObject> indexes = collection.getIndexInfo(); for (DBObject dbo : indexes) { if (dbo.get("name") != null && dbo.get("name") instanceof String && ((String) dbo.get("name")).startsWith("name")) { return true; } } return false; } })); DetectedCollectionWithIndex dcwi = new DetectedCollectionWithIndex("test"); template.insert(dcwi); assertTrue( template.execute(MongoCollectionUtils.getPreferredCollectionName(DetectedCollectionWithIndex.class), new CollectionCallback<Boolean>() { public Boolean doInCollection(DBCollection collection) throws MongoException, DataAccessException { List<DBObject> indexes = collection.getIndexInfo(); for (DBObject dbo : indexes) { if (dbo.get("name") != null && dbo.get("name") instanceof String && ((String) dbo.get("name")).startsWith("name")) { return true; } } return false; } })); }