Java Code Examples for org.springframework.data.mongodb.core.MongoTemplate#dropCollection()
The following examples show how to use
org.springframework.data.mongodb.core.MongoTemplate#dropCollection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoEnvironmentRepositoryTests.java From spring-cloud-config-server-mongodb with Apache License 2.0 | 6 votes |
@Test public void defaultRepo() { // Prepare context Map<String, Object> props = new HashMap<>(); props.put("spring.data.mongodb.database", "testdb"); context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties(props).run(); // Prepare test MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class); mongoTemplate.dropCollection("testapp"); MongoPropertySource ps = new MongoPropertySource(); ps.getSource().put("testkey", "testval"); mongoTemplate.save(ps, "testapp"); // Test EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); Environment environment = repository.findOne("testapp", "default", null); assertEquals("testapp-default", environment.getPropertySources().get(0).getName()); assertEquals(1, environment.getPropertySources().size()); assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("testkey")); assertEquals("testval", environment.getPropertySources().get(0).getSource().get("testkey")); }
Example 2
Source File: MongoEnvironmentRepositoryTests.java From spring-cloud-config-server-mongodb with Apache License 2.0 | 6 votes |
@Test public void nestedPropertySource() { // Prepare context Map<String, Object> props = new HashMap<>(); props.put("spring.data.mongodb.database", "testdb"); context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties(props).run(); // Prepare test MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class); mongoTemplate.dropCollection("testapp"); MongoPropertySource ps = new MongoPropertySource(); Map<String, String> inner = new HashMap<String, String>(); inner.put("inner", "value"); ps.getSource().put("outer", inner); mongoTemplate.save(ps, "testapp"); // Test EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); Environment environment = repository.findOne("testapp", "default", null); assertEquals("testapp-default", environment.getPropertySources().get(0).getName()); assertEquals(1, environment.getPropertySources().size()); assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("outer.inner")); assertEquals("value", environment.getPropertySources().get(0).getSource().get("outer.inner")); }
Example 3
Source File: MongoEnvironmentRepositoryTests.java From spring-cloud-config-server-mongodb with Apache License 2.0 | 6 votes |
@Test public void repoWithProfileAndLabelInSource() { // Prepare context Map<String, Object> props = new HashMap<>(); props.put("spring.data.mongodb.database", "testdb"); context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE).properties(props).run(); // Prepare test MongoTemplate mongoTemplate = this.context.getBean(MongoTemplate.class); mongoTemplate.dropCollection("testapp"); MongoPropertySource ps = new MongoPropertySource(); ps.setProfile("confprofile"); ps.setLabel("conflabel"); ps.getSource().put("profile", "sourceprofile"); ps.getSource().put("label", "sourcelabel"); mongoTemplate.save(ps, "testapp"); // Test EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class); Environment environment = repository.findOne("testapp", "confprofile", "conflabel"); assertEquals(1, environment.getPropertySources().size()); assertEquals("testapp-confprofile-conflabel", environment.getPropertySources().get(0).getName()); assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("profile")); assertEquals("sourceprofile", environment.getPropertySources().get(0).getSource().get("profile")); assertEquals(true, environment.getPropertySources().get(0).getSource().containsKey("label")); assertEquals("sourcelabel", environment.getPropertySources().get(0).getSource().get("label")); }
Example 4
Source File: MongodbDataProviderEngineTest.java From n2o-framework with Apache License 2.0 | 5 votes |
@BeforeAll public void init() { engine.setConnectionUrl("mongodb://localhost:" + port); engine.setDatabaseName("dbName"); engine.setMapper(mongoObjectMapper()); provider = new N2oMongoDbDataProvider(); provider.setCollectionName(collectionName); MongoTemplate mongoTemplate = new MongoTemplate(new MongoClient(new MongoClientURI("mongodb://localhost:" + port)), "dbName"); mongoTemplate.dropCollection(collectionName); mongoTemplate.createCollection(collectionName); mongoTemplate.getCollection(collectionName).insertMany(TestUserBuilder.testData()); }
Example 5
Source File: UserServiceTest.java From maven-framework-project with MIT License | 5 votes |
@BeforeClass public static void setup() throws Exception { // test 시작전 collection 제거 Mongo mongo = new Mongo("localhost"); MongoTemplate mongoTemplate = new MongoTemplate(mongo, "testdb"); mongoTemplate.dropCollection("testcollect"); }
Example 6
Source File: ApplicationConfiguration.java From spring-data-examples with Apache License 2.0 | 4 votes |
@Bean CommandLineRunner init(MongoTemplate template) { return (args) -> { if (template.collectionExists(COLLECTION)) { template.dropCollection(COLLECTION); } GeospatialIndex index = new GeospatialIndex("homePlanet.coordinates") // .typed(GeoSpatialIndexType.GEO_2DSPHERE) // .named("planet-coordinate-idx"); template.createCollection(COLLECTION); template.indexOps(SWCharacter.class).ensureIndex(index); Planet alderaan = new Planet("alderaan", new Point(-73.9667, 40.78)); Planet stewjon = new Planet("stewjon", new Point(-73.9836, 40.7538)); Planet tatooine = new Planet("tatooine", new Point(-73.9928, 40.7193)); Jedi anakin = new Jedi("anakin", "skywalker"); anakin.setHomePlanet(tatooine); Jedi luke = new Jedi("luke", "skywalker"); luke.setHomePlanet(tatooine); Jedi leia = new Jedi("leia", "organa"); leia.setHomePlanet(alderaan); Jedi obiWan = new Jedi("obi-wan", "kenobi"); obiWan.setHomePlanet(stewjon); Human han = new Human("han", "solo"); template.save(anakin, COLLECTION); template.save(luke, COLLECTION); template.save(leia, COLLECTION); template.save(obiWan, COLLECTION); template.save(han, COLLECTION); }; }