diff --git a/eventuate-util-swagger-ui-tests/build.gradle b/eventuate-util-swagger-ui-tests/build.gradle index 18b1323..556c37b 100644 --- a/eventuate-util-swagger-ui-tests/build.gradle +++ b/eventuate-util-swagger-ui-tests/build.gradle @@ -1,5 +1,6 @@ dependencies { testCompile project(":eventuate-util-swagger-ui") + testCompile project(":eventuate-util-test") testCompile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}" testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}" testCompile "junit:junit:4.12" diff --git a/eventuate-util-swagger-ui-tests/src/test/java/io/eventuate/util/swaggerui/tests/SwaggerUiAvailabilityTest.java b/eventuate-util-swagger-ui-tests/src/test/java/io/eventuate/util/swaggerui/tests/SwaggerUiAvailabilityTest.java index fb40fd8..dc13be8 100644 --- a/eventuate-util-swagger-ui-tests/src/test/java/io/eventuate/util/swaggerui/tests/SwaggerUiAvailabilityTest.java +++ b/eventuate-util-swagger-ui-tests/src/test/java/io/eventuate/util/swaggerui/tests/SwaggerUiAvailabilityTest.java @@ -1,7 +1,7 @@ package io.eventuate.util.swaggerui.tests; -import org.junit.Assert; +import io.eventuate.util.test.async.UrlTesting; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -11,8 +11,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = SwaggerUiAvailabilityTest.Config.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -27,12 +25,7 @@ public static class Config { @Test public void testSwaggerUiAvailability() throws IOException { - assertUrlStatusIsOk(String.format("http://%s:%s/swagger-ui/index.html", "localhost", port)); + UrlTesting.assertUrlStatusIsOk("localhost", port, "/swagger-ui/index.html"); } - private void assertUrlStatusIsOk(String url) throws IOException { - HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection(); - - Assert.assertEquals(200, connection.getResponseCode()); - } } diff --git a/eventuate-util-test/build.gradle b/eventuate-util-test/build.gradle index 8b13789..ee721ab 100644 --- a/eventuate-util-test/build.gradle +++ b/eventuate-util-test/build.gradle @@ -1 +1,3 @@ - +dependencies { + compile "junit:junit:4.12" +} \ No newline at end of file diff --git a/eventuate-util-test/src/main/java/io/eventuate/util/test/async/UrlTesting.java b/eventuate-util-test/src/main/java/io/eventuate/util/test/async/UrlTesting.java new file mode 100644 index 0000000..f6763f1 --- /dev/null +++ b/eventuate-util-test/src/main/java/io/eventuate/util/test/async/UrlTesting.java @@ -0,0 +1,15 @@ +package io.eventuate.util.test.async; + +import org.junit.Assert; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +public class UrlTesting { + public static void assertUrlStatusIsOk(String host, int port, String path) throws IOException { + HttpURLConnection connection = (HttpURLConnection)new URL(String.format("http://%s:%s%s", host, port, path)).openConnection(); + + Assert.assertEquals(200, connection.getResponseCode()); + } +}