BAEL-17956 Fix the integrations tests in vertx (#7889)
* BAEL-17956 Fix the integrations tests in vertx * BAEL-17956 Fix the integrations tests in vertx -Added random port logic
This commit is contained in:
parent
e4ef23d7b9
commit
4a04af8ebf
|
@ -64,9 +64,8 @@
|
|||
</build>
|
||||
|
||||
<properties>
|
||||
<vertx.version>3.0.0</vertx.version>
|
||||
<testng.version>6.10</testng.version>
|
||||
<maven-shade-plugin.version>2.3</maven-shade-plugin.version>
|
||||
<vertx.version>3.8.1</vertx.version>
|
||||
<maven-shade-plugin.version>3.2.1</maven-shade-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.baeldung.rest.RestServiceVerticle;
|
||||
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.ext.unit.Async;
|
||||
import io.vertx.ext.unit.TestContext;
|
||||
import io.vertx.ext.unit.junit.VertxUnitRunner;
|
||||
|
||||
@RunWith(VertxUnitRunner.class)
|
||||
public class RestServiceVerticleIntegrationTest {
|
||||
|
||||
private Vertx vertx;
|
||||
|
||||
@Before
|
||||
public void setup(TestContext testContext) {
|
||||
vertx = Vertx.vertx();
|
||||
|
||||
vertx.deployVerticle(RestServiceVerticle.class.getName(), testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(TestContext testContext) {
|
||||
vertx.close(testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenId_whenReceivedArticle_thenSuccess(TestContext testContext) {
|
||||
final Async async = testContext.async();
|
||||
|
||||
vertx.createHttpClient()
|
||||
.getNow(8080, "localhost", "/api/baeldung/articles/article/12345", response -> {
|
||||
response.handler(responseBody -> {
|
||||
testContext.assertTrue(responseBody.toString()
|
||||
.contains("\"id\" : \"12345\""));
|
||||
async.complete();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.baeldung;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.baeldung.rest.RestServiceVerticle;
|
||||
|
||||
import io.vertx.core.DeploymentOptions;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.unit.Async;
|
||||
import io.vertx.ext.unit.TestContext;
|
||||
import io.vertx.ext.unit.junit.VertxUnitRunner;
|
||||
|
||||
@RunWith(VertxUnitRunner.class)
|
||||
public class RestServiceVerticleUnitTest {
|
||||
|
||||
private Vertx vertx;
|
||||
|
||||
private int port = 8081;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup(TestContext testContext) throws IOException {
|
||||
vertx = Vertx.vertx();
|
||||
|
||||
// Pick an available and random
|
||||
ServerSocket socket = new ServerSocket(0);
|
||||
port = socket.getLocalPort();
|
||||
socket.close();
|
||||
|
||||
DeploymentOptions options = new DeploymentOptions().setConfig(new JsonObject().put("http.port", port));
|
||||
|
||||
vertx.deployVerticle(RestServiceVerticle.class.getName(), options, testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(TestContext testContext) {
|
||||
vertx.close(testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenId_whenReceivedArticle_thenSuccess(TestContext testContext) {
|
||||
final Async async = testContext.async();
|
||||
|
||||
vertx.createHttpClient()
|
||||
.getNow(port, "localhost", "/api/baeldung/articles/article/12345", response -> {
|
||||
response.handler(responseBody -> {
|
||||
testContext.assertTrue(responseBody.toString()
|
||||
.contains("\"id\" : \"12345\""));
|
||||
async.complete();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package com.baeldung;
|
||||
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.ext.unit.Async;
|
||||
import io.vertx.ext.unit.TestContext;
|
||||
import io.vertx.ext.unit.junit.VertxUnitRunner;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(VertxUnitRunner.class)
|
||||
public class SimpleServerVerticleIntegrationTest {
|
||||
private Vertx vertx;
|
||||
|
||||
@Before
|
||||
public void setup(TestContext testContext) {
|
||||
vertx = Vertx.vertx();
|
||||
|
||||
vertx.deployVerticle(SimpleServerVerticle.class.getName(), testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(TestContext testContext) {
|
||||
vertx.close(testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReceivedResponse_thenSuccess(TestContext testContext) {
|
||||
final Async async = testContext.async();
|
||||
|
||||
vertx
|
||||
.createHttpClient()
|
||||
.getNow(8080, "localhost", "/",
|
||||
response -> response.handler(responseBody -> {
|
||||
testContext.assertTrue(responseBody
|
||||
.toString()
|
||||
.contains("Welcome"));
|
||||
async.complete();
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package com.baeldung;
|
||||
|
||||
import io.vertx.core.DeploymentOptions;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.unit.Async;
|
||||
import io.vertx.ext.unit.TestContext;
|
||||
import io.vertx.ext.unit.junit.VertxUnitRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(VertxUnitRunner.class)
|
||||
public class SimpleServerVerticleUnitTest {
|
||||
private Vertx vertx;
|
||||
|
||||
private int port = 8081;
|
||||
|
||||
@Before
|
||||
public void setup(TestContext testContext) throws IOException {
|
||||
vertx = Vertx.vertx();
|
||||
|
||||
// Pick an available and random
|
||||
ServerSocket socket = new ServerSocket(0);
|
||||
port = socket.getLocalPort();
|
||||
socket.close();
|
||||
|
||||
DeploymentOptions options = new DeploymentOptions().setConfig(new JsonObject().put("http.port", port));
|
||||
|
||||
vertx.deployVerticle(SimpleServerVerticle.class.getName(), options, testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown(TestContext testContext) {
|
||||
vertx.close(testContext.asyncAssertSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReceivedResponse_thenSuccess(TestContext testContext) {
|
||||
final Async async = testContext.async();
|
||||
|
||||
vertx.createHttpClient()
|
||||
.getNow(port, "localhost", "/", response -> response.handler(responseBody -> {
|
||||
testContext.assertTrue(responseBody.toString()
|
||||
.contains("Welcome"));
|
||||
async.complete();
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue