gh-2217 converted all Junit 4 test cases to Junit 5 (#2218)

* gh-2217 converted all Junit 4 test cases to Junit 5

* Added the junit platform launcher in the test scope to fix unit test case issues

* added the Junit platform launcher in test scope.
This commit is contained in:
Krishna
2023-02-01 20:44:08 +05:30
committed by GitHub
parent 3fcf9ac6f3
commit b66f23b03b
108 changed files with 833 additions and 938 deletions

View File

@@ -92,8 +92,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -21,7 +21,7 @@ import java.io.FileOutputStream;
import java.io.OutputStream;
import java.security.KeyStore;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
public abstract class AbstractTlsSetup {
@@ -41,7 +41,7 @@ public abstract class AbstractTlsSetup {
protected static File wrongClientCert;
@BeforeClass
@BeforeAll
public static void createCertificates() throws Exception {
KeyTool tool = new KeyTool();

View File

@@ -18,9 +18,10 @@ package org.springframework.cloud.config.client.tls;
import java.io.File;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -32,12 +33,12 @@ public class ConfigClientTlsTests extends AbstractTlsSetup {
protected static TlsConfigServerRunner server;
@BeforeClass
@BeforeAll
public static void setupAll() throws Exception {
startConfigServer();
}
@AfterClass
@AfterAll
public static void tearDownAll() {
stopConfigServer();
}
@@ -96,20 +97,24 @@ public class ConfigClientTlsTests extends AbstractTlsSetup {
}
}
@Test(expected = IllegalStateException.class)
@Test
public void wrongPasswordCauseFailure() {
TlsConfigClientRunner client = createConfigClient(false);
enableTlsClient(client);
client.setKeyStore(clientCert, WRONG_PASSWORD, WRONG_PASSWORD);
client.start();
Assertions.assertThrows(IllegalStateException.class, () -> {
TlsConfigClientRunner client = createConfigClient(false);
enableTlsClient(client);
client.setKeyStore(clientCert, WRONG_PASSWORD, WRONG_PASSWORD);
client.start();
});
}
@Test(expected = IllegalStateException.class)
@Test
public void nonExistKeyStoreCauseFailure() {
TlsConfigClientRunner client = createConfigClient(false);
enableTlsClient(client);
client.setKeyStore(new File("nonExistFile"));
client.start();
Assertions.assertThrows(IllegalStateException.class, () -> {
TlsConfigClientRunner client = createConfigClient(false);
enableTlsClient(client);
client.setKeyStore(new File("nonExistFile"));
client.start();
});
}
@Test

View File

@@ -86,8 +86,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -19,9 +19,7 @@ package org.springframework.cloud.config.client;
import java.util.Arrays;
import java.util.Collections;
import org.junit.After;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.AfterEach;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -41,16 +39,13 @@ import static org.springframework.cloud.config.client.ConfigClientProperties.Dis
public abstract class BaseDiscoveryClientConfigServiceBootstrapConfigurationTests {
@Rule
public ExpectedException expectedException = ExpectedException.none();
protected AnnotationConfigApplicationContext context;
protected DiscoveryClient client = Mockito.mock(DiscoveryClient.class);
protected ServiceInstance info = new DefaultServiceInstance("app:8877", "app", "foo", 8877, false);
@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();
@@ -74,11 +69,6 @@ public abstract class BaseDiscoveryClientConfigServiceBootstrapConfigurationTest
.willReturn(Collections.<ServiceInstance>emptyList()).willReturn(Collections.singletonList(this.info));
}
void expectNoInstancesOfConfigServerException() {
this.expectedException.expect(IllegalStateException.class);
this.expectedException.expectMessage("No instances found of configserver (" + DEFAULT_CONFIG_SERVER + ")");
}
void expectDiscoveryClientConfigServiceBootstrapConfigurationIsSetup() {
assertThat(this.context.getBeanNamesForType(DiscoveryClientConfigServiceBootstrapConfiguration.class).length)
.isEqualTo(1);

View File

@@ -16,9 +16,8 @@
package org.springframework.cloud.config.client;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.cloud.config.client.ConfigClientProperties.Credentials;
@@ -35,9 +34,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class ConfigClientPropertiesTests {
@Rule
public ExpectedException expected = ExpectedException.none();
private ConfigClientProperties locator = new ConfigClientProperties(new StandardEnvironment());
@Test
@@ -149,26 +145,26 @@ public class ConfigClientPropertiesTests {
@Test
public void checkIfExceptionThrownForNegativeIndex() {
this.locator.setUri(new String[] { "http://localhost:8888", "http://localhost:8889" });
this.expected.expect(IllegalStateException.class);
this.expected.expectMessage("Trying to access an invalid array index");
Credentials credentials = this.locator.getCredentials(-1);
Assertions.assertThatThrownBy(() -> {
this.locator.setUri(new String[] { "http://localhost:8888", "http://localhost:8889" });
Credentials credentials = this.locator.getCredentials(-1);
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("Trying to access an invalid array index");
}
@Test
public void checkIfExceptionThrownForPositiveInvalidIndex() {
this.locator.setUri(new String[] { "http://localhost:8888", "http://localhost:8889" });
this.expected.expect(IllegalStateException.class);
this.expected.expectMessage("Trying to access an invalid array index");
Credentials credentials = this.locator.getCredentials(3);
Assertions.assertThatThrownBy(() -> {
this.locator.setUri(new String[] { "http://localhost:8888", "http://localhost:8889" });
Credentials credentials = this.locator.getCredentials(3);
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("Trying to access an invalid array index");
}
@Test
public void checkIfExceptionThrownForIndexEqualToLength() {
this.locator.setUri(new String[] { "http://localhost:8888", "http://localhost:8889" });
this.expected.expect(IllegalStateException.class);
this.expected.expectMessage("Trying to access an invalid array index");
Credentials credentials = this.locator.getCredentials(2);
Assertions.assertThatThrownBy(() -> {
this.locator.setUri(new String[] { "http://localhost:8888", "http://localhost:8889" });
Credentials credentials = this.locator.getCredentials(2);
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("Trying to access an invalid array index");
}
@Test

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.config.client;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.config.client;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.boot.WebApplicationType;

View File

@@ -18,9 +18,9 @@ package org.springframework.cloud.config.client;
import java.lang.reflect.Field;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.util.TestPropertyValues;
@@ -41,12 +41,12 @@ public class ConfigServiceBootstrapConfigurationTest {
private AnnotationConfigApplicationContext context;
@Before
@BeforeEach
public void setUp() throws Exception {
this.context = new AnnotationConfigApplicationContext();
}
@After
@AfterEach
public void tearDown() throws Exception {
if (this.context != null) {
this.context.close();

View File

@@ -27,10 +27,9 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.logging.LogFactory;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.assertj.core.api.AbstractThrowableAssert;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
@@ -66,9 +65,6 @@ import static org.springframework.cloud.config.environment.EnvironmentMediaType.
public class ConfigServicePropertySourceLocatorTests {
@Rule
public ExpectedException expected = ExpectedException.none();
private ConfigurableEnvironment environment = new StandardEnvironment();
private ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator(
@@ -140,16 +136,16 @@ public class ConfigServicePropertySourceLocatorTests {
@Test
public void sunnyDayWithNoSuchLabelAndFailFast() {
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
this.locator = new ConfigServicePropertySourceLocator(defaults);
mockRequestResponseWithLabel(new ResponseEntity<>((Void) null, HttpStatus.NOT_FOUND), "release(_)v1.0.0");
this.locator.setRestTemplate(this.restTemplate);
TestPropertyValues.of("spring.cloud.config.label:release/v1.0.1").applyTo(this.environment);
this.expected.expect(IsInstanceOf.instanceOf(IllegalStateException.class));
this.expected.expectMessage(
Assertions.assertThatThrownBy(() -> {
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
this.locator = new ConfigServicePropertySourceLocator(defaults);
mockRequestResponseWithLabel(new ResponseEntity<>((Void) null, HttpStatus.NOT_FOUND), "release(_)v1.0.0");
this.locator.setRestTemplate(this.restTemplate);
TestPropertyValues.of("spring.cloud.config.label:release/v1.0.1").applyTo(this.environment);
this.locator.locateCollection(this.environment);
}).isInstanceOf(IllegalStateException.class).hasMessageContaining(
"Could not locate PropertySource and the fail fast property is set, failing: None of labels [release/v1.0.1] found");
this.locator.locateCollection(this.environment);
}
@Test
@@ -161,61 +157,62 @@ public class ConfigServicePropertySourceLocatorTests {
@Test
public void failFast() throws Exception {
ClientHttpRequestFactory requestFactory = Mockito.mock(ClientHttpRequestFactory.class);
mockRequestResponse(requestFactory, null, HttpStatus.INTERNAL_SERVER_ERROR);
RestTemplate restTemplate = new RestTemplate(requestFactory);
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.locator.setRestTemplate(restTemplate);
this.expected.expect(IsInstanceOf.instanceOf(IllegalStateException.class));
this.expected.expectCause(IsInstanceOf.instanceOf(HttpServerErrorException.class));
this.expected.expectMessage("fail fast property is set");
this.locator.locateCollection(this.environment);
Assertions.assertThatThrownBy(() -> {
ClientHttpRequestFactory requestFactory = Mockito.mock(ClientHttpRequestFactory.class);
mockRequestResponse(requestFactory, null, HttpStatus.INTERNAL_SERVER_ERROR);
RestTemplate restTemplate = new RestTemplate(requestFactory);
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.locator.setRestTemplate(restTemplate);
this.locator.locateCollection(this.environment);
}).isInstanceOf(IllegalStateException.class).hasCauseInstanceOf(HttpServerErrorException.class)
.hasMessageContaining("fail fast property is set");
}
@Test
public void failFastWhenNotFound() throws Exception {
ClientHttpRequestFactory requestFactory = Mockito.mock(ClientHttpRequestFactory.class);
mockRequestResponse(requestFactory, null, HttpStatus.NOT_FOUND);
RestTemplate restTemplate = new RestTemplate(requestFactory);
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.locator.setRestTemplate(restTemplate);
this.expected.expect(IsInstanceOf.instanceOf(IllegalStateException.class));
this.expected.expectMessage("fail fast property is set, failing: None of labels [] found");
this.locator.locateCollection(this.environment);
Assertions.assertThatThrownBy(() -> {
ClientHttpRequestFactory requestFactory = Mockito.mock(ClientHttpRequestFactory.class);
mockRequestResponse(requestFactory, null, HttpStatus.NOT_FOUND);
RestTemplate restTemplate = new RestTemplate(requestFactory);
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.locator.setRestTemplate(restTemplate);
this.locator.locateCollection(this.environment);
}).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("fail fast property is set, failing: None of labels [] found");
}
@Test
public void failFastWhenRequestTimesOut() {
mockRequestTimedOut();
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.locator.setRestTemplate(this.restTemplate);
this.expected.expect(IsInstanceOf.instanceOf(IllegalStateException.class));
this.expected.expectCause(IsInstanceOf.instanceOf(ResourceAccessException.class));
this.expected.expectMessage("fail fast property is set");
this.locator.locateCollection(this.environment);
Assertions.assertThatThrownBy(() -> {
mockRequestTimedOut();
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.locator.setRestTemplate(this.restTemplate);
this.locator.locateCollection(this.environment);
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("fail fast property is set");
}
@Test
public void failFastWhenBothPasswordAndAuthorizationPropertiesSet() throws Exception {
ClientHttpRequestFactory requestFactory = Mockito.mock(ClientHttpRequestFactory.class);
ClientHttpRequest request = Mockito.mock(ClientHttpRequest.class);
Mockito.when(requestFactory.createRequest(Mockito.any(URI.class), Mockito.any(HttpMethod.class)))
.thenReturn(request);
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
defaults.setUsername("username");
defaults.setPassword("password");
defaults.getHeaders().put(AUTHORIZATION, "Basic dXNlcm5hbWU6cGFzc3dvcmQNCg==");
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.expected.expect(IllegalStateException.class);
this.expected.expectMessage("Could not locate PropertySource and the fail fast property is set, failing");
this.locator.locateCollection(this.environment);
Assertions.assertThatThrownBy(() -> {
ClientHttpRequestFactory requestFactory = Mockito.mock(ClientHttpRequestFactory.class);
ClientHttpRequest request = Mockito.mock(ClientHttpRequest.class);
Mockito.when(requestFactory.createRequest(Mockito.any(URI.class), Mockito.any(HttpMethod.class)))
.thenReturn(request);
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setFailFast(true);
defaults.setUsername("username");
defaults.setPassword("password");
defaults.getHeaders().put(AUTHORIZATION, "Basic dXNlcm5hbWU6cGFzc3dvcmQNCg==");
this.locator = new ConfigServicePropertySourceLocator(defaults);
this.locator.locateCollection(this.environment);
}).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Could not locate PropertySource and the fail fast property is set, failing");
}
@Test
@@ -253,32 +250,33 @@ public class ConfigServicePropertySourceLocatorTests {
@Test
public void shouldThrowExceptionWhenPasswordAndAuthorizationBothSet() {
HttpHeaders headers = new HttpHeaders();
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.getHeaders().put(AUTHORIZATION, "Basic dXNlcm5hbWU6cGFzc3dvcmQNCg==");
String username = "user";
String password = "pass";
this.expected.expect(IllegalStateException.class);
this.expected.expectMessage("You must set either 'password' or 'authorization'");
factory(defaults).addAuthorizationToken(headers, username, password);
Assertions.assertThatThrownBy(() -> {
HttpHeaders headers = new HttpHeaders();
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.getHeaders().put(AUTHORIZATION, "Basic dXNlcm5hbWU6cGFzc3dvcmQNCg==");
String username = "user";
String password = "pass";
factory(defaults).addAuthorizationToken(headers, username, password);
}).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("You must set either 'password' or 'authorization'");
}
@Test
public void shouldThrowExceptionWhenNegativeReadTimeoutSet() {
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setRequestReadTimeout(-1);
this.expected.expect(IllegalStateException.class);
this.expected.expectMessage("Invalid Value for Read Timeout set.");
factory(defaults).create();
Assertions.assertThatThrownBy(() -> {
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setRequestReadTimeout(-1);
factory(defaults).create();
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("Invalid Value for Read Timeout set.");
}
@Test
public void shouldThrowExceptionWhenNegativeConnectTimeoutSet() {
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setRequestConnectTimeout(-1);
this.expected.expect(IllegalStateException.class);
this.expected.expectMessage("Invalid Value for Connect Timeout set.");
factory(defaults).create();
Assertions.assertThatThrownBy(() -> {
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
defaults.setRequestConnectTimeout(-1);
factory(defaults).create();
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("Invalid Value for Connect Timeout set.");
}
@Test
@@ -440,29 +438,32 @@ public class ConfigServicePropertySourceLocatorTests {
}
private void assertNextUriIsNotTried(ConfigClientProperties.MultipleUriStrategy multipleUriStrategy,
HttpStatus firstUriResponse, Class<? extends Exception> expectedCause) throws Exception {
// Set up with two URIs.
ConfigClientProperties clientProperties = new ConfigClientProperties(this.environment);
String badURI = "http://baduri";
String goodURI = "http://localhost:8888";
String[] uris = new String[] { badURI, goodURI };
clientProperties.setUri(uris);
clientProperties.setFailFast(true);
// Strategy is CONNECTION_TIMEOUT_ONLY, so it should not try the next URI for
// INTERNAL_SERVER_ERROR
clientProperties.setMultipleUriStrategy(multipleUriStrategy);
this.locator = new ConfigServicePropertySourceLocator(clientProperties);
ClientHttpRequestFactory requestFactory = Mockito.mock(ClientHttpRequestFactory.class);
RestTemplate restTemplate = new RestTemplate(requestFactory);
mockRequestResponse(requestFactory, badURI, firstUriResponse);
mockRequestResponse(requestFactory, goodURI, HttpStatus.OK);
this.locator.setRestTemplate(restTemplate);
this.expected.expect(IsInstanceOf.instanceOf(IllegalStateException.class));
if (expectedCause != null) {
this.expected.expectCause(IsInstanceOf.instanceOf(expectedCause));
HttpStatus firstUriResponse, Class<? extends Exception> expectedCause) {
AbstractThrowableAssert throwableAssert = Assertions.assertThatThrownBy(() -> {
// Set up with two URIs.
ConfigClientProperties clientProperties = new ConfigClientProperties(this.environment);
String badURI = "http://baduri";
String goodURI = "http://localhost:8888";
String[] uris = new String[] { badURI, goodURI };
clientProperties.setUri(uris);
clientProperties.setFailFast(true);
// Strategy is CONNECTION_TIMEOUT_ONLY, so it should not try the next URI for
// INTERNAL_SERVER_ERROR
clientProperties.setMultipleUriStrategy(multipleUriStrategy);
this.locator = new ConfigServicePropertySourceLocator(clientProperties);
ClientHttpRequestFactory requestFactory = Mockito.mock(ClientHttpRequestFactory.class);
RestTemplate restTemplate = new RestTemplate(requestFactory);
mockRequestResponse(requestFactory, badURI, firstUriResponse);
mockRequestResponse(requestFactory, goodURI, HttpStatus.OK);
this.locator.setRestTemplate(restTemplate);
this.locator.locateCollection(this.environment);
});
if (expectedCause == null) {
throwableAssert.hasNoCause().hasMessageContaining("fail fast property is set");
}
else {
throwableAssert.hasCauseInstanceOf(expectedCause).hasMessageContaining("fail fast property is set");
}
this.expected.expectMessage("fail fast property is set");
this.locator.locateCollection(this.environment);
}
@SuppressWarnings("SameParameterValue")

View File

@@ -21,9 +21,8 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.BootstrapRegistry;
@@ -36,7 +35,6 @@ import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.config.client.ConfigClientProperties.Credentials;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
@@ -48,7 +46,6 @@ import static org.springframework.cloud.config.client.ConfigClientProperties.Dis
/**
* @author Dave Syer
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-retry-*.jar", "spring-boot-starter-aop-*.jar" })
public class DiscoveryClientConfigDataConfigurationNoRetryTests {
@@ -58,7 +55,7 @@ public class DiscoveryClientConfigDataConfigurationNoRetryTests {
protected ServiceInstance info = new DefaultServiceInstance("app:8877", "app", "foo", 8877, false);
@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();

View File

@@ -16,24 +16,23 @@
package org.springframework.cloud.config.client;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
@RunWith(ModifiedClassPathRunner.class)
import static org.springframework.cloud.config.client.ConfigClientProperties.Discovery.DEFAULT_CONFIG_SERVER;
@ClassPathExclusions({ "spring-retry-*.jar", "spring-boot-starter-aop-*.jar" })
public class DiscoveryClientConfigServiceBootstrapConfigurationNoSpringRetryTests
extends BaseDiscoveryClientConfigServiceBootstrapConfigurationTests {
@Test
public void shouldFailWithExceptionGetConfigServerInstanceFromDiscoveryClient() throws Exception {
givenDiscoveryClientReturnsNoInfo();
expectNoInstancesOfConfigServerException();
setup("spring.cloud.config.discovery.enabled=true", "spring.cloud.config.fail-fast=true");
org.assertj.core.api.Assertions.assertThatThrownBy(() -> {
givenDiscoveryClientReturnsNoInfo();
setup("spring.cloud.config.discovery.enabled=true", "spring.cloud.config.fail-fast=true");
}).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("No instances found of configserver (" + DEFAULT_CONFIG_SERVER + ")");
}
@Test

View File

@@ -18,7 +18,7 @@ package org.springframework.cloud.config.client;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
@@ -178,13 +178,12 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests
}
@Test
public void shouldRetryAndFailWithExceptionGetConfigServerInstanceFromDiscoveryClient() throws Exception {
givenDiscoveryClientReturnsNoInfo();
expectNoInstancesOfConfigServerException();
setup("spring.cloud.config.discovery.enabled=true", "spring.cloud.config.retry.maxAttempts=3",
"spring.cloud.config.retry.initialInterval=10", "spring.cloud.config.fail-fast=true");
public void shouldRetryAndFailWithExceptionGetConfigServerInstanceFromDiscoveryClient() {
org.assertj.core.api.Assertions.assertThatThrownBy(() -> {
givenDiscoveryClientReturnsNoInfo();
setup("spring.cloud.config.discovery.enabled=true", "spring.cloud.config.retry.maxAttempts=3",
"spring.cloud.config.retry.initialInterval=10", "spring.cloud.config.fail-fast=true");
}).isInstanceOf(IllegalStateException.class);
}
@Test

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.config.environment;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -47,8 +47,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -21,8 +21,8 @@ import java.util.UUID;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
@@ -41,7 +41,7 @@ public class BitbucketPropertyPathNotificationExtractorTests {
private HttpHeaders headers;
@Before
@BeforeEach
public void setup() {
this.headers = new HttpHeaders();
}

View File

@@ -22,7 +22,7 @@ import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;

View File

@@ -18,7 +18,7 @@ package org.springframework.cloud.config.monitor;
import java.util.Collection;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerProperties;

View File

@@ -23,9 +23,9 @@ import java.util.List;
import java.util.Set;
import io.micrometer.observation.ObservationRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.server.environment.AbstractScmEnvironmentRepository;
import org.springframework.cloud.config.server.environment.JGitEnvironmentProperties;
@@ -54,12 +54,12 @@ public class FileMonitorConfigurationTest {
private List<AbstractScmEnvironmentRepository> repositories = new ArrayList<>();
@Before
@BeforeEach
public void setup() {
fileMonitorConfiguration.setResourceLoader(new FileSystemResourceLoader());
}
@After
@AfterEach
public void tearDown() {
fileMonitorConfiguration.stop();
}

View File

@@ -20,7 +20,7 @@ import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;

View File

@@ -20,7 +20,7 @@ import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;

View File

@@ -20,7 +20,7 @@ import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;

View File

@@ -20,7 +20,7 @@ import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;

View File

@@ -20,7 +20,7 @@ import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;

View File

@@ -20,8 +20,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.http.HttpHeaders;
@@ -37,7 +37,7 @@ public class PropertyPathEndpointTests {
private PropertyPathEndpoint endpoint = new PropertyPathEndpoint(
new CompositePropertyPathNotificationExtractor(Collections.emptyList()), "abc1");
@Before
@BeforeEach
public void init() {
StaticApplicationContext publisher = new StaticApplicationContext();
this.endpoint.setApplicationEventPublisher(publisher);

View File

@@ -53,8 +53,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -19,10 +19,9 @@ package sample;
import java.io.IOException;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -32,7 +31,6 @@ import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,7 +45,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
*
* @author Spencer Gibb
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config
@@ -67,7 +64,7 @@ public class ApplicationBootstrapTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
System.setProperty("spring.cloud.bootstrap.name", "bootstrapservercomposite");
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
@@ -80,7 +77,7 @@ public class ApplicationBootstrapTests {
System.setProperty("config.port", "" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("config.port");
System.clearProperty("spring.cloud.bootstrap.name");

View File

@@ -19,10 +19,9 @@ package sample;
import java.io.IOException;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -31,13 +30,11 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -57,7 +54,7 @@ public class ApplicationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
@@ -71,7 +68,7 @@ public class ApplicationTests {
System.setProperty("config.port", "" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("config.port");
if (server != null) {

View File

@@ -18,10 +18,9 @@ package sample;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
@@ -34,13 +33,11 @@ import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -62,7 +59,7 @@ public class ConfigDataCustomMediaTypeIntegrationTests {
@Autowired
ConfigurableEnvironment env;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
@@ -73,7 +70,7 @@ public class ConfigDataCustomMediaTypeIntegrationTests {
System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("spring.cloud.config.uri");
if (server != null) {

View File

@@ -19,10 +19,9 @@ package sample;
import java.io.IOException;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -31,13 +30,11 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -56,7 +53,7 @@ public class ConfigDataIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
@@ -67,7 +64,7 @@ public class ConfigDataIntegrationTests {
System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("spring.cloud.config.uri");
if (server != null) {

View File

@@ -18,10 +18,9 @@ package sample;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -31,13 +30,11 @@ import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -58,7 +55,7 @@ public class ConfigDataOrderingIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() {
server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class,
"--spring.profiles.active=native", "--server.port=" + configPort, "--spring.config.name=server");
@@ -66,7 +63,7 @@ public class ConfigDataOrderingIntegrationTests {
System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("spring.cloud.config.uri");
if (server != null) {

View File

@@ -22,10 +22,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
@@ -37,7 +36,6 @@ import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.TestSocketUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@@ -46,7 +44,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class,
// Normally spring.cloud.config.enabled:true is the default but since we have the
// config server on the classpath we need to set it explicitly
@@ -66,7 +63,7 @@ public class ConfigDataRetryIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String baseDir = ConfigServerTestUtils.getBaseDirectory("spring-cloud-config-sample");
String repo = ConfigServerTestUtils.prepareLocalRepo(baseDir, "target/repos", "config-repo", "target/config");
@@ -76,7 +73,7 @@ public class ConfigDataRetryIntegrationTests {
System.setProperty("spring.cloud.config.uri", "http://localhost:" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("spring.cloud.config.uri");
if (server != null) {

View File

@@ -18,10 +18,9 @@ package sample;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
@@ -30,12 +29,10 @@ import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, properties = "spring.application.name:bad", webEnvironment = RANDOM_PORT)
public class ServerNativeApplicationTests {
@@ -49,7 +46,7 @@ public class ServerNativeApplicationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void startConfigServer() throws IOException {
String repo = ConfigServerTestUtils.prepareLocalRepo();
server = SpringApplication.run(org.springframework.cloud.config.server.test.TestConfigServerApplication.class,
@@ -62,7 +59,7 @@ public class ServerNativeApplicationTests {
System.setProperty("config.port", "" + configPort);
}
@AfterClass
@AfterAll
public static void close() {
System.clearProperty("config.port");
if (server != null) {

View File

@@ -162,8 +162,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.config.server;
import org.junit.Ignore;
import org.junit.jupiter.api.Disabled;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@@ -85,7 +85,7 @@ import org.springframework.cloud.config.server.ssh.SshUriPropertyProcessorTest;
ConfigServerHealthIndicatorTests.class, CustomCompositeEnvironmentRepositoryTests.class,
CustomEnvironmentRepositoryTests.class, BootstrapConfigServerIntegrationTests.class,
AwsS3EnvironmentRepositoryTests.class, AwsParameterStoreEnvironmentRepositoryTests.class })
@Ignore
@Disabled
public class AdhocTestSuite {
}

View File

@@ -20,10 +20,9 @@ import java.io.IOException;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -36,13 +35,11 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.assertOriginTrackedValue;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.cloud.bootstrap.enabled=true",
"logging.level.org.springframework.boot.context.config=TRACE", "spring.cloud.bootstrap.name:enable-bootstrap",
"encrypt.rsa.algorithm=DEFAULT", "encrypt.rsa.strong=false" },
@@ -56,7 +53,7 @@ public class BootstrapConfigServerIntegrationTests {
@Autowired
ConfigurableEnvironment env;
@BeforeClass
@BeforeAll
public static void init() throws IOException {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
@@ -76,7 +73,7 @@ public class BootstrapConfigServerIntegrationTests {
}
@Test
@Ignore // FIXME: configdata
@Disabled // FIXME: configdata
public void environmentBootstraps() {
assertThat(this.env.getProperty("info.foo", "")).isEqualTo("bar");
assertThat(this.env.getProperty("config.foo", "")).isEqualTo("foo");

View File

@@ -16,20 +16,17 @@
package org.springframework.cloud.config.server;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.cloud.config.server.composite.CompositeUtils;
import org.springframework.cloud.config.server.test.TestConfigServerApplication;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import static org.assertj.core.api.Assertions.assertThat;
public class CompositeClasspathTests {
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-jdbc-*.jar", "spring-data-redis-*.jar" })
public static class JdbcTests {
@@ -49,7 +46,6 @@ public class CompositeClasspathTests {
}
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-jdbc-*.jar", "spring-data-redis-*.jar", "spring-boot-actuator-*.jar" })
public static class NoActuatorTests {
@@ -68,7 +64,6 @@ public class CompositeClasspathTests {
}
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("httpclient-*.jar")
public static class HttpClientTests {
@@ -88,7 +83,6 @@ public class CompositeClasspathTests {
}
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("svnkit-*.jar")
public static class SvnTests {
@@ -108,7 +102,6 @@ public class CompositeClasspathTests {
}
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("org.eclipse.jgit-*.jar")
public static class JGitTests {
@@ -128,7 +121,6 @@ public class CompositeClasspathTests {
}
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("google-auth-library-oauth2-http-*.jar")
public static class GoogleAuthTests {

View File

@@ -18,9 +18,8 @@ package org.springframework.cloud.config.server;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
@@ -31,7 +30,6 @@ import org.springframework.cloud.config.server.test.TestConfigServerApplication;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@@ -43,7 +41,6 @@ import static org.springframework.cloud.config.server.test.ConfigServerTestUtils
*/
public class CompositeIntegrationTests {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class,
properties = { "spring.config.name:compositeconfigserver",
"spring.cloud.config.server.svn.uri:file:///./target/repos/svn-config-repo",
@@ -57,7 +54,7 @@ public class CompositeIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
@@ -94,7 +91,6 @@ public class CompositeIntegrationTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class,
properties = { "spring.config.name:compositeconfigserver",
"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
@@ -108,7 +104,7 @@ public class CompositeIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());

View File

@@ -22,9 +22,8 @@ import java.util.Map;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -36,13 +35,11 @@ import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.config.name:configserver" },
webEnvironment = RANDOM_PORT)
@ActiveProfiles({ "test", "native" })
@@ -54,7 +51,7 @@ public class ConfigClientBackwardsCompatibilityIntegrationTests {
@Autowired
private ApplicationContext context;
@BeforeClass
@BeforeAll
public static void init() throws IOException {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());

View File

@@ -20,9 +20,8 @@ import java.io.IOException;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.BeanFactoryUtils;
@@ -43,7 +42,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -51,7 +49,6 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class, webEnvironment = RANDOM_PORT)
@ActiveProfiles("test")
public class ConfigClientOffIntegrationTests {
@@ -62,7 +59,7 @@ public class ConfigClientOffIntegrationTests {
@Autowired
private ApplicationContext context;
@BeforeClass
@BeforeAll
public static void init() throws IOException {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());

View File

@@ -20,10 +20,9 @@ import java.io.IOException;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.BeanFactoryUtils;
@@ -45,14 +44,12 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class,
properties = { "spring.config.use-legacy-processing=true", "spring.cloud.config.enabled:true" },
webEnvironment = WebEnvironment.RANDOM_PORT)
@@ -68,7 +65,7 @@ public class ConfigClientOnIntegrationTests {
@Autowired
private ApplicationContext context;
@BeforeClass
@BeforeAll
public static void init() throws IOException {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
@@ -76,7 +73,7 @@ public class ConfigClientOnIntegrationTests {
localRepo = ConfigServerTestUtils.prepareLocalRepo();
}
@AfterClass
@AfterAll
public static void after() throws IOException {
ConfigServerTestUtils.deleteLocalRepo(localRepo);
}

View File

@@ -17,15 +17,12 @@
package org.springframework.cloud.config.server;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext;
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("h2-*.jar")
public class ConfigServerApplicationTests {

View File

@@ -16,15 +16,13 @@
package org.springframework.cloud.config.server;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.test.TestConfigServerApplication;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@@ -32,7 +30,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
/**
* @author Alberto C. Ríos
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class,
properties = { "spring.profiles.active:composite", "spring.cloud.config.server.composite[0].type:credhub",
"spring.cloud.config.server.composite[0].url:https://credhub:8844" },

View File

@@ -16,15 +16,13 @@
package org.springframework.cloud.config.server;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.test.TestConfigServerApplication;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@@ -32,7 +30,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
/**
* @author Alberto C. Ríos
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.profiles.active:credhub",
"spring.cloud.config.server.credhub.url:https://credhub:8844" }, webEnvironment = RANDOM_PORT)
public class CredhubConfigServerIntegrationTests extends CredhubIntegrationTest {

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.config.server;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -39,7 +39,7 @@ public class CredhubIntegrationTest {
@MockBean
private CredHubOperations credHubOperations;
@Before
@BeforeEach
public void setUp() {
CredHubCredentialOperations credhubCredentialOperations = Mockito.mock(CredHubCredentialOperations.class);

View File

@@ -20,9 +20,8 @@ import java.io.IOException;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
@@ -34,14 +33,12 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.prepareLocalRepo;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class, properties = { "spring.config.name:configserver" },
webEnvironment = RANDOM_PORT)
@ActiveProfiles({ "test", "native" })
@@ -50,7 +47,7 @@ public class NativeConfigServerIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void init() throws IOException {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());

View File

@@ -20,10 +20,9 @@ import java.io.IOException;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -46,7 +45,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.isA;
@@ -55,7 +53,6 @@ import static org.mockito.BDDMockito.given;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.assertOriginTrackedValue;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class,
properties = { "spring.cloud.config.enabled=true", "spring.cloud.bootstrap.enabled=true",
"management.endpoint.env.post.enabled=true", "management.endpoints.web.exposure.include=env, refresh" },
@@ -69,7 +66,7 @@ public class RefreshableConfigServerIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void init() throws IOException {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
@@ -77,7 +74,7 @@ public class RefreshableConfigServerIntegrationTests {
localRepo = ConfigServerTestUtils.prepareLocalRepo();
}
@AfterClass
@AfterAll
public static void after() throws IOException {
ConfigServerTestUtils.deleteLocalRepo(localRepo);
}

View File

@@ -19,9 +19,8 @@ package org.springframework.cloud.config.server;
import java.io.File;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -35,7 +34,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@@ -47,7 +45,6 @@ import static org.springframework.cloud.config.server.test.ConfigServerTestUtils
* @author Dave Syer
* @author Roy Clarkson
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class,
properties = { "spring.config.name:configserver",
"spring.cloud.config.server.svn.uri:file:///./target/repos/svn-config-repo",
@@ -62,7 +59,7 @@ public class SubversionConfigServerIntegrationTests {
@Autowired
private ApplicationContext context;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo", "target/repos/svn-config-repo");
}

View File

@@ -27,8 +27,7 @@ import org.eclipse.jgit.transport.SshConfigStore;
import org.eclipse.jgit.transport.SshTransport;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.sshd.SshdSessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -41,7 +40,6 @@ import org.springframework.cloud.config.server.ssh.PropertyBasedSshSessionFactor
import org.springframework.cloud.config.server.ssh.SshPropertyValidator;
import org.springframework.cloud.config.server.test.TestConfigServerApplication;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@@ -54,7 +52,6 @@ public class TransportConfigurationIntegrationTests {
public static class PropertyBasedCallbackTest {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/",
@@ -84,7 +81,6 @@ public class TransportConfigurationIntegrationTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/",
@@ -118,7 +114,6 @@ public class TransportConfigurationIntegrationTests {
public static class PrivateKeyPropertyWithLineBreaks {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/",
@@ -141,7 +136,6 @@ public class TransportConfigurationIntegrationTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/",
@@ -168,7 +162,6 @@ public class TransportConfigurationIntegrationTests {
public static class SshPropertiesWithinNestedRepo {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/",
@@ -196,7 +189,6 @@ public class TransportConfigurationIntegrationTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.config.additional-location=optional:file:/ssh/,optional:classpath:/ssh/",
@@ -228,7 +220,6 @@ public class TransportConfigurationIntegrationTests {
public static class FileBasedCallbackTest {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.cloud.config.server.git.uri=git@gitserver.com:team/repo.git",
@@ -282,7 +273,6 @@ public class TransportConfigurationIntegrationTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class, SshPropertyValidator.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.cloud.config.server.composite[0].type=git",

View File

@@ -21,9 +21,8 @@ import java.util.Arrays;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
@@ -37,13 +36,11 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.cloud.config.server.test.ConfigServerTestUtils.getV2AcceptEntity;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfigServerApplication.class,
properties = { "spring.config.name:configserver",
"spring.cloud.config.server.git.uri:file:./target/repos/config-repo" },
@@ -54,7 +51,7 @@ public class VanillaConfigServerIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void init() throws IOException {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());

View File

@@ -18,20 +18,19 @@ package org.springframework.cloud.config.server.composite;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.config.server.test.TestConfigServerApplication;
import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(OutputCaptureExtension.class)
public class CompositUtilsTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void getCompositeTypeListWorks() {
new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class)
@@ -49,18 +48,18 @@ public class CompositUtilsTests {
@Test
public void getCompositeTypeListFails() {
this.thrown.expect(IllegalStateException.class);
new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class)
.withPropertyValues("spring.profiles.active:test,composite", "spring.config.name:compositeconfigserver",
"spring.jmx.enabled=false",
"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
"spring.cloud.config.server.composite[0].type:git",
"spring.cloud.config.server.composite[2].uri:file:///./target/repos/svn-config-repo",
"spring.cloud.config.server.composite[2].type:svn")
.run(context -> {
CompositeUtils.getCompositeTypeList(context.getEnvironment());
});
Assertions.assertThatThrownBy(() -> {
new WebApplicationContextRunner().withUserConfiguration(TestConfigServerApplication.class)
.withPropertyValues("spring.profiles.active:test,composite",
"spring.config.name:compositeconfigserver", "spring.jmx.enabled=false",
"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
"spring.cloud.config.server.composite[0].type:git",
"spring.cloud.config.server.composite[2].uri:file:///./target/repos/svn-config-repo",
"spring.cloud.config.server.composite[2].type:svn")
.run(context -> {
CompositeUtils.getCompositeTypeList(context.getEnvironment());
});
}).isInstanceOf(IllegalStateException.class);
}
}

View File

@@ -18,8 +18,8 @@ package org.springframework.cloud.config.server.config;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -49,7 +49,7 @@ public class ConfigServerHealthIndicatorTests {
private ConfigServerHealthIndicator indicator;
@Before
@BeforeEach
public void init() {
initMocks(this);
this.indicator = new ConfigServerHealthIndicator(this.repository);

View File

@@ -21,9 +21,8 @@ import java.util.List;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -43,7 +42,6 @@ import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,7 +50,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class CustomCompositeEnvironmentRepositoryTests {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CustomCompositeEnvironmentRepositoryTests.StaticTests.Config.class,
properties = { "spring.config.name:compositeconfigserver",
"spring.cloud.config.server.git.uri:file:./target/repos/config-repo",
@@ -65,7 +62,7 @@ public class CustomCompositeEnvironmentRepositoryTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
@@ -102,7 +99,6 @@ public class CustomCompositeEnvironmentRepositoryTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CustomCompositeEnvironmentRepositoryTests.ListTests.Config.class,
properties = { "spring.config.name:compositeconfigserver",
"spring.cloud.config.server.composite[0].type:git",
@@ -117,7 +113,7 @@ public class CustomCompositeEnvironmentRepositoryTests {
@LocalServerPort
private int port;
@BeforeClass
@BeforeAll
public static void init() throws Exception {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());

View File

@@ -16,8 +16,7 @@
package org.springframework.cloud.config.server.config;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -33,7 +32,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@@ -41,7 +39,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class, properties = { "spring.config.name:configserver" },
webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.config.server.config;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;

View File

@@ -20,21 +20,15 @@ import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.server.environment.HttpClientVaultRestTemplateFactory;
import org.springframework.cloud.config.server.environment.VaultEnvironmentProperties;
import org.springframework.cloud.config.server.proxy.ProxyHostProperties;
import org.springframework.web.client.RestTemplate;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
/**
* @author Dylan Roberts
*/
@@ -72,74 +66,65 @@ public class HttpClientVaultRestTemplateFactoryTest {
HTTPS_PROXY.setPort(8081);
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
private HttpClientVaultRestTemplateFactory factory;
@Before
@BeforeEach
public void setUp() {
this.factory = new HttpClientVaultRestTemplateFactory();
}
@Test
public void authenticatedHttpsProxy() throws Exception {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(null, AUTHENTICATED_HTTPS_PROXY);
RestTemplate restTemplate = this.factory.build(properties);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(AUTHENTICATED_HTTPS_PROXY.getHost()))));
restTemplate.getForObject("https://somehost", String.class);
Assertions.assertThatThrownBy(() -> {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(null, AUTHENTICATED_HTTPS_PROXY);
RestTemplate restTemplate = this.factory.build(properties);
restTemplate.getForObject("https://somehost", String.class);
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(AUTHENTICATED_HTTPS_PROXY.getHost());
}
@Test
public void httpsProxy() throws Exception {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(null, HTTPS_PROXY);
RestTemplate restTemplate = this.factory.build(properties);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTPS_PROXY.getHost()))));
restTemplate.getForObject("https://somehost", String.class);
Assertions.assertThatThrownBy(() -> {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(null, HTTPS_PROXY);
RestTemplate restTemplate = this.factory.build(properties);
restTemplate.getForObject("https://somehost", String.class);
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTPS_PROXY.getHost());
}
@Test
public void httpsProxy_called_for_http_request_when_no_httpProxy_specified() throws Exception {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(null, HTTPS_PROXY);
RestTemplate restTemplate = this.factory.build(properties);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTPS_PROXY.getHost()))));
restTemplate.getForObject("http://somehost", String.class);
Assertions.assertThatThrownBy(() -> {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(null, HTTPS_PROXY);
RestTemplate restTemplate = this.factory.build(properties);
restTemplate.getForObject("http://somehost", String.class);
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTPS_PROXY.getHost());
}
@Test
public void authenticatedHttpProxy() throws Exception {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(AUTHENTICATED_HTTP_PROXY, null);
RestTemplate restTemplate = this.factory.build(properties);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(AUTHENTICATED_HTTP_PROXY.getHost()))));
restTemplate.getForObject("http://somehost", String.class);
Assertions.assertThatThrownBy(() -> {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(AUTHENTICATED_HTTP_PROXY, null);
RestTemplate restTemplate = this.factory.build(properties);
restTemplate.getForObject("http://somehost", String.class);
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(AUTHENTICATED_HTTP_PROXY.getHost());
}
@Test
public void httpProxy() throws Exception {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(HTTP_PROXY, null);
RestTemplate restTemplate = this.factory.build(properties);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTP_PROXY.getHost()))));
restTemplate.getForObject("http://somehost", String.class);
Assertions.assertThatThrownBy(() -> {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(HTTP_PROXY, null);
RestTemplate restTemplate = this.factory.build(properties);
restTemplate.getForObject("http://somehost", String.class);
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTP_PROXY.getHost());
}
@Test
public void httpProxy_called_for_https_request_when_no_httpsProxy_specified() throws Exception {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(HTTP_PROXY, null);
RestTemplate restTemplate = this.factory.build(properties);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTP_PROXY.getHost()))));
restTemplate.getForObject("https://somehost", String.class);
Assertions.assertThatThrownBy(() -> {
VaultEnvironmentProperties properties = getVaultEnvironmentProperties(HTTP_PROXY, null);
RestTemplate restTemplate = this.factory.build(properties);
restTemplate.getForObject("https://somehost", String.class);
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTP_PROXY.getHost());
}
private VaultEnvironmentProperties getVaultEnvironmentProperties(ProxyHostProperties httpProxy,

View File

@@ -21,8 +21,8 @@ import java.net.URISyntaxException;
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
import org.eclipse.jgit.transport.CredentialItem;
import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider;
@@ -53,7 +53,7 @@ public class AwsCodeCommitCredentialsProviderTests {
private AwsCodeCommitCredentialProvider provider;
@Before
@BeforeEach
public void init() {
GitCredentialsProviderFactory factory = new GitCredentialsProviderFactory();
this.provider = (AwsCodeCommitCredentialProvider) factory.createFor(AWS_REPO, USER, PASSWORD, null, false);

View File

@@ -18,8 +18,8 @@ package org.springframework.cloud.config.server.credentials;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider;
import org.springframework.cloud.config.server.support.GitCredentialsProviderFactory;
@@ -48,7 +48,7 @@ public class GitCredentialsProviderFactoryTests {
private GitCredentialsProviderFactory factory;
@Before
@BeforeEach
public void init() {
this.factory = new GitCredentialsProviderFactory();
}

View File

@@ -20,9 +20,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.cloud.config.environment.Environment;
@@ -34,18 +33,13 @@ import org.springframework.security.crypto.encrypt.TextEncryptor;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
/**
* Converted all the tests to parameterized tests.
*
* @author Siva Krishna Battu
*/
public class CipherEnvironmentEncryptorTests {
TextEncryptor textEncryptor = new EncryptorFactory().create("foo");
EnvironmentEncryptor encryptor;
public CipherEnvironmentEncryptorTests(String salt, String key) {
this.textEncryptor = new EncryptorFactory(salt).create(key);
this.encryptor = new CipherEnvironmentEncryptor(keys -> CipherEnvironmentEncryptorTests.this.textEncryptor);
}
@Parameters
public static List<Object[]> params() {
List<Object[]> list = new ArrayList<>();
@@ -54,66 +48,75 @@ public class CipherEnvironmentEncryptorTests {
return list;
}
@Test
public void shouldDecryptEnvironment() {
@ParameterizedTest
@MethodSource("params")
public void shouldDecryptEnvironment(String salt, String key) {
TextEncryptor textEncryptor = new EncryptorFactory(salt).create(key);
EnvironmentEncryptor encryptor = new CipherEnvironmentEncryptor(keys -> textEncryptor);
// given
String secret = randomUUID().toString();
// when
Environment environment = new Environment("name", "profile", "label");
environment.add(new PropertySource("a", Collections.<Object, Object>singletonMap(environment.getName(),
"{cipher}" + this.textEncryptor.encrypt(secret))));
"{cipher}" + textEncryptor.encrypt(secret))));
// then
assertThat(
this.encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()))
.isEqualTo(secret);
assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()))
.isEqualTo(secret);
}
@Test
public void shouldDecryptEnvironmentWithKey() {
@ParameterizedTest
@MethodSource("params")
public void shouldDecryptEnvironmentWithKey(String salt, String key) {
TextEncryptor textEncryptor = new EncryptorFactory(salt).create(key);
EnvironmentEncryptor encryptor = new CipherEnvironmentEncryptor(keys -> textEncryptor);
// given
String secret = randomUUID().toString();
// when
Environment environment = new Environment("name", "profile", "label");
environment.add(new PropertySource("a", Collections.<Object, Object>singletonMap(environment.getName(),
"{cipher}{key:test}" + this.textEncryptor.encrypt(secret))));
"{cipher}{key:test}" + textEncryptor.encrypt(secret))));
// then
assertThat(
this.encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()))
.isEqualTo(secret);
assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()))
.isEqualTo(secret);
}
@Test
public void shouldBeAbleToUseNullAsPropertyValue() {
@ParameterizedTest
@MethodSource("params")
public void shouldBeAbleToUseNullAsPropertyValue(String salt, String key) {
TextEncryptor textEncryptor = new EncryptorFactory(salt).create(key);
EnvironmentEncryptor encryptor = new CipherEnvironmentEncryptor(keys -> textEncryptor);
// when
Environment environment = new Environment("name", "profile", "label");
environment.add(new PropertySource("a", Collections.<Object, Object>singletonMap(environment.getName(), null)));
// then
assertThat(
this.encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()))
.isEqualTo(null);
assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()))
.isEqualTo(null);
}
@Test
public void shouldDecryptEnvironmentIncludeOrigin() {
@ParameterizedTest
@MethodSource("params")
public void shouldDecryptEnvironmentIncludeOrigin(String salt, String key) {
TextEncryptor textEncryptor = new EncryptorFactory(salt).create(key);
EnvironmentEncryptor encryptor = new CipherEnvironmentEncryptor(keys -> textEncryptor);
// given
String secret = randomUUID().toString();
// when
Environment environment = new Environment("name", "profile", "label");
String encrypted = "{cipher}" + this.textEncryptor.encrypt(secret);
String encrypted = "{cipher}" + textEncryptor.encrypt(secret);
environment.add(new PropertySource("a", Collections.<Object, Object>singletonMap(environment.getName(),
new PropertyValueDescriptor(encrypted, "encrypted value"))));
// then
assertThat(
this.encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()))
.isEqualTo(secret);
assertThat(encryptor.decrypt(environment).getPropertySources().get(0).getSource().get(environment.getName()))
.isEqualTo(secret);
}
}

View File

@@ -20,7 +20,7 @@ import java.io.File;
import java.nio.file.Files;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.context.encrypt.EncryptorFactory;

View File

@@ -20,7 +20,7 @@ import java.io.File;
import java.nio.file.Files;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.context.encrypt.EncryptorFactory;

View File

@@ -20,7 +20,7 @@ import java.io.File;
import java.nio.file.Files;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.context.encrypt.EncryptorFactory;

View File

@@ -16,7 +16,8 @@
package org.springframework.cloud.config.server.encryption;
import org.junit.Test;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.security.crypto.encrypt.Encryptors;
@@ -52,26 +53,22 @@ public class EncryptionControllerMultiTextEncryptorTests {
.isEqualTo(this.data);
}
@Test(expected = EncryptionTooWeakException.class)
@Test
public void shouldNotEncryptUsingNoOp() {
// given
String application = "unknown";
// when
this.controller.encrypt(application, this.profiles, this.data, TEXT_PLAIN);
// then exception is thrown
Assertions.assertThatThrownBy(() -> {
String application = "unknown";
this.controller.encrypt(application, this.profiles, this.data, TEXT_PLAIN);
}).isInstanceOf(EncryptionTooWeakException.class);
}
@Test(expected = EncryptionTooWeakException.class)
@Test
public void shouldNotDecryptUsingNoOp() {
// given
String application = "unknown";
// when
this.controller.decrypt(application, this.profiles, this.data, TEXT_PLAIN);
// then exception is thrown
Assertions.assertThatThrownBy(() -> {
String application = "unknown";
this.controller.decrypt(application, this.profiles, this.data, TEXT_PLAIN);
}).isInstanceOf(EncryptionTooWeakException.class);
}
}

View File

@@ -18,7 +18,8 @@ package org.springframework.cloud.config.server.encryption;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.http.MediaType;
@@ -42,27 +43,33 @@ public class EncryptionControllerTests {
private EncryptionController controller = new EncryptionController(
new SingleTextEncryptorLocator(Encryptors.noOpText()));
@Test(expected = EncryptionTooWeakException.class)
@Test
public void cannotDecryptWithoutKey() {
this.controller.decrypt("foo", MediaType.TEXT_PLAIN);
Assertions.assertThrows(EncryptionTooWeakException.class,
() -> this.controller.decrypt("foo", MediaType.TEXT_PLAIN));
}
@Test(expected = EncryptionTooWeakException.class)
@Test
public void cannotDecryptWithNoopEncryptor() {
this.controller.decrypt("foo", MediaType.TEXT_PLAIN);
Assertions.assertThrows(EncryptionTooWeakException.class,
() -> this.controller.decrypt("foo", MediaType.TEXT_PLAIN));
}
@Test(expected = InvalidCipherException.class)
@Test
public void shouldThrowExceptionOnDecryptInvalidData() {
this.controller = new EncryptionController(new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
this.controller.decrypt("foo", MediaType.TEXT_PLAIN);
Assertions.assertThrows(InvalidCipherException.class, () -> {
this.controller = new EncryptionController(new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
this.controller.decrypt("foo", MediaType.TEXT_PLAIN);
});
}
@Test(expected = InvalidCipherException.class)
@Test
public void shouldThrowExceptionOnDecryptWrongKey() {
RsaSecretEncryptor encryptor = new RsaSecretEncryptor();
this.controller = new EncryptionController(new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
this.controller.decrypt(encryptor.encrypt("foo"), MediaType.TEXT_PLAIN);
Assertions.assertThrows(InvalidCipherException.class, () -> {
RsaSecretEncryptor encryptor = new RsaSecretEncryptor();
this.controller = new EncryptionController(new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
this.controller.decrypt(encryptor.encrypt("foo"), MediaType.TEXT_PLAIN);
});
}
@Test
@@ -134,7 +141,7 @@ public class EncryptionControllerTests {
public void addEnvironment() {
TextEncryptorLocator locator = new TextEncryptorLocator() {
private RsaSecretEncryptor encryptor = new RsaSecretEncryptor();
private final RsaSecretEncryptor encryptor = new RsaSecretEncryptor();
@Override
public TextEncryptor locate(Map<String, String> keys) {

View File

@@ -16,9 +16,8 @@
package org.springframework.cloud.config.server.encryption;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -32,13 +31,11 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
public class EncryptionIntegrationTests {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class },
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.config.use-legacy-processing=true", "encrypt.key=foobar" })
@@ -57,7 +54,6 @@ public class EncryptionIntegrationTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class },
properties = { "spring.config.use-legacy-processing=true",
"spring.cloud.bootstrap.name:symmetric-key-bootstrap" },
@@ -77,7 +73,6 @@ public class EncryptionIntegrationTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class },
properties = { "spring.config.use-legacy-processing=true",
"spring.cloud.bootstrap.name:keystore-bootstrap" },
@@ -97,7 +92,6 @@ public class EncryptionIntegrationTests {
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TestConfigServerApplication.class },
properties = { "spring.config.use-legacy-processing=true", "spring.cloud.bootstrap.name:keystore-bootstrap",
"spring.cloud.config.server.encrypt.enabled=false", "encrypt.keyStore.alias=myencryptionkey" },
@@ -109,7 +103,7 @@ public class EncryptionIntegrationTests {
@Autowired
private TestRestTemplate testRestTemplate;
@BeforeClass
@BeforeAll
public static void setupTest() throws Exception {
ConfigServerTestUtils.prepareLocalRepo("./", "target/repos", "encrypt-repo", "target/config");
}

View File

@@ -19,7 +19,7 @@ package org.springframework.cloud.config.server.encryption;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -20,7 +20,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.crypto.encrypt.TextEncryptor;

View File

@@ -20,7 +20,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;

View File

@@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.List;
import io.micrometer.observation.ObservationRegistry;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;

View File

@@ -31,13 +31,12 @@ import java.util.List;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.assertj.core.api.Assertions;
import org.eclipse.jgit.transport.HttpTransport;
import org.eclipse.jgit.transport.http.HttpConnection;
import org.eclipse.jgit.transport.http.HttpConnectionFactory;
import org.eclipse.jgit.transport.http.apache.HttpClientConnection;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -51,10 +50,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
/**
* @author Dylan Roberts
@@ -93,130 +88,120 @@ public class ConfigurableHttpConnectionFactoryIntegrationTests {
HTTPS_PROXY.setPort(8081);
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void authenticatedHttpsProxy() throws Exception {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, null, AUTHENTICATED_HTTPS_PROXY)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(AUTHENTICATED_HTTPS_PROXY.getHost()))));
Assertions.assertThatThrownBy(() -> {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, null, AUTHENTICATED_HTTPS_PROXY)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
makeRequest(httpClient, "https://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(AUTHENTICATED_HTTPS_PROXY.getHost());
makeRequest(httpClient, "https://somehost");
}
@Test
public void httpsProxy() throws Exception {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, null, HTTPS_PROXY)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTPS_PROXY.getHost()))));
makeRequest(httpClient, "https://somehost");
Assertions.assertThatThrownBy(() -> {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, null, HTTPS_PROXY)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
makeRequest(httpClient, "https://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTPS_PROXY.getHost());
}
@Test
public void httpsProxy_placeholderUrl() throws Exception {
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties("https://myrepo/{placeholder1}/{placeholder2}-repo.git", null, HTTPS_PROXY))
.run();
HttpClient httpClient = getHttpClientForUrl(
"https://myrepo/someplaceholdervalue/anotherplaceholdervalue-repo.git");
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTPS_PROXY.getHost()))));
makeRequest(httpClient, "https://somehost");
Assertions.assertThatThrownBy(() -> {
String repoUrl = "https://myrepo/{placeholder1}/{placeholder2}-repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, null, HTTPS_PROXY)).run();
HttpClient httpClient = getHttpClientForUrl(
"https://myrepo/someplaceholdervalue/anotherplaceholdervalue-repo.git");
makeRequest(httpClient, "https://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTPS_PROXY.getHost());
}
@Test
public void httpsProxy_called_for_http_request_when_no_httpProxy_specified() throws Exception {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, null, HTTPS_PROXY)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTPS_PROXY.getHost()))));
makeRequest(httpClient, "http://somehost");
Assertions.assertThatThrownBy(() -> {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, null, HTTPS_PROXY)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
makeRequest(httpClient, "http://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTPS_PROXY.getHost());
}
@Test
public void authenticatedHttpProxy() throws Exception {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, AUTHENTICATED_HTTP_PROXY, null)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(AUTHENTICATED_HTTP_PROXY.getHost()))));
makeRequest(httpClient, "http://somehost");
Assertions.assertThatThrownBy(() -> {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, AUTHENTICATED_HTTP_PROXY, null)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
makeRequest(httpClient, "http://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(AUTHENTICATED_HTTP_PROXY.getHost());
}
@Test
public void httpProxy() throws Exception {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, HTTP_PROXY, null)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTP_PROXY.getHost()))));
makeRequest(httpClient, "http://somehost");
Assertions.assertThatThrownBy(() -> {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, HTTP_PROXY, null)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
makeRequest(httpClient, "http://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTP_PROXY.getHost());
}
@Test
public void httpProxy_placeholderUrl() throws Exception {
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties("https://myrepo/{placeholder}-repo.git", HTTP_PROXY, null)).run();
HttpClient httpClient = getHttpClientForUrl("https://myrepo/someplaceholdervalue-repo.git");
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTP_PROXY.getHost()))));
makeRequest(httpClient, "http://somehost");
Assertions.assertThatThrownBy(() -> {
String repoUrl = "https://myrepo/{placeholder}-repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, HTTP_PROXY, null)).run();
HttpClient httpClient = getHttpClientForUrl("https://myrepo/someplaceholdervalue-repo.git");
makeRequest(httpClient, "http://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTP_PROXY.getHost());
}
@Test
public void httpProxy_called_for_https_request_when_no_httpsProxy_specified() throws Exception {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, HTTP_PROXY, null)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTP_PROXY.getHost()))));
makeRequest(httpClient, "https://somehost");
Assertions.assertThatThrownBy(() -> {
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(gitProperties(repoUrl, HTTP_PROXY, null)).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
makeRequest(httpClient, "https://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTP_PROXY.getHost());
}
@Test
public void httpProxy_fromSystemProperty() throws Exception {
ProxySelector defaultProxySelector = ProxySelector.getDefault();
try {
ProxySelector.setDefault(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
InetSocketAddress address = new InetSocketAddress(HTTP_PROXY.getHost(), HTTP_PROXY.getPort());
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
return Collections.singletonList(proxy);
}
Assertions.assertThatThrownBy(() -> {
ProxySelector.setDefault(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
InetSocketAddress address = new InetSocketAddress(HTTP_PROXY.getHost(), HTTP_PROXY.getPort());
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
return Collections.singletonList(proxy);
}
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
}
});
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(new String[] { "spring.cloud.config.server.git.uri=" + repoUrl }).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
this.expectedException.expectCause(allOf(instanceOf(UnknownHostException.class),
hasProperty("message", containsString(HTTP_PROXY.getHost()))));
makeRequest(httpClient, "http://somehost");
}
});
String repoUrl = "https://myrepo/repo.git";
new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties(new String[] { "spring.cloud.config.server.git.uri=" + repoUrl }).run();
HttpClient httpClient = getHttpClientForUrl(repoUrl);
makeRequest(httpClient, "http://somehost");
}).hasCauseInstanceOf(UnknownHostException.class).hasMessageContaining(HTTP_PROXY.getHost());
}
finally {
ProxySelector.setDefault(defaultProxySelector);

View File

@@ -18,8 +18,8 @@ package org.springframework.cloud.config.server.environment;
import java.util.HashMap;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.cloud.config.environment.Environment;
@@ -47,7 +47,7 @@ public class CredhubEnvironmentRepositoryTests {
private CredHubCredentialOperations credhubCredentialOperations;
@Before
@BeforeEach
public void setUp() {
CredHubOperations credhubOperations = Mockito.mock(CredHubOperations.class);
this.credhubCredentialOperations = Mockito.mock(CredHubCredentialOperations.class);

View File

@@ -21,9 +21,9 @@ import java.util.HashMap;
import java.util.Map;
import io.micrometer.observation.ObservationRegistry;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
@@ -48,7 +48,7 @@ public class EnvironmentEncryptorEnvironmentRepositoryTests {
private Environment environment = new Environment("foo", "master");
@Before
@BeforeEach
public void init() {
this.controller = new EnvironmentEncryptorEnvironmentRepository(this.repository, ObservationRegistry.NOOP);
}

View File

@@ -29,7 +29,8 @@ import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;
import com.google.cloud.secretmanager.v1.SecretPayload;
import com.google.cloud.secretmanager.v1.SecretVersion;
import com.google.protobuf.ByteString;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatcher;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
@@ -57,12 +58,14 @@ public class GoogleSecretManagerEnvironmentRepositoryTests {
mock) instanceof GoogleSecretManagerV1AccessStrategy).isTrue();
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testGetUnsupportedStrategy() {
GoogleSecretManagerEnvironmentProperties properties = new GoogleSecretManagerEnvironmentProperties();
SecretManagerServiceClient mock = mock(SecretManagerServiceClient.class);
properties.setVersion(2);
GoogleSecretManagerAccessStrategyFactory.forVersion(null, null, properties, mock);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
GoogleSecretManagerEnvironmentProperties properties = new GoogleSecretManagerEnvironmentProperties();
SecretManagerServiceClient mock = mock(SecretManagerServiceClient.class);
properties.setVersion(2);
GoogleSecretManagerAccessStrategyFactory.forVersion(null, null, properties, mock);
});
}
@Test

View File

@@ -25,8 +25,8 @@ import java.util.Objects;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.eclipse.jgit.transport.http.HttpConnection;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.util.ReflectionUtils;
@@ -36,7 +36,7 @@ public class HttpClientConfigurableHttpConnectionFactoryTest {
private HttpClientConfigurableHttpConnectionFactory connectionFactory;
@Before
@BeforeEach
public void setUp() {
this.connectionFactory = new HttpClientConfigurableHttpConnectionFactory();
}

View File

@@ -17,8 +17,9 @@
package org.springframework.cloud.config.server.environment;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -35,23 +36,28 @@ public class HttpRequestConfigTokenProviderTests {
private HttpRequestConfigTokenProvider tokenProvider;
@Before
@BeforeEach
@SuppressWarnings("unchecked")
public void setUp() {
httpRequestProvider = mock(ObjectProvider.class);
tokenProvider = new HttpRequestConfigTokenProvider(httpRequestProvider);
}
@Test(expected = IllegalStateException.class)
@Test
public void missingHttpRequest() {
when(httpRequestProvider.getIfAvailable()).thenReturn(null);
tokenProvider.getToken();
Assertions.assertThrows(IllegalStateException.class, () -> {
when(httpRequestProvider.getIfAvailable()).thenReturn(null);
tokenProvider.getToken();
});
}
@Test(expected = IllegalArgumentException.class)
@Test
public void missingTokenHeader() {
when(httpRequestProvider.getIfAvailable()).thenReturn(new MockHttpServletRequest());
tokenProvider.getToken();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
when(httpRequestProvider.getIfAvailable()).thenReturn(new MockHttpServletRequest());
tokenProvider.getToken();
});
}
}

View File

@@ -44,10 +44,10 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -75,13 +75,13 @@ public class JGitEnvironmentRepositoryConcurrencyTests {
private File basedir = new File("target/config");
@BeforeClass
@BeforeAll
public static void initClass() {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
}
@Before
@BeforeEach
public void init() throws Exception {
if (this.basedir.exists()) {
FileUtils.delete(this.basedir, FileUtils.RECURSIVE);
@@ -89,7 +89,7 @@ public class JGitEnvironmentRepositoryConcurrencyTests {
ConfigServerTestUtils.deleteLocalRepo("config-copy");
}
@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();

View File

@@ -40,11 +40,12 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.WebApplicationType;
@@ -77,13 +78,13 @@ public class JGitEnvironmentRepositoryIntegrationTests {
private File basedir = new File("target/config");
@BeforeClass
@BeforeAll
public static void initClass() {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
}
@Before
@BeforeEach
public void init() throws Exception {
if (this.basedir.exists()) {
FileUtils.delete(this.basedir, FileUtils.RECURSIVE);
@@ -91,7 +92,7 @@ public class JGitEnvironmentRepositoryIntegrationTests {
ConfigServerTestUtils.deleteLocalRepo("");
}
@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();
@@ -111,15 +112,17 @@ public class JGitEnvironmentRepositoryIntegrationTests {
assertThat(environment.getLabel()).isEqualTo("master");
}
@Test(expected = NoSuchLabelException.class)
public void shouldFailIfNotTryingMaster() throws IOException {
String uri = ConfigServerTestUtils.prepareLocalRepo();
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties("spring.cloud.config.server.git.uri:" + uri,
"spring.cloud.config.server.git.tryMasterBranch:false")
.run();
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
Environment environment = repository.findOne("bar", "staging", null);
@Test
public void shouldFailIfNotTryingMaster() {
Assertions.assertThrows(NoSuchLabelException.class, () -> {
String uri = ConfigServerTestUtils.prepareLocalRepo();
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties("spring.cloud.config.server.git.uri:" + uri,
"spring.cloud.config.server.git.tryMasterBranch:false")
.run();
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
Environment environment = repository.findOne("bar", "staging", null);
});
}
@Test
@@ -233,7 +236,7 @@ public class JGitEnvironmentRepositoryIntegrationTests {
}
@Test
@Ignore // see https://github.com/spring-projects/spring-framework/issues/29333
@Disabled // see https://github.com/spring-projects/spring-framework/issues/29333
public void verifyPropertySourceOrdering() throws IOException {
String uri = ConfigServerTestUtils.prepareLocalRepo("ordering-repo");
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
@@ -280,13 +283,15 @@ public class JGitEnvironmentRepositoryIntegrationTests {
assertThat(repository.getDefaultLabel()).isEqualTo(JGitEnvironmentProperties.MAIN_LABEL);
}
@Test(expected = NoSuchLabelException.class)
public void invalidLabel() throws IOException {
String uri = ConfigServerTestUtils.prepareLocalRepo();
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties("spring.cloud.config.server.git.uri:" + uri).run();
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "unknownlabel");
@Test
public void invalidLabel() {
Assertions.assertThrows(NoSuchLabelException.class, () -> {
String uri = ConfigServerTestUtils.prepareLocalRepo();
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties("spring.cloud.config.server.git.uri:" + uri).run();
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "unknownlabel");
});
}
@Test
@@ -335,15 +340,17 @@ public class JGitEnvironmentRepositoryIntegrationTests {
assertThat(environment.getPropertySources().size()).isEqualTo(2);
}
@Test(expected = NoSuchLabelException.class)
@Test
public void findOne_FindInvalidLabel_IllegalStateExceptionThrown() throws IOException {
String uri = ConfigServerTestUtils.prepareLocalRepo();
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties("spring.cloud.config.server.git.uri:" + uri,
"--spring.cloud.config.server.git.cloneOnStart=true")
.run();
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "unknownlabel");
Assertions.assertThrows(NoSuchLabelException.class, () -> {
String uri = ConfigServerTestUtils.prepareLocalRepo();
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties("spring.cloud.config.server.git.uri:" + uri,
"--spring.cloud.config.server.git.cloneOnStart=true")
.run();
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "unknownlabel");
});
}
@Test
@@ -549,11 +556,13 @@ public class JGitEnvironmentRepositoryIntegrationTests {
assertThat("bar").isEqualTo(fooProperty);
}
@Test(expected = NoSuchLabelException.class)
@Test
public void testUnknownLabelWithRemote() throws Exception {
JGitConfigServerTestData testData = JGitConfigServerTestData
.prepareClonedGitRepository(TestConfiguration.class);
testData.getRepository().findOne("bar", "staging", "BADLabel");
Assertions.assertThrows(NoSuchLabelException.class, () -> {
JGitConfigServerTestData testData = JGitConfigServerTestData
.prepareClonedGitRepository(TestConfiguration.class);
testData.getRepository().findOne("bar", "staging", "BADLabel");
});
}
private String getCommitID(Git git, String label) throws GitAPIException {
@@ -610,24 +619,26 @@ public class JGitEnvironmentRepositoryIntegrationTests {
assertThat(environment).isNotNull();
}
@Test(expected = NoSuchLabelException.class)
@Test
public void testShouldFailIfRemoteBranchWasDeleted() throws Exception {
JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(
Collections.singleton("spring.cloud.config.server.git.deleteUntrackedBranches=true"),
TestConfiguration.class);
Assertions.assertThrows(NoSuchLabelException.class, () -> {
JGitConfigServerTestData testData = JGitConfigServerTestData.prepareClonedGitRepository(
Collections.singleton("spring.cloud.config.server.git.deleteUntrackedBranches=true"),
TestConfiguration.class);
String branchToDelete = "branchToDelete";
testData.getServerGit().getGit().branchCreate().setName(branchToDelete).call();
String branchToDelete = "branchToDelete";
testData.getServerGit().getGit().branchCreate().setName(branchToDelete).call();
// checkout and simulate regular flow
Environment environment = testData.getRepository().findOne("bar", "staging", "branchToDelete");
assertThat(environment).isNotNull();
// checkout and simulate regular flow
Environment environment = testData.getRepository().findOne("bar", "staging", "branchToDelete");
assertThat(environment).isNotNull();
// remove branch
testData.getServerGit().getGit().branchDelete().setBranchNames(branchToDelete).call();
// remove branch
testData.getServerGit().getGit().branchDelete().setBranchNames(branchToDelete).call();
// test
testData.getRepository().findOne("bar", "staging", "branchToDelete");
// test
testData.getRepository().findOne("bar", "staging", "branchToDelete");
});
}
@Configuration(proxyBeanMethods = false)

View File

@@ -26,10 +26,11 @@ import java.util.List;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.junit.http.SimpleHttpServer;
import org.eclipse.jgit.lib.Repository;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -42,12 +43,12 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
// FIXME: 4.0.0 https://bugs.eclipse.org/bugs/show_bug.cgi?id=570447
@Ignore("SimpleHttpServer does not use jakarta.servlet")
@Disabled("SimpleHttpServer does not use jakarta.servlet")
public class JGitEnvironmentRepositorySslTests {
private static SimpleHttpServer server;
@BeforeClass
@BeforeAll
public static void setup() throws Exception {
URL repoUrl = JGitEnvironmentRepositorySslTests.class.getResource("/test1-config-repo/git");
Repository repo = new FileRepository(new File(repoUrl.toURI()));
@@ -55,7 +56,7 @@ public class JGitEnvironmentRepositorySslTests {
server.start();
}
@AfterClass
@AfterAll
public static void teardown() throws Exception {
server.stop();
}
@@ -68,25 +69,27 @@ public class JGitEnvironmentRepositorySslTests {
return properties.toArray(new String[0]);
}
@Test(expected = CertificateException.class)
public void selfSignedCertIsRejected() throws Throwable {
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
.properties(configServerProperties()).web(WebApplicationType.NONE).run();
@Test
public void selfSignedCertIsRejected() {
Assertions.assertThrows(CertificateException.class, () -> {
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
.properties(configServerProperties()).web(WebApplicationType.NONE).run();
JGitEnvironmentRepository repository = context.getBean(JGitEnvironmentRepository.class);
JGitEnvironmentRepository repository = context.getBean(JGitEnvironmentRepository.class);
try {
repository.findOne("bar", "staging", "master");
}
catch (Throwable e) {
while (e.getCause() != null) {
e = e.getCause();
if (e instanceof CertificateException) {
break;
}
try {
repository.findOne("bar", "staging", "master");
}
throw e;
}
catch (Throwable e) {
while (e.getCause() != null) {
e = e.getCause();
if (e instanceof CertificateException) {
break;
}
}
throw e;
}
});
}
@Test

View File

@@ -65,11 +65,11 @@ import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
@@ -109,13 +109,13 @@ public class JGitEnvironmentRepositoryTests {
private File basedir = new File("target/config");
@BeforeClass
@BeforeAll
public static void initClass() {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
}
@Before
@BeforeEach
public void init() throws Exception {
String uri = ConfigServerTestUtils.prepareLocalRepo();
this.repository = new JGitEnvironmentRepository(this.environment, new JGitEnvironmentProperties(),
@@ -166,7 +166,7 @@ public class JGitEnvironmentRepositoryTests {
}
@Test
@Ignore // see https://github.com/spring-projects/spring-framework/issues/29333
@Disabled // see https://github.com/spring-projects/spring-framework/issues/29333
public void nestedPattern() throws IOException {
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
this.repository.setUri(uri);

View File

@@ -21,7 +21,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.boot.test.context.runner.ContextConsumer;

View File

@@ -18,8 +18,7 @@ package org.springframework.cloud.config.server.environment;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -32,7 +31,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -41,7 +39,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
* @author Dave Syer
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ApplicationConfiguration.class,
properties = { "logging.level.root=debug", "spring.sql.init.schema-locations=classpath:schema-jdbc.sql",
"spring.sql.init.data-locations=classpath:data-jdbc.sql" })

View File

@@ -22,10 +22,10 @@ import java.util.Map;
import io.micrometer.observation.ObservationRegistry;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository;
@@ -46,13 +46,13 @@ public class MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests {
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(this.environment,
new MultipleJGitEnvironmentProperties(), ObservationRegistry.NOOP);
@BeforeClass
@BeforeAll
public static void initClass() {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
}
@Before
@BeforeEach
public void init() throws Exception {
String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
this.repository.setUri(defaultUri);
@@ -116,7 +116,7 @@ public class MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests {
}
@Test
@Ignore("not supported yet (placeholders in search paths with lists)")
@Disabled("not supported yet (placeholders in search paths with lists)")
public void profilesInSearchPaths() {
this.repository.setSearchPaths("{profile}");
Locations locations = this.repository.getLocations("foo", "dev,one,two", "master");

View File

@@ -19,9 +19,9 @@ package org.springframework.cloud.config.server.environment;
import io.micrometer.observation.ObservationRegistry;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
@@ -43,13 +43,13 @@ public class MultipleJGitEnvironmentLabelPlaceholderRepositoryTests {
private String defaultUri;
@BeforeClass
@BeforeAll
public static void initClass() {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
}
@Before
@BeforeEach
public void init() throws Exception {
this.defaultUri = ConfigServerTestUtils.prepareLocalRepo("master-labeltest-config-repo");
this.repository.setUri(this.defaultUri.replace("master-", "{label}-"));

View File

@@ -23,9 +23,9 @@ import java.util.Map;
import io.micrometer.observation.ObservationRegistry;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository;
@@ -48,13 +48,13 @@ public class MultipleJGitEnvironmentProfilePlaceholderRepositoryTests {
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(this.environment,
new MultipleJGitEnvironmentProperties(), ObservationRegistry.NOOP);
@BeforeClass
@BeforeAll
public static void initClass() {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
}
@Before
@BeforeEach
public void init() throws Exception {
String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
this.repository.setUri(defaultUri);

View File

@@ -20,7 +20,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import org.springframework.cloud.config.server.support.GitCredentialsProviderFactory;

View File

@@ -25,13 +25,10 @@ import org.assertj.core.api.Assertions;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.matchers.ThrowableMessageMatcher;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -46,7 +43,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
/**
* @author Andy Chan (iceycake)
@@ -55,20 +51,17 @@ import static org.hamcrest.CoreMatchers.containsString;
*/
public class MultipleJGitEnvironmentRepositoryIntegrationTests {
@Rule
public ExpectedException expected = ExpectedException.none();
private ConfigurableApplicationContext context;
private File basedir = new File("target/config");
@BeforeClass
@BeforeAll
public static void initClass() {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
}
@Before
@BeforeEach
public void init() throws Exception {
if (this.basedir.exists()) {
FileUtils.delete(this.basedir, FileUtils.RECURSIVE);
@@ -76,7 +69,7 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
ConfigServerTestUtils.deleteLocalRepo("config-copy");
}
@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();
@@ -190,13 +183,14 @@ public class MultipleJGitEnvironmentRepositoryIntegrationTests {
}
@Test
public void nonWritableBasedir() throws IOException {
String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
this.expected.expectCause(ThrowableMessageMatcher.hasMessage(containsString("Cannot write parent")));
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties("spring.cloud.config.server.git.uri:" + defaultRepoUri,
"spring.cloud.config.server.git.basedir:/tmp")
.run();
public void nonWritableBasedir() {
Assertions.assertThatThrownBy(() -> {
String defaultRepoUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.properties("spring.cloud.config.server.git.uri:" + defaultRepoUri,
"spring.cloud.config.server.git.basedir:/tmp")
.run();
}).hasMessageContaining("Cannot write parent");
}
@Test

View File

@@ -24,14 +24,13 @@ import java.util.HashMap;
import java.util.Map;
import io.micrometer.observation.ObservationRegistry;
import org.assertj.core.api.Assertions;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository;
@@ -51,20 +50,17 @@ import static org.mockito.Mockito.when;
*/
public class MultipleJGitEnvironmentRepositoryTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private StandardEnvironment environment = new StandardEnvironment();
private MultipleJGitEnvironmentRepository repository;
@BeforeClass
@BeforeAll
public static void initClass() {
// mock Git configuration to make tests independent of local Git configuration
SystemReader.setInstance(new MockSystemReader());
}
@Before
@BeforeEach
public void init() throws Exception {
String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
this.repository = new MultipleJGitEnvironmentRepository(this.environment,
@@ -306,19 +302,19 @@ public class MultipleJGitEnvironmentRepositoryTests {
@Test
// test for gh-700
public void exceptionThrownIfBasedirDoesnotExistAndCannotBeCreated() throws Exception {
File basedir = mock(File.class);
File absoluteBasedir = mock(File.class);
when(basedir.getAbsoluteFile()).thenReturn(absoluteBasedir);
Assertions.assertThatThrownBy(() -> {
File basedir = mock(File.class);
File absoluteBasedir = mock(File.class);
when(basedir.getAbsoluteFile()).thenReturn(absoluteBasedir);
when(absoluteBasedir.exists()).thenReturn(false);
when(absoluteBasedir.mkdir()).thenReturn(false);
when(absoluteBasedir.exists()).thenReturn(false);
when(absoluteBasedir.mkdir()).thenReturn(false);
this.repository.setBasedir(basedir);
this.repository.setBasedir(basedir);
this.exception.expect(IllegalStateException.class);
this.exception.expectMessage("Basedir does not exist and can not be created:");
this.repository.afterPropertiesSet();
this.repository.afterPropertiesSet();
}).isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Basedir does not exist and can not be created:");
}
@Test

View File

@@ -17,7 +17,7 @@
package org.springframework.cloud.config.server.environment;
import io.micrometer.observation.ObservationRegistry;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import org.springframework.core.env.StandardEnvironment;

View File

@@ -20,9 +20,9 @@ import java.util.Collections;
import java.util.regex.Matcher;
import io.micrometer.observation.ObservationRegistry;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -44,7 +44,7 @@ public class NativeEnvironmentRepositoryTests {
private NativeEnvironmentRepository repository;
@Before
@BeforeEach
public void init() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(NativeEnvironmentRepositoryTests.class)
.properties("logging.level.org.springframework.boot.context.config=TRACE").web(WebApplicationType.NONE)
@@ -150,7 +150,7 @@ public class NativeEnvironmentRepositoryTests {
}
@Test
@Ignore // FIXME: configdata
@Disabled // FIXME: configdata
public void labelled() {
this.repository.setSearchLocations("classpath:/test");
Environment environment = this.repository.findOne("foo", "development", "dev", false);

View File

@@ -20,7 +20,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.cloud.config.environment.Environment;

View File

@@ -22,9 +22,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc2.SvnCheckout;
@@ -58,7 +59,7 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
private File workingDir;
@Before
@BeforeEach
public void init() {
this.workingDir = new File("target/repos/svn-config-repo-update");
if (this.workingDir.exists()) {
@@ -66,7 +67,7 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
}
}
@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();
@@ -122,14 +123,17 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
assertThat(repository.getDefaultLabel()).isEqualTo("trunk");
}
@Test(expected = NoSuchLabelException.class)
public void invalidLabel() throws Exception {
String uri = ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo", "target/config");
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.profiles("subversion").run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
Environment environment = repository.findOne("bar", "staging", "unknownlabel");
assertThat(environment.getPropertySources().size()).isEqualTo(0);
@Test
public void invalidLabel() {
Assertions.assertThatThrownBy(() -> {
String uri = ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo",
"target/config");
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(WebApplicationType.NONE)
.profiles("subversion").run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
Environment environment = repository.findOne("bar", "staging", "unknownlabel");
assertThat(environment.getPropertySources().size()).isEqualTo(0);
}).isInstanceOf(NoSuchLabelException.class);
}
@Test

View File

@@ -20,9 +20,10 @@ import java.io.File;
import java.io.IOException;
import io.micrometer.observation.ObservationRegistry;
import org.assertj.core.api.Assertions;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -49,7 +50,7 @@ public class SVNKitEnvironmentRepositoryTests {
private File basedir = new File("target/config");
@Before
@BeforeEach
public void init() throws Exception {
String uri = ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/" + REPOSITORY_NAME,
"target/repos/" + REPOSITORY_NAME);
@@ -114,10 +115,12 @@ public class SVNKitEnvironmentRepositoryTests {
assertThat(environment.getPropertySources().get(1).getName().contains("application.yml")).isTrue();
}
@Test(expected = NoSuchLabelException.class)
@Test
public void invalidLabel() {
Environment environment = this.repository.findOne("bar", "staging", "unknownlabel");
assertThat(environment.getPropertySources().size()).isEqualTo(0);
Assertions.assertThatThrownBy(() -> {
Environment environment = this.repository.findOne("bar", "staging", "unknownlabel");
assertThat(environment.getPropertySources().size()).isEqualTo(0);
}).isInstanceOf(NoSuchLabelException.class);
}
@Test

View File

@@ -21,10 +21,8 @@ import java.util.Optional;
import javax.net.ssl.SSLHandshakeException;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringApplication;
@@ -33,40 +31,35 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Dylan Roberts
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VaultEnvironmentRepositoryIntegrationTests.TestApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "server.ssl.key-store=classpath:ssl-test.jks", "server.ssl.key-store-password=password",
"server.ssl.key-password=password", "server.key-alias=ssl-test" })
public class VaultEnvironmentRepositoryIntegrationTests {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@LocalServerPort
private String localServerPort;
@Test
public void withSslValidation() throws Exception {
ObjectProvider<HttpServletRequest> request = withRequest();
VaultEnvironmentRepositoryFactory vaultEnvironmentRepositoryFactory = new VaultEnvironmentRepositoryFactory(
request, new EnvironmentWatch.Default(), Optional.of(new HttpClientVaultRestTemplateFactory()),
withTokenProvider(request));
VaultEnvironmentRepository vaultEnvironmentRepository = vaultEnvironmentRepositoryFactory
.build(withEnvironmentProperties(false));
this.expectedException.expectCause(instanceOf(SSLHandshakeException.class));
vaultEnvironmentRepository.findOne("application", "profile", "label");
Assertions.assertThatThrownBy(() -> {
ObjectProvider<HttpServletRequest> request = withRequest();
VaultEnvironmentRepositoryFactory vaultEnvironmentRepositoryFactory = new VaultEnvironmentRepositoryFactory(
request, new EnvironmentWatch.Default(), Optional.of(new HttpClientVaultRestTemplateFactory()),
withTokenProvider(request));
VaultEnvironmentRepository vaultEnvironmentRepository = vaultEnvironmentRepositoryFactory
.build(withEnvironmentProperties(false));
vaultEnvironmentRepository.findOne("application", "profile", "label");
}).hasCauseInstanceOf(SSLHandshakeException.class);
}
@Test

View File

@@ -22,8 +22,9 @@ import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.Before;
import org.junit.Test;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.config.environment.Environment;
@@ -55,7 +56,7 @@ public class VaultEnvironmentRepositoryTests {
private ObjectMapper objectMapper;
@Before
@BeforeEach
public void init() {
this.objectMapper = new ObjectMapper();
}
@@ -285,15 +286,17 @@ public class VaultEnvironmentRepositoryTests {
.as("Properties should be returned for specified application").isEqualTo(result);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void missingConfigToken() {
ConfigTokenProvider tokenProvider = mock(ConfigTokenProvider.class);
when(tokenProvider.getToken()).thenReturn(null);
Assertions.assertThatThrownBy(() -> {
ConfigTokenProvider tokenProvider = mock(ConfigTokenProvider.class);
when(tokenProvider.getToken()).thenReturn(null);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(mockHttpRequest(),
new EnvironmentWatch.Default(), mock(RestTemplate.class), new VaultEnvironmentProperties(),
tokenProvider);
repo.findOne("myapp", null, null);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(mockHttpRequest(),
new EnvironmentWatch.Default(), mock(RestTemplate.class), new VaultEnvironmentProperties(),
tokenProvider);
repo.findOne("myapp", null, null);
}).isInstanceOf(IllegalArgumentException.class);
}
@Test

View File

@@ -16,7 +16,8 @@
package org.springframework.cloud.config.server.environment;
import org.junit.Test;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.server.environment.VaultKvAccessStrategyFactory.V1VaultKvAccessStrategy;
import org.springframework.cloud.config.server.environment.VaultKvAccessStrategyFactory.V2VaultKvAccessStrategy;
@@ -40,9 +41,10 @@ public class VaultKvAccessStrategyFactoryTest {
assertThat(vaultKvAccessStrategy instanceof V2VaultKvAccessStrategy).isTrue();
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testGetUnsupportedStrategy() {
VaultKvAccessStrategyFactory.forVersion(null, "foo", 0, "");
Assertions.assertThatThrownBy(() -> VaultKvAccessStrategyFactory.forVersion(null, "foo", 0, ""))
.isInstanceOf(IllegalArgumentException.class);
}
}

View File

@@ -20,7 +20,7 @@ import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.config.server.environment.VaultKvAccessStrategy.VaultResponse;

View File

@@ -17,7 +17,7 @@
package org.springframework.cloud.config.server.environment.vault;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.config.server.environment.EnvironmentWatch;

View File

@@ -20,7 +20,7 @@ import java.util.HashMap;
import java.util.Map;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.config.environment.Environment;

View File

@@ -20,16 +20,17 @@ import java.io.IOException;
import java.net.URL;
import io.micrometer.observation.ObservationRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import software.amazon.awssdk.services.s3.S3Client;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import org.springframework.cloud.config.server.environment.AwsS3EnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentProperties;
@@ -41,7 +42,6 @@ import org.springframework.core.io.ResourceLoader;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -50,28 +50,24 @@ import static org.mockito.Mockito.when;
* @author Dave Syer
*
*/
@ExtendWith(OutputCaptureExtension.class)
public class GenericResourceRepositoryTests {
@Rule
public OutputCaptureRule output = new OutputCaptureRule();
@Rule
public ExpectedException exception = ExpectedException.none();
private GenericResourceRepository repository;
private ConfigurableApplicationContext context;
private NativeEnvironmentRepository nativeRepository;
@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();
}
}
@Before
@BeforeEach
public void init() {
this.context = new SpringApplicationBuilder(NativeEnvironmentRepositoryTests.class).web(WebApplicationType.NONE)
.run();
@@ -98,50 +94,57 @@ public class GenericResourceRepositoryTests {
assertThat(this.repository.findOne("blah", "local", "master", "foo.txt")).isNotNull();
}
@Test(expected = NoSuchResourceException.class)
@Test
public void locateMissingResource() {
assertThat(this.repository.findOne("blah", "default", "master", "foo.txt")).isNotNull();
Assertions
.assertThatThrownBy(
() -> assertThat(this.repository.findOne("blah", "default", "master", "foo.txt")).isNotNull())
.isInstanceOf(NoSuchResourceException.class);
}
@Test
public void invalidPath() {
this.exception.expect(NoSuchResourceException.class);
this.nativeRepository.setSearchLocations("file:./src/test/resources/test/{profile}");
this.output.expect(containsString("Path contains \"../\" after call to StringUtils#cleanPath"));
this.repository.findOne("blah", "local", "master", "..%2F..%2Fdata-jdbc.sql");
public void invalidPath(CapturedOutput capturedOutput) {
Assertions.assertThatThrownBy(() -> {
this.nativeRepository.setSearchLocations("file:./src/test/resources/test/{profile}");
this.repository.findOne("blah", "local", "master", "..%2F..%2Fdata-jdbc.sql");
}).isInstanceOf(NoSuchResourceException.class);
Assertions.assertThat(capturedOutput.getAll())
.contains("Path contains \"../\" after call to StringUtils#cleanPath");
}
@Test
public void invalidPathWithPreviousDirectory() {
testInvalidPath("../");
public void invalidPathWithPreviousDirectory(CapturedOutput capturedOutput) {
testInvalidPath("../", capturedOutput);
}
@Test
public void invalidPathWithPreviousDirectoryEncodedSlash() {
testInvalidPath("..%2F");
public void invalidPathWithPreviousDirectoryEncodedSlash(CapturedOutput capturedOutput) {
testInvalidPath("..%2F", capturedOutput);
}
@Test
public void invalidPathWithPreviousDirectoryAllEncoded() {
testInvalidPath("%2E%2E%2F");
public void invalidPathWithPreviousDirectoryAllEncoded(CapturedOutput capturedOutput) {
testInvalidPath("%2E%2E%2F", capturedOutput);
}
@Test
public void invalidPathEncodedSlash() {
String file = System.getProperty("user.dir");
file = file.replaceFirst("\\/", "%2f");
file += "/src/test/resources/ssh/key";
this.exception.expect(NoSuchResourceException.class);
this.nativeRepository.setSearchLocations("file:./");
this.output.expect(containsString("is neither under the current location"));
this.repository.findOne("blah", "local", "master", file);
public void invalidPathEncodedSlash(CapturedOutput capturedOutput) {
Assertions.assertThatThrownBy(() -> {
String file = System.getProperty("user.dir");
file = file.replaceFirst("\\/", "%2f");
file += "/src/test/resources/ssh/key";
this.nativeRepository.setSearchLocations("file:./");
this.repository.findOne("blah", "local", "master", file);
}).isInstanceOf(NoSuchResourceException.class);
Assertions.assertThat(capturedOutput.getAll()).contains("is neither under the current location");
}
private void testInvalidPath(String label) {
this.exception.expect(NoSuchResourceException.class);
this.nativeRepository.setSearchLocations("file:./src/test/resources/test/local");
this.output.expect(containsString("Location contains \"..\""));
this.repository.findOne("blah", "local", label, "foo.properties");
private void testInvalidPath(String label, CapturedOutput capturedOutput) {
Assertions.assertThatThrownBy(() -> {
this.nativeRepository.setSearchLocations("file:./src/test/resources/test/local");
this.repository.findOne("blah", "local", label, "foo.properties");
}).isInstanceOf(NoSuchResourceException.class);
Assertions.assertThat(capturedOutput.getAll()).contains("Location contains \"..\"");
}
@Test

View File

@@ -19,9 +19,8 @@ package org.springframework.cloud.config.server.resource;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
@@ -41,7 +40,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@@ -59,7 +57,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
* @author Daniel Lavoie
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ControllerConfiguration.class, webEnvironment = RANDOM_PORT)
@DirtiesContext
public class ResourceControllerIntegrationTests {
@@ -78,7 +75,7 @@ public class ResourceControllerIntegrationTests {
@LocalServerPort
int port;
@Before
@BeforeEach
public void init() {
Mockito.reset(this.repository, this.resources);
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();

Some files were not shown because too many files have changed in this diff Show More