Skip to content

Commit

Permalink
Removed ModifiedClasspathRunner and used the ClasspathExtensions from…
Browse files Browse the repository at this point in the history
… the Spring boot test support (#1181)
  • Loading branch information
shivakrishnaah authored Jan 23, 2023
1 parent f6dd592 commit a6c5d43
Show file tree
Hide file tree
Showing 20 changed files with 505 additions and 77 deletions.
5 changes: 0 additions & 5 deletions spring-cloud-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-test-support</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@

package org.springframework.cloud.client.discovery;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext;

import static org.assertj.core.api.BDDAssertions.then;

@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-boot-actuator-autoconfigure-*" })
public class ManagementServerPortUtilsTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Map;
import java.util.Random;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.WebApplicationType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

import java.util.List;

import org.junit.runner.RunWith;

import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;

Expand All @@ -30,7 +27,6 @@
/**
* @author Spencer Gibb
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-retry-*.jar", "spring-boot-starter-aop-*.jar" })
public class LoadBalancerAutoConfigurationTests extends AbstractLoadBalancerAutoConfigurationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

package org.springframework.cloud.client.serviceregistry;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;

Expand All @@ -32,7 +30,6 @@
/**
* @author Spencer Gibb
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-boot-actuator-*.jar", "spring-boot-starter-actuator-*.jar" })
public class ServiceRegistryAutoConfigurationTests {

Expand Down
5 changes: 0 additions & 5 deletions spring-cloud-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-test-support</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

package org.springframework.cloud.autoconfigure;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.endpoint.event.RefreshEventListener;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;

Expand All @@ -33,7 +31,6 @@
/**
* @author Spencer Gibb
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-boot-actuator-*.jar", "spring-boot-starter-actuator-*.jar" })
public class RefreshAutoConfigurationClassPathTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

package org.springframework.cloud.autoconfigure;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
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.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;

Expand All @@ -34,21 +33,18 @@
/**
* @author Spencer Gibb
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-boot-actuator-autoconfigure-*.jar", "spring-boot-starter-actuator-*.jar" })
@ExtendWith(OutputCaptureExtension.class)
public class RefreshAutoConfigurationMoreClassPathTests {

@Rule
public OutputCaptureRule outputCapture = new OutputCaptureRule();

private static ConfigurableApplicationContext getApplicationContext(Class<?> configuration, String... properties) {
return new SpringApplicationBuilder(configuration).web(WebApplicationType.NONE).properties(properties).run();
}

@Test
public void unknownClassProtected() {
public void unknownClassProtected(CapturedOutput outputCapture) {
try (ConfigurableApplicationContext context = getApplicationContext(Config.class, "debug=true")) {
String output = this.outputCapture.toString();
String output = outputCapture.toString();
then(output)
.doesNotContain("Failed to introspect annotations on "
+ "[class org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,33 @@

import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext;

import static org.assertj.core.api.BDDAssertions.then;

/**
* @author Ryan Baxter
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "spring-security-rsa*.jar" })
public class RsaDisabledTests {

private ConfigurableApplicationContext context;

@Before
@BeforeEach
public void setUp() {
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
.sources(EncryptionBootstrapConfiguration.class).web(WebApplicationType.NONE)
.properties("encrypt.key:mykey", "encrypt.rsa.strong:true", "encrypt.rsa.salt:foobar").run();
}

@After
@AfterEach
public void tearDown() {
if (this.context != null) {
this.context.close();
Expand Down
5 changes: 0 additions & 5 deletions spring-cloud-loadbalancer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,5 @@
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,44 @@
package org.springframework.cloud.loadbalancer.security;

import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
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.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.test.ClassPathExclusions;
import org.springframework.cloud.test.ModifiedClassPathRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Dave Syer
*
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("spring-retry-*.jar")
public class OAuth2LoadBalancerClientAutoConfigurationTests {

private ConfigurableApplicationContext context;

@Rule
public ExpectedException expected = ExpectedException.none();

@Before
@BeforeEach
public void before() {
// FIXME: why do I need to do this? (fails in maven build without it.
// https://stackoverflow.com/questions/28911560/tomcat-8-embedded-error-org-apache-catalina-core-containerbase-a-child-con
// https://github.com/spring-projects/spring-boot/issues/21535
TomcatURLStreamHandlerFactory.disable();
}

@After
@AfterEach
public void close() {
if (this.context != null) {
this.context.close();
}
}

@Test
@Ignore
@Disabled
public void userInfoNotLoadBalanced() {
this.context = new SpringApplicationBuilder(ClientConfiguration.class).properties("spring.config.name=test",
"server.port=0", "security.oauth2.resource.userInfoUri:https://example.com").run();
Expand All @@ -73,7 +64,7 @@ public void userInfoNotLoadBalanced() {
}

@Test
@Ignore
@Disabled
public void userInfoLoadBalancedNoRetry() {
this.context = new SpringApplicationBuilder(ClientConfiguration.class).properties("spring.config.name=test",
"server.port=0", "security.oauth2.resource.userInfoUri:https://nosuchservice",
Expand Down
4 changes: 4 additions & 0 deletions spring-cloud-starter-bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
12 changes: 12 additions & 0 deletions spring-cloud-test-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;

/**
* Taken from Spring Boot test utils. https://github.com/spring-projects/spring-boot/blob/
* 1.4.x/spring-boot/src/test/java/org/springframework/boot/testutil/ClassPathExclusions.java
* @author Ryan Baxter
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@ExtendWith(ModifiedClassPathExtension.class)
public @interface ClassPathExclusions {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;

/**
* Annotation used in combination with {@link ModifiedClassPathRunner} to override entries
* Annotation used in combination with {@link ModifiedClassPathExtension} to override entries
* on the classpath.
*
* @author Andy Wilkinson
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@ExtendWith(ModifiedClassPathExtension.class)
public @interface ClassPathOverrides {

/**
Expand Down
Loading

0 comments on commit a6c5d43

Please sign in to comment.