diff --git a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java index b80e5803f1e..ba18f3f2bd4 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java @@ -21,6 +21,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; import java.nio.file.Path; @@ -29,12 +31,11 @@ import java.util.HashSet; import org.junit.jupiter.api.Test; -import org.springframework.tests.EnabledForTestGroups; import org.springframework.util.FileCopyUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.springframework.tests.TestGroup.CI; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * Unit tests for various {@link Resource} implementations. @@ -220,12 +221,28 @@ class ResourceTests { } @Test - @EnabledForTestGroups(CI) - void testNonFileResourceExists() throws Exception { - Resource resource = new UrlResource("https://spring.io/"); + void nonFileResourceExists() throws Exception { + URL url = new URL("https://spring.io/"); + + // Abort if spring.io is not reachable. + assumeTrue(urlIsReachable(url)); + + Resource resource = new UrlResource(url); assertThat(resource.exists()).isTrue(); } + private boolean urlIsReachable(URL url) { + try { + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("HEAD"); + connection.setReadTimeout(5_000); + return connection.getResponseCode() == HttpURLConnection.HTTP_OK; + } + catch (Exception ex) { + return false; + } + } + @Test void abstractResourceExceptions() throws Exception { final String name = "test-resource"; diff --git a/spring-core/src/test/java/org/springframework/tests/AssumeTests.java b/spring-core/src/test/java/org/springframework/tests/AssumeTests.java index 1accee1ef82..f077ffe6170 100644 --- a/spring-core/src/test/java/org/springframework/tests/AssumeTests.java +++ b/spring-core/src/test/java/org/springframework/tests/AssumeTests.java @@ -29,7 +29,6 @@ import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.springframework.tests.Assume.TEST_GROUPS_SYSTEM_PROPERTY; -import static org.springframework.tests.TestGroup.CI; import static org.springframework.tests.TestGroup.LONG_RUNNING; import static org.springframework.tests.TestGroup.PERFORMANCE; @@ -70,7 +69,7 @@ class AssumeTests { @Test @SuppressWarnings("deprecation") void assumeGroupWithNoMatchingActiveTestGroup() { - setTestGroups(PERFORMANCE, CI); + setTestGroups(PERFORMANCE); assertThatExceptionOfType(TestAbortedException.class).isThrownBy(() -> Assume.group(LONG_RUNNING)); } @@ -99,7 +98,7 @@ class AssumeTests { // // java.lang.IllegalStateException: Failed to parse 'testGroups' system property: // Unable to find test group 'bogus' when parsing testGroups value: 'all-bogus'. - // Available groups include: [LONG_RUNNING,PERFORMANCE,CI] + // Available groups include: [LONG_RUNNING,PERFORMANCE] setTestGroups(testGroups); assertThatIllegalStateException() @@ -109,7 +108,7 @@ class AssumeTests { .satisfies(ex -> assertThat(ex.getCause().getMessage()).isEqualTo( "Unable to find test group 'bogus' when parsing testGroups value: '" + testGroups + - "'. Available groups include: [LONG_RUNNING,PERFORMANCE,CI]")); + "'. Available groups include: [LONG_RUNNING,PERFORMANCE]")); } private void setTestGroups(TestGroup... testGroups) { diff --git a/spring-core/src/test/java/org/springframework/tests/TestGroup.java b/spring-core/src/test/java/org/springframework/tests/TestGroup.java index c597c859e8d..f04c47bc182 100644 --- a/spring-core/src/test/java/org/springframework/tests/TestGroup.java +++ b/spring-core/src/test/java/org/springframework/tests/TestGroup.java @@ -49,12 +49,7 @@ public enum TestGroup { * {@code StopWatch}, etc. should be considered a candidate as their successful * execution is likely to be based on events occurring within a given time window. */ - PERFORMANCE, - - /** - * Tests that should only be run on the continuous integration server. - */ - CI; + PERFORMANCE; /** @@ -82,6 +77,7 @@ public enum TestGroup { "' system property: " + ex.getMessage(), ex); } } + /** * Parse the specified comma separated string of groups. * @param value the comma separated string of groups diff --git a/spring-core/src/test/java/org/springframework/tests/TestGroupTests.java b/spring-core/src/test/java/org/springframework/tests/TestGroupTests.java index 152a63041a4..5377c4b5f74 100644 --- a/spring-core/src/test/java/org/springframework/tests/TestGroupTests.java +++ b/spring-core/src/test/java/org/springframework/tests/TestGroupTests.java @@ -64,7 +64,7 @@ class TestGroupTests { .isThrownBy(() -> TestGroup.parse("performance, missing")) .withMessageContaining("Unable to find test group 'missing' when parsing " + "testGroups value: 'performance, missing'. Available groups include: " + - "[LONG_RUNNING,PERFORMANCE,CI]"); + "[LONG_RUNNING,PERFORMANCE]"); } @Test @@ -85,7 +85,7 @@ class TestGroupTests { .isThrownBy(() -> TestGroup.parse("all-missing")) .withMessageContaining("Unable to find test group 'missing' when parsing " + "testGroups value: 'all-missing'. Available groups include: " + - "[LONG_RUNNING,PERFORMANCE,CI]"); + "[LONG_RUNNING,PERFORMANCE]"); } }