Search in sources :

Example 26 with Environment

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"));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 27 with Environment

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"));
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 28 with Environment

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"));
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 29 with Environment

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"));
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Example 30 with Environment

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());
}
Also used : HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) RestTemplate(org.springframework.web.client.RestTemplate) Environment(org.springframework.cloud.config.environment.Environment) Test(org.junit.Test)

Aggregations

Environment (org.springframework.cloud.config.environment.Environment)118 Test (org.junit.Test)104 StandardEnvironment (org.springframework.core.env.StandardEnvironment)37 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)20 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)19 PropertySource (org.springframework.cloud.config.environment.PropertySource)12 LinkedHashMap (java.util.LinkedHashMap)9 File (java.io.File)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)7 FileOutputStream (java.io.FileOutputStream)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)4 EnvironmentPropertySource.prepareEnvironment (org.springframework.cloud.config.server.support.EnvironmentPropertySource.prepareEnvironment)4 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)4 HttpEntity (org.springframework.http.HttpEntity)4 RestTemplate (org.springframework.web.client.RestTemplate)4 Git (org.eclipse.jgit.api.Git)3 Matchers.anyString (org.mockito.Matchers.anyString)3