Created
September 2, 2016 13:01
-
-
Save alexlehm/7e0ee918bc1737c4bb2b1a49def70487 to your computer and use it in GitHub Desktop.
LoginServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import io.vertx.core.Vertx; | |
import io.vertx.core.http.HttpClientRequest; | |
import io.vertx.core.logging.Logger; | |
import io.vertx.core.logging.LoggerFactory; | |
import io.vertx.ext.unit.Async; | |
import io.vertx.ext.unit.TestContext; | |
import io.vertx.ext.unit.junit.VertxUnitRunner; | |
@RunWith(VertxUnitRunner.class) | |
public class LoginServiceTest { | |
private Logger logger; | |
private Vertx vertx; | |
@Before | |
public void setUp(TestContext context) throws IOException, InterruptedException { | |
logger = LoggerFactory.getLogger(LoginServiceTest.class.getName()); | |
vertx = Vertx.vertx(); | |
vertx.deployVerticle(RestEntry.class.getName(), context.asyncAssertSuccess()); | |
vertx.deployVerticle(LoginService.class.getName(), context.asyncAssertSuccess()); | |
System.out.println("Setup completed"); | |
} | |
@After | |
public void tearDown(TestContext context) { | |
vertx.close(context.asyncAssertSuccess()); | |
} | |
@Test | |
public void testServiceRouterAvailability(TestContext context) { | |
final Async async = context.async(); | |
System.out.println("Requesting Router"); | |
HttpClientRequest request = vertx.createHttpClient().get(8080, "localhost", "/", response -> { | |
response.exceptionHandler(th -> context.fail(th)); | |
response.handler(body -> { | |
System.out.println("Received response"); | |
context.assertTrue(body.toString().contains("Hello")); | |
System.out.println("Assertion completed"); | |
async.complete(); | |
System.out.println("Async completed"); | |
}); | |
}); | |
request.exceptionHandler(th -> context.fail(th)); | |
request.end(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment