use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class NativeEnvironmentRepositoryTests method locationAddLabelLocations.
@Test
public void locationAddLabelLocations() {
this.repository.setSearchLocations("classpath:/test/dev/");
Environment environment = this.repository.findOne("foo", "development", "ignore");
assertEquals(2, environment.getPropertySources().size());
assertNotEquals("dev_bar", environment.getPropertySources().get(0).getSource().get("foo"));
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class NativeEnvironmentRepositoryTests method placeholdersProfile.
@Test
public void placeholdersProfile() {
this.repository.setSearchLocations("classpath:/test/{profile}/");
Environment environment = this.repository.findOne("foo", "dev", "master");
assertEquals(1, environment.getPropertySources().size());
assertEquals("dev_bar", environment.getPropertySources().get(0).getSource().get("foo"));
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class SVNKitEnvironmentRepositoryTests method branch_no_folder.
@Test
public void branch_no_folder() {
Environment environment = this.repository.findOne("bar", "staging", "demobranch");
assertEquals(1, environment.getPropertySources().size());
assertTrue(environment.getPropertySources().get(0).getName().contains("bar.properties"));
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class SVNKitEnvironmentRepositoryTests method branch.
@Test
public void branch() {
Environment environment = this.repository.findOne("bar", "staging", "branches/demobranch");
assertEquals(1, environment.getPropertySources().size());
assertTrue(environment.getPropertySources().get(0).getName().contains("bar.properties"));
}
use of org.springframework.cloud.config.environment.Environment in project spring-cloud-config by spring-cloud.
the class VaultEnvironmentRepositoryTests method testFindOneDefaultKeySetAndDifferentToApplication.
@Test
public void testFindOneDefaultKeySetAndDifferentToApplication() throws IOException {
MockHttpServletRequest configRequest = new MockHttpServletRequest();
configRequest.addHeader("X-CONFIG-TOKEN", "mytoken");
RestTemplate rest = Mockito.mock(RestTemplate.class);
ResponseEntity<VaultEnvironmentRepository.VaultResponse> myAppResp = Mockito.mock(ResponseEntity.class);
Mockito.when(myAppResp.getStatusCode()).thenReturn(HttpStatus.OK);
VaultEnvironmentRepository.VaultResponse myAppVaultResp = Mockito.mock(VaultEnvironmentRepository.VaultResponse.class);
Mockito.when(myAppVaultResp.getData()).thenReturn("{\"foo\":\"bar\"}");
Mockito.when(myAppResp.getBody()).thenReturn(myAppVaultResp);
Mockito.when(rest.exchange(Mockito.eq("http://127.0.0.1:8200/v1/{backend}/{key}"), Mockito.eq(HttpMethod.GET), Mockito.any(HttpEntity.class), Mockito.eq(VaultEnvironmentRepository.VaultResponse.class), Mockito.eq("secret"), Mockito.eq("myapp"))).thenReturn(myAppResp);
ResponseEntity<VaultEnvironmentRepository.VaultResponse> myDefaultKeyResp = Mockito.mock(ResponseEntity.class);
Mockito.when(myDefaultKeyResp.getStatusCode()).thenReturn(HttpStatus.OK);
VaultEnvironmentRepository.VaultResponse myDefaultKeyVaultResp = Mockito.mock(VaultEnvironmentRepository.VaultResponse.class);
Mockito.when(myDefaultKeyVaultResp.getData()).thenReturn("{\"def-foo\":\"def-bar\"}");
Mockito.when(myDefaultKeyResp.getBody()).thenReturn(myDefaultKeyVaultResp);
Mockito.when(rest.exchange(Mockito.eq("http://127.0.0.1:8200/v1/{backend}/{key}"), Mockito.eq(HttpMethod.GET), Mockito.any(HttpEntity.class), Mockito.eq(VaultEnvironmentRepository.VaultResponse.class), Mockito.eq("secret"), Mockito.eq("mydefaultkey"))).thenReturn(myDefaultKeyResp);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties());
repo.setDefaultKey("mydefaultkey");
Environment e = repo.findOne("myapp", null, null);
assertEquals("Name should be the same as the application argument", "myapp", e.getName());
assertEquals("Properties for specified application and default application with key 'mydefaultkey' should be returned", 2, e.getPropertySources().size());
Map<String, String> firstResult = new HashMap<String, String>();
firstResult.put("foo", "bar");
assertEquals("Properties for specified application should be returned in priority position", firstResult, e.getPropertySources().get(0).getSource());
Map<String, String> secondResult = new HashMap<String, String>();
secondResult.put("def-foo", "def-bar");
assertEquals("Properties for default application with key 'mydefaultkey' should be returned in second position", secondResult, e.getPropertySources().get(1).getSource());
}
Aggregations