Skip to content

Commit

Permalink
Merge pull request #12 from dartartem/master
Browse files Browse the repository at this point in the history
Added url testing util.
  • Loading branch information
cer authored May 18, 2021
2 parents 89fd5df + 1a0be86 commit 5f6b5aa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions eventuate-util-swagger-ui-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -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());
}
}
4 changes: 3 additions & 1 deletion eventuate-util-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

dependencies {
compile "junit:junit:4.12"
}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 5f6b5aa

Please sign in to comment.