Java Code Examples for org.springframework.cloud.config.server.environment.EnvironmentRepository#findOne()

The following examples show how to use org.springframework.cloud.config.server.environment.EnvironmentRepository#findOne() . 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 vote down vote up
@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 vote down vote up
@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 vote down vote up
@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"));
}