use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class CompositeEnvironmentRepositoryTests method testOrder.
@Test
public void testOrder() {
PropertySource p1 = mock(PropertySource.class);
doReturn("p1").when(p1).getName();
PropertySource p2 = mock(PropertySource.class);
doReturn("p2").when(p2).getName();
PropertySource p3 = mock(PropertySource.class);
doReturn("p3").when(p3).getName();
PropertySource p4 = mock(PropertySource.class);
doReturn("p4").when(p4).getName();
PropertySource p5 = mock(PropertySource.class);
doReturn("p5").when(p5).getName();
String sLoc1 = "loc1";
String sLoc2 = "loc2";
String sLoc3 = "loc3";
String sLoc4 = "loc4";
String sLoc5 = "loc5";
Environment e1 = new Environment("app", "dev");
e1.add(p1);
e1.add(p5);
Environment e2 = new Environment("app", "dev");
e2.add(p2);
Environment e3 = new Environment("app", "dev");
e3.add(p3);
e3.add(p4);
SearchPathLocator.Locations loc1 = new SearchPathLocator.Locations("app", "dev", "label", "version", new String[] { sLoc1 });
SearchPathLocator.Locations loc2 = new SearchPathLocator.Locations("app", "dev", "label", "version", new String[] { sLoc5, sLoc4 });
SearchPathLocator.Locations loc3 = new SearchPathLocator.Locations("app", "dev", "label", "version", new String[] { sLoc3, sLoc2 });
List<EnvironmentRepository> repos = new ArrayList<EnvironmentRepository>();
repos.add(new TestOrderedEnvironmentRepository(3, e1, loc1));
repos.add(new TestOrderedEnvironmentRepository(2, e3, loc2));
repos.add(new TestOrderedEnvironmentRepository(1, e2, loc3));
SearchPathCompositeEnvironmentRepository compositeRepo = new SearchPathCompositeEnvironmentRepository(repos);
Environment compositeEnv = compositeRepo.findOne("foo", "bar", "world");
List<PropertySource> propertySources = compositeEnv.getPropertySources();
assertEquals(5, propertySources.size());
assertEquals("p2", propertySources.get(0).getName());
assertEquals("p3", propertySources.get(1).getName());
assertEquals("p4", propertySources.get(2).getName());
assertEquals("p1", propertySources.get(3).getName());
assertEquals("p5", propertySources.get(4).getName());
SearchPathLocator.Locations locations = compositeRepo.getLocations("app", "dev", "label");
String[] locationStrings = locations.getLocations();
assertEquals(5, locationStrings.length);
assertEquals(sLoc3, locationStrings[0]);
assertEquals(sLoc2, locationStrings[1]);
assertEquals(sLoc5, locationStrings[2]);
assertEquals(sLoc4, locationStrings[3]);
assertEquals(sLoc1, locationStrings[4]);
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class CompositeEnvironmentRepositoryTests method testVersion.
@Test
public void testVersion() {
PropertySource p1 = mock(PropertySource.class);
doReturn("p1").when(p1).getName();
PropertySource p2 = mock(PropertySource.class);
doReturn("p2").when(p2).getName();
String sLoc1 = "loc1";
String sLoc2 = "loc2";
Environment e1 = new Environment("app", "dev");
e1.add(p1);
e1.setVersion("1");
e1.setState("state");
Environment e2 = new Environment("app", "dev");
e2.add(p2);
e2.setVersion("2");
e2.setState("state2");
SearchPathLocator.Locations loc1 = new SearchPathLocator.Locations("app", "dev", "label", "version", new String[] { sLoc1 });
SearchPathLocator.Locations loc2 = new SearchPathLocator.Locations("app", "dev", "label", "version", new String[] { sLoc1, sLoc2 });
List<EnvironmentRepository> repos = new ArrayList<EnvironmentRepository>();
repos.add(new TestOrderedEnvironmentRepository(3, e1, loc1));
List<EnvironmentRepository> repos2 = new ArrayList<EnvironmentRepository>();
repos2.add(new TestOrderedEnvironmentRepository(3, e1, loc1));
repos2.add(new TestOrderedEnvironmentRepository(3, e2, loc2));
SearchPathCompositeEnvironmentRepository compositeRepo = new SearchPathCompositeEnvironmentRepository(repos);
SearchPathCompositeEnvironmentRepository multiCompositeRepo = new SearchPathCompositeEnvironmentRepository(repos2);
Environment env = compositeRepo.findOne("app", "dev", "label");
assertEquals("1", env.getVersion());
assertEquals("state", env.getState());
Environment multiEnv = multiCompositeRepo.findOne("app", "dev", "label");
assertEquals(null, multiEnv.getVersion());
assertEquals(null, multiEnv.getState());
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method arrayOverridenInEnvironment.
@Test
public void arrayOverridenInEnvironment() throws Exception {
// Add original values first source
Map<String, Object> oneMap = new LinkedHashMap<String, Object>();
oneMap.put("a.b[0]", "c");
oneMap.put("a.b[1]", "d");
oneMap.put("a.b[2]", "z");
this.environment.add(new PropertySource("one", oneMap));
// Add overridden values in second source
Map<String, Object> twoMap = new LinkedHashMap<String, Object>();
twoMap.put("a.b[0]", "f");
twoMap.put("a.b[1]", "h");
this.environment.addFirst(new PropertySource("two", twoMap));
Mockito.when(this.repository.findOne("foo", "bar", "two")).thenReturn(this.environment);
Environment environment = this.controller.labelled("foo", "bar", "two");
assertThat(environment, not(nullValue()));
assertThat(environment.getName(), equalTo("foo"));
assertThat(environment.getProfiles(), equalTo(new String[] { "master" }));
assertThat(environment.getLabel(), equalTo("master"));
assertThat(environment.getVersion(), nullValue());
assertThat(environment.getPropertySources(), hasSize(2));
assertThat(environment.getPropertySources().get(0).getName(), equalTo("two"));
assertThat(environment.getPropertySources().get(0).getSource().entrySet(), hasSize(2));
assertThat(environment.getPropertySources().get(1).getName(), equalTo("one"));
assertThat(environment.getPropertySources().get(1).getSource().entrySet(), hasSize(3));
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerIntegrationTests method environmentNoLabel.
@Test
public void environmentNoLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", null)).thenReturn(new Environment("foo", "default"));
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default")).andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", null);
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerIntegrationTests method propertiesLabelWithSlash.
@Test
public void propertiesLabelWithSlash() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "label/spam")).thenReturn(new Environment("foo", "default"));
this.mvc.perform(MockMvcRequestBuilders.get("/label(_)spam/foo-default.properties")).andExpect(MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", "label/spam");
}
Aggregations