use of org.springframework.cloud.config.environment.PropertySource 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.PropertySource 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.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method whenPlaceholdersSystemProps.
private void whenPlaceholdersSystemProps() {
System.setProperty("foo", "bar");
this.environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c", "${foo}")));
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method arrayInYaml.
@Test
public void arrayInYaml() throws Exception {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("a.b[0]", "c");
map.put("a.b[1]", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertEquals("a:\n b:\n - c\n - d\n", yaml);
}
use of org.springframework.cloud.config.environment.PropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentControllerTests method arrayObObjectAtTopLevelInYaml.
@Test
public void arrayObObjectAtTopLevelInYaml() throws Exception {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("document[0].a", "c");
map.put("document[1].a", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar", false).getBody();
assertEquals("- a: c\n- a: d\n", yaml);
}
Aggregations