diff --git a/spring-cloud-config-client-tls-tests/pom.xml b/spring-cloud-config-client-tls-tests/pom.xml index ff057a05..b7382269 100644 --- a/spring-cloud-config-client-tls-tests/pom.xml +++ b/spring-cloud-config-client-tls-tests/pom.xml @@ -92,8 +92,8 @@ test - org.junit.vintage - junit-vintage-engine + org.junit.platform + junit-platform-launcher test diff --git a/spring-cloud-config-client-tls-tests/src/test/java/org/springframework/cloud/config/client/tls/AbstractTlsSetup.java b/spring-cloud-config-client-tls-tests/src/test/java/org/springframework/cloud/config/client/tls/AbstractTlsSetup.java index e09ea4a7..e116ca7f 100644 --- a/spring-cloud-config-client-tls-tests/src/test/java/org/springframework/cloud/config/client/tls/AbstractTlsSetup.java +++ b/spring-cloud-config-client-tls-tests/src/test/java/org/springframework/cloud/config/client/tls/AbstractTlsSetup.java @@ -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(); diff --git a/spring-cloud-config-client-tls-tests/src/test/java/org/springframework/cloud/config/client/tls/ConfigClientTlsTests.java b/spring-cloud-config-client-tls-tests/src/test/java/org/springframework/cloud/config/client/tls/ConfigClientTlsTests.java index dbeb5fd8..c9213c6f 100644 --- a/spring-cloud-config-client-tls-tests/src/test/java/org/springframework/cloud/config/client/tls/ConfigClientTlsTests.java +++ b/spring-cloud-config-client-tls-tests/src/test/java/org/springframework/cloud/config/client/tls/ConfigClientTlsTests.java @@ -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 diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index 11398624..0ac027a2 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -86,8 +86,8 @@ test - org.junit.vintage - junit-vintage-engine + org.junit.platform + junit-platform-launcher test diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/BaseDiscoveryClientConfigServiceBootstrapConfigurationTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/BaseDiscoveryClientConfigServiceBootstrapConfigurationTests.java index d6ffdddd..df1fd00e 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/BaseDiscoveryClientConfigServiceBootstrapConfigurationTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/BaseDiscoveryClientConfigServiceBootstrapConfigurationTests.java @@ -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.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); diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigClientPropertiesTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigClientPropertiesTests.java index 86fcfe9d..83d0dd98 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigClientPropertiesTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigClientPropertiesTests.java @@ -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 diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigClientWatchTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigClientWatchTests.java index 8773cf89..28c7082c 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigClientWatchTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigClientWatchTests.java @@ -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; diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServerBootstrapConfigurationTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServerBootstrapConfigurationTests.java index 2fb8263c..3bc06345 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServerBootstrapConfigurationTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServerBootstrapConfigurationTests.java @@ -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; diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfigurationTest.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfigurationTest.java index be7d3fc0..cf68b4b2 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfigurationTest.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServiceBootstrapConfigurationTest.java @@ -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(); diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java index 2423baa7..aff87d90 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocatorTests.java @@ -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 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 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") diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigDataConfigurationNoRetryTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigDataConfigurationNoRetryTests.java index bbb35bf5..1bf01f9f 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigDataConfigurationNoRetryTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigDataConfigurationNoRetryTests.java @@ -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(); diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigServiceBootstrapConfigurationNoSpringRetryTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigServiceBootstrapConfigurationNoSpringRetryTests.java index af83aee6..c62447d4 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigServiceBootstrapConfigurationNoSpringRetryTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigServiceBootstrapConfigurationNoSpringRetryTests.java @@ -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 diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigServiceBootstrapConfigurationTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigServiceBootstrapConfigurationTests.java index 0b46b3e7..fd7eb797 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigServiceBootstrapConfigurationTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/client/DiscoveryClientConfigServiceBootstrapConfigurationTests.java @@ -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 diff --git a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/environment/EnvironmentTests.java b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/environment/EnvironmentTests.java index e72b7453..dcf85566 100644 --- a/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/environment/EnvironmentTests.java +++ b/spring-cloud-config-client/src/test/java/org/springframework/cloud/config/environment/EnvironmentTests.java @@ -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; diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index 3315c44a..7f3fa558 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -47,8 +47,8 @@ test - org.junit.vintage - junit-vintage-engine + org.junit.platform + junit-platform-launcher test diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/BitbucketPropertyPathNotificationExtractorTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/BitbucketPropertyPathNotificationExtractorTests.java index 48e1193c..ae6ea92d 100644 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/BitbucketPropertyPathNotificationExtractorTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/BitbucketPropertyPathNotificationExtractorTests.java @@ -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(); } diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/CompositePropertyPathNotificationExtractorTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/CompositePropertyPathNotificationExtractorTests.java index c889d616..6fae4cd8 100644 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/CompositePropertyPathNotificationExtractorTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/CompositePropertyPathNotificationExtractorTests.java @@ -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; diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfigurationTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfigurationTests.java index 6fefe54b..a83905a7 100644 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfigurationTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfigurationTests.java @@ -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; diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/FileMonitorConfigurationTest.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/FileMonitorConfigurationTest.java index 162cfafa..bf7b9ce3 100644 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/FileMonitorConfigurationTest.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/FileMonitorConfigurationTest.java @@ -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 repositories = new ArrayList<>(); - @Before + @BeforeEach public void setup() { fileMonitorConfiguration.setResourceLoader(new FileSystemResourceLoader()); } - @After + @AfterEach public void tearDown() { fileMonitorConfiguration.stop(); } diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GiteaPropertyPathNotificationExtractorTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GiteaPropertyPathNotificationExtractorTests.java index 1b9b7287..9024ab84 100755 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GiteaPropertyPathNotificationExtractorTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GiteaPropertyPathNotificationExtractorTests.java @@ -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; diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GiteePropertyPathNotificationExtractorTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GiteePropertyPathNotificationExtractorTests.java index 9b5352e8..38979cc6 100644 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GiteePropertyPathNotificationExtractorTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GiteePropertyPathNotificationExtractorTests.java @@ -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; diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GithubPropertyPathNotificationExtractorTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GithubPropertyPathNotificationExtractorTests.java index cd02eacb..c8bcfc63 100644 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GithubPropertyPathNotificationExtractorTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GithubPropertyPathNotificationExtractorTests.java @@ -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; diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GitlabPropertyPathNotificationExtractorTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GitlabPropertyPathNotificationExtractorTests.java index bfdb74f8..7f082f33 100644 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GitlabPropertyPathNotificationExtractorTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GitlabPropertyPathNotificationExtractorTests.java @@ -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; diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GogsPropertyPathNotificationExtractorTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GogsPropertyPathNotificationExtractorTests.java index 5a6c04b9..06e2f6a5 100755 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GogsPropertyPathNotificationExtractorTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/GogsPropertyPathNotificationExtractorTests.java @@ -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; diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/PropertyPathEndpointTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/PropertyPathEndpointTests.java index d1bccab5..9350d0b0 100644 --- a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/PropertyPathEndpointTests.java +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/PropertyPathEndpointTests.java @@ -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); diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index 6ba34e93..9b8c5016 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -53,8 +53,8 @@ test - org.junit.vintage - junit-vintage-engine + org.junit.platform + junit-platform-launcher test diff --git a/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java b/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java index fe249f01..daa50455 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ApplicationBootstrapTests.java @@ -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"); diff --git a/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java b/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java index bd94f2f8..45d85c1a 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ApplicationTests.java @@ -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) { diff --git a/spring-cloud-config-sample/src/test/java/sample/ConfigDataCustomMediaTypeIntegrationTests.java b/spring-cloud-config-sample/src/test/java/sample/ConfigDataCustomMediaTypeIntegrationTests.java index 82fa0627..b401e31a 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ConfigDataCustomMediaTypeIntegrationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ConfigDataCustomMediaTypeIntegrationTests.java @@ -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) { diff --git a/spring-cloud-config-sample/src/test/java/sample/ConfigDataIntegrationTests.java b/spring-cloud-config-sample/src/test/java/sample/ConfigDataIntegrationTests.java index ffd7e0e4..1f001431 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ConfigDataIntegrationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ConfigDataIntegrationTests.java @@ -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) { diff --git a/spring-cloud-config-sample/src/test/java/sample/ConfigDataOrderingIntegrationTests.java b/spring-cloud-config-sample/src/test/java/sample/ConfigDataOrderingIntegrationTests.java index fb466012..0f973c8d 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ConfigDataOrderingIntegrationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ConfigDataOrderingIntegrationTests.java @@ -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) { diff --git a/spring-cloud-config-sample/src/test/java/sample/ConfigDataRetryIntegrationTests.java b/spring-cloud-config-sample/src/test/java/sample/ConfigDataRetryIntegrationTests.java index 5685251d..a34706c0 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ConfigDataRetryIntegrationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ConfigDataRetryIntegrationTests.java @@ -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) { diff --git a/spring-cloud-config-sample/src/test/java/sample/ServerNativeApplicationTests.java b/spring-cloud-config-sample/src/test/java/sample/ServerNativeApplicationTests.java index daab047a..27520398 100644 --- a/spring-cloud-config-sample/src/test/java/sample/ServerNativeApplicationTests.java +++ b/spring-cloud-config-sample/src/test/java/sample/ServerNativeApplicationTests.java @@ -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) { diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index ceb1dd62..2d650ff9 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -162,8 +162,8 @@ test - org.junit.vintage - junit-vintage-engine + org.junit.platform + junit-platform-launcher test diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AdhocTestSuite.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AdhocTestSuite.java index 1de908f7..146b0394 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AdhocTestSuite.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/AdhocTestSuite.java @@ -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 { } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java index be2fba0a..4a2d90cd 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/BootstrapConfigServerIntegrationTests.java @@ -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"); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java index b30b7ba0..fc248f34 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeClasspathTests.java @@ -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 { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeIntegrationTests.java index 04d09cb2..d544454f 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CompositeIntegrationTests.java @@ -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()); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientBackwardsCompatibilityIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientBackwardsCompatibilityIntegrationTests.java index 3b1a19a8..5fc6efcf 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientBackwardsCompatibilityIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientBackwardsCompatibilityIntegrationTests.java @@ -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()); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java index c520cf51..d70d1312 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOffIntegrationTests.java @@ -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()); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOnIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOnIntegrationTests.java index 0f614f67..f62b6e8a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOnIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigClientOnIntegrationTests.java @@ -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); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigServerApplicationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigServerApplicationTests.java index 4e0374a1..f9e01cb6 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigServerApplicationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ConfigServerApplicationTests.java @@ -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 { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubCompositeConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubCompositeConfigServerIntegrationTests.java index 18b8e7e1..e2a9f1c7 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubCompositeConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubCompositeConfigServerIntegrationTests.java @@ -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" }, diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubConfigServerIntegrationTests.java index 392b62c3..bc1ae1f0 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubConfigServerIntegrationTests.java @@ -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 { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubIntegrationTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubIntegrationTest.java index 3829cfb4..895bd526 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubIntegrationTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/CredhubIntegrationTest.java @@ -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); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/NativeConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/NativeConfigServerIntegrationTests.java index 5c45cb7f..a58b4250 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/NativeConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/NativeConfigServerIntegrationTests.java @@ -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()); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java index 7b1f8586..b5ca28ba 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/RefreshableConfigServerIntegrationTests.java @@ -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); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java index b07b29f0..be51290c 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java @@ -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"); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/TransportConfigurationIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/TransportConfigurationIntegrationTests.java index 40fcf444..d7666876 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/TransportConfigurationIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/TransportConfigurationIntegrationTests.java @@ -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", diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/VanillaConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/VanillaConfigServerIntegrationTests.java index e0614b54..f5d98ec0 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/VanillaConfigServerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/VanillaConfigServerIntegrationTests.java @@ -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()); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/composite/CompositUtilsTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/composite/CompositUtilsTests.java index 3228239d..ad56246b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/composite/CompositUtilsTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/composite/CompositUtilsTests.java @@ -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); } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java index 58367441..43ec7114 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/ConfigServerHealthIndicatorTests.java @@ -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); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomCompositeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomCompositeEnvironmentRepositoryTests.java index 47f8a2fc..55403653 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomCompositeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomCompositeEnvironmentRepositoryTests.java @@ -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()); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomEnvironmentRepositoryTests.java index a61956e6..15c57a04 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/CustomEnvironmentRepositoryTests.java @@ -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") diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java index d5ec6763..7d451d95 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/HttpClientVaultRestTemplateFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/HttpClientVaultRestTemplateFactoryTest.java index fd2308a2..21fb3990 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/HttpClientVaultRestTemplateFactoryTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/HttpClientVaultRestTemplateFactoryTest.java @@ -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, diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java index 3839f1c7..c6f90d9b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/AwsCodeCommitCredentialsProviderTests.java @@ -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); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/GitCredentialsProviderFactoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/GitCredentialsProviderFactoryTests.java index ac33d576..a7a72e5d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/GitCredentialsProviderFactoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/credentials/GitCredentialsProviderFactoryTests.java @@ -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(); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherEnvironmentEncryptorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherEnvironmentEncryptorTests.java index ee5c6338..67886ad7 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherEnvironmentEncryptorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherEnvironmentEncryptorTests.java @@ -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 params() { List 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.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.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.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.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); } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourceJsonEncryptorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourceJsonEncryptorTests.java index c2bf1035..a5c3837e 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourceJsonEncryptorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourceJsonEncryptorTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourcePropertiesEncryptorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourcePropertiesEncryptorTests.java index 1d9ea051..c42ca024 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourcePropertiesEncryptorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourcePropertiesEncryptorTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourceYamlEncryptorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourceYamlEncryptorTests.java index 7cdabf67..0733c5e1 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourceYamlEncryptorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/CipherResourceYamlEncryptorTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionControllerMultiTextEncryptorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionControllerMultiTextEncryptorTests.java index 5f4b9c94..faa45c39 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionControllerMultiTextEncryptorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionControllerMultiTextEncryptorTests.java @@ -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); } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionControllerTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionControllerTests.java index d99bb742..5fe3ed7b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionControllerTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionControllerTests.java @@ -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 keys) { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionIntegrationTests.java index 4912acda..002ae1e5 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EncryptionIntegrationTests.java @@ -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"); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EnvironmentPrefixHelperTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EnvironmentPrefixHelperTests.java index 3e585c83..4d7c0613 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EnvironmentPrefixHelperTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/EnvironmentPrefixHelperTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/KeyStoreTextEncryptorLocatorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/KeyStoreTextEncryptorLocatorTests.java index 0ac1682e..ad7eb1f5 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/KeyStoreTextEncryptorLocatorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/KeyStoreTextEncryptorLocatorTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptorTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptorTests.java index 6ea60066..8d77e854 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptorTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/encryption/vault/VaultEnvironmentEncryptorTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java index 0831f641..d9a198cb 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CompositeEnvironmentRepositoryTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/ConfigurableHttpConnectionFactoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/ConfigurableHttpConnectionFactoryIntegrationTests.java index a7ae985f..7c35efa9 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/ConfigurableHttpConnectionFactoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/ConfigurableHttpConnectionFactoryIntegrationTests.java @@ -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 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 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); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepositoryTests.java index f75af118..8cdac8ba 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/CredhubEnvironmentRepositoryTests.java @@ -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); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepositoryTests.java index 82fa2217..4a0b8877 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/EnvironmentEncryptorEnvironmentRepositoryTests.java @@ -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); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/GoogleSecretManagerEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/GoogleSecretManagerEnvironmentRepositoryTests.java index b0528e73..8263d5ce 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/GoogleSecretManagerEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/GoogleSecretManagerEnvironmentRepositoryTests.java @@ -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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java index 43948763..cfe138e9 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpClientConfigurableHttpConnectionFactoryTest.java @@ -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(); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpRequestConfigTokenProviderTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpRequestConfigTokenProviderTests.java index 50bd8f95..6cd10ad1 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpRequestConfigTokenProviderTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/HttpRequestConfigTokenProviderTests.java @@ -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(); + }); + } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryConcurrencyTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryConcurrencyTests.java index 44177b6a..dccdb8de 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryConcurrencyTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryConcurrencyTests.java @@ -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(); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java index 82557e07..e12508d0 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java @@ -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) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositorySslTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositorySslTests.java index b6d6528c..6cb90623 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositorySslTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositorySslTests.java @@ -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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java index 62fd99eb..df99a744 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java @@ -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); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryConfigurationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryConfigurationTests.java index 6bb6e5b1..d8ca64d4 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryConfigurationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryConfigurationTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryTests.java index 979fa284..7ff0534a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JdbcEnvironmentRepositoryTests.java @@ -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" }) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests.java index 9fc72f90..0d7958c4 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests.java @@ -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"); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentLabelPlaceholderRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentLabelPlaceholderRepositoryTests.java index 07b9c003..3a12ff8b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentLabelPlaceholderRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentLabelPlaceholderRepositoryTests.java @@ -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}-")); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java index 1a95e13c..cd23b10d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentProfilePlaceholderRepositoryTests.java @@ -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); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryFactoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryFactoryTests.java index d6e9805b..60f44a58 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryFactoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryFactoryTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java index 38e6e927..efcfd176 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryIntegrationTests.java @@ -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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java index b0dde5d9..0e25ef8a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/MultipleJGitEnvironmentRepositoryTests.java @@ -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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactoryTest.java index 1ecd621c..d5992863 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactoryTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryFactoryTest.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java index 1b74dd9f..1534347a 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/NativeEnvironmentRepositoryTests.java @@ -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); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepositoryTests.java index 5724280d..e0da56a1 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepositoryTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryIntegrationTests.java index c13a968a..2e6492bd 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryIntegrationTests.java @@ -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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryTests.java index 9f4d6648..63e01657 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/SVNKitEnvironmentRepositoryTests.java @@ -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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryIntegrationTests.java index 7d4b1650..db500296 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryIntegrationTests.java @@ -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 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 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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryTests.java index 4e253037..6e2f08d9 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultEnvironmentRepositoryTests.java @@ -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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultKvAccessStrategyFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultKvAccessStrategyFactoryTest.java index 4c5e37fe..b55c788b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultKvAccessStrategyFactoryTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultKvAccessStrategyFactoryTest.java @@ -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); } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultKvAccessStrategyTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultKvAccessStrategyTest.java index bb4ca09e..8e9123c6 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultKvAccessStrategyTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/VaultKvAccessStrategyTest.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryFactoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryFactoryTests.java index 87be8ba9..562b780b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryFactoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryFactoryTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java index f9546b7c..74760449 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/vault/SpringVaultEnvironmentRepositoryTests.java @@ -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; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java index 5a95cce5..68dc0003 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/GenericResourceRepositoryTests.java @@ -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 diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerIntegrationTests.java index 605fe78a..f82290c6 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerIntegrationTests.java @@ -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(); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerTests.java index ccaab8ed..7ee6793e 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/resource/ResourceControllerTests.java @@ -19,10 +19,10 @@ package org.springframework.cloud.config.server.resource; import java.util.Map; import io.micrometer.observation.ObservationRegistry; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +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; @@ -59,14 +59,14 @@ public class ResourceControllerTests { @SuppressWarnings("unchecked") private Map resourceEncryptorMap = Mockito.mock(Map.class); - @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(); @@ -80,7 +80,7 @@ public class ResourceControllerTests { } @Test - @Ignore // FIXME: configdata + @Disabled // FIXME: configdata public void templateReplacement() throws Exception { this.environmentRepository.setSearchLocations("classpath:/test"); String resource = this.controller.retrieve("foo", "bar", "dev", "template.json", true); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/FileBasedSshSessionFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/FileBasedSshSessionFactoryTest.java index 0fc31172..96b380d5 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/FileBasedSshSessionFactoryTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/FileBasedSshSessionFactoryTest.java @@ -21,9 +21,9 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.jgit.transport.SshConfigStore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.cloud.config.server.environment.JGitEnvironmentProperties; @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * Unit tests for file based SSH config processor. */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class FileBasedSshSessionFactoryTest { private FileBasedSshSessionFactory factory; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/PropertyBasedSshSessionFactoryTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/PropertyBasedSshSessionFactoryTest.java index 66c45111..7a9d71f9 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/PropertyBasedSshSessionFactoryTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/PropertyBasedSshSessionFactoryTest.java @@ -45,9 +45,11 @@ import org.eclipse.jgit.transport.sshd.ProxyData; import org.eclipse.jgit.transport.sshd.ProxyDataFactory; import org.eclipse.jgit.transport.sshd.ServerKeyDatabase; import org.eclipse.jgit.transport.sshd.SshdSessionFactory; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.springframework.cloud.config.server.environment.JGitEnvironmentProperties; import org.springframework.cloud.config.server.proxy.ProxyHostProperties; @@ -65,7 +67,8 @@ import static org.mockito.Mockito.when; * @author William Tran * @author Ollie Hughes */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) public class PropertyBasedSshSessionFactoryTest { private static final String HOST_KEY = "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAAB" diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/SshPropertyValidatorTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/SshPropertyValidatorTest.java index 16058458..79d8e35b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/SshPropertyValidatorTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/SshPropertyValidatorTest.java @@ -22,8 +22,8 @@ import jakarta.validation.ConstraintViolation; import jakarta.validation.Validation; import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties; @@ -74,7 +74,7 @@ public class SshPropertyValidatorTest { private static Validator validator; - @BeforeClass + @BeforeAll public static void setUpValidator() { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); validator = factory.getValidator(); diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/SshUriPropertyProcessorTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/SshUriPropertyProcessorTest.java index a5ec94a9..9caf2abf 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/SshUriPropertyProcessorTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ssh/SshUriPropertyProcessorTest.java @@ -19,8 +19,8 @@ package org.springframework.cloud.config.server.ssh; import java.util.Map; import org.eclipse.jgit.transport.SshSessionFactory; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.cloud.config.server.environment.JGitEnvironmentProperties; import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties; @@ -57,7 +57,7 @@ public class SshUriPropertyProcessorTest { private static final String HOST3 = "gitlab3.test.local"; - @After + @AfterEach public void cleanup() { SshSessionFactory.setInstance(null); } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/EnvironmentPropertySourceTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/EnvironmentPropertySourceTest.java index 4de89e06..85e5ff83 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/EnvironmentPropertySourceTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/EnvironmentPropertySourceTest.java @@ -16,7 +16,7 @@ package org.springframework.cloud.config.server.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.env.StandardEnvironment; diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/GitSkipSslValidationCredentialsProviderTest.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/GitSkipSslValidationCredentialsProviderTest.java index d0ebd5fa..8679d511 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/GitSkipSslValidationCredentialsProviderTest.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/GitSkipSslValidationCredentialsProviderTest.java @@ -24,11 +24,12 @@ import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.transport.CredentialItem; import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.URIish; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; @@ -37,7 +38,7 @@ import static org.mockito.Mockito.when; /** * @author Gareth Clay */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GitSkipSslValidationCredentialsProviderTest { @Mock @@ -45,7 +46,7 @@ public class GitSkipSslValidationCredentialsProviderTest { private GitSkipSslValidationCredentialsProvider skipSslValidationCredentialsProvider; - @Before + @BeforeEach public void setup() { this.skipSslValidationCredentialsProvider = new GitSkipSslValidationCredentialsProvider(null); } @@ -152,13 +153,15 @@ public class GitSkipSslValidationCredentialsProviderTest { .isTrue(); } - @Test(expected = UnsupportedCredentialItem.class) + @Test public void testGetUnrelatedCredentialItemTypes() throws URISyntaxException { - URIish uri = new URIish("https://example.com/repo.git"); - CredentialItem usernameCredentialItem = new CredentialItem.Username(); - CredentialItem passwordCredentialItem = new CredentialItem.Password(); + Assertions.assertThrows(UnsupportedCredentialItem.class, () -> { + URIish uri = new URIish("https://example.com/repo.git"); + CredentialItem usernameCredentialItem = new CredentialItem.Username(); + CredentialItem passwordCredentialItem = new CredentialItem.Password(); - this.skipSslValidationCredentialsProvider.get(uri, usernameCredentialItem, passwordCredentialItem); + this.skipSslValidationCredentialsProvider.get(uri, usernameCredentialItem, passwordCredentialItem); + }); } @Test diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/GoogleCloudSourceSupportTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/GoogleCloudSourceSupportTests.java index f9b9ba86..f319b88f 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/GoogleCloudSourceSupportTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/support/GoogleCloudSourceSupportTests.java @@ -25,7 +25,7 @@ import org.eclipse.jgit.transport.SshTransport; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.TransportHttp; import org.eclipse.jgit.transport.URIish; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.cloud.config.server.support.GoogleCloudSourceSupport.CredentialsProvider;