Created
September 2, 2015 17:51
-
-
Save cobratbq/9a35d02f40c0241f2258 to your computer and use it in GitHub Desktop.
Example integration test implementation for PingVerticle (See https://github.com/vert-x/vertx-maven)
This file contains 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 org.junit.Test; | |
import org.vertx.java.core.AsyncResult; | |
import org.vertx.java.core.AsyncResultHandler; | |
import org.vertx.java.core.Handler; | |
import org.vertx.java.core.eventbus.Message; | |
import org.vertx.java.core.http.HttpClientResponse; | |
import org.vertx.java.core.http.HttpServerRequest; | |
import org.vertx.testtools.TestVerticle; | |
import org.vertx.testtools.VertxAssert; | |
public class ModuleIntegrationTest extends TestVerticle { | |
@Test | |
public void testPing() { | |
container.logger().info("in testPing()"); | |
vertx.eventBus().send("ping-address", "ping!", new Handler<Message<String>>() { | |
@Override | |
public void handle(Message<String> reply) { | |
assertEquals("pong!", reply.body()); | |
/* | |
If we get here, the test is complete | |
You must always call `testComplete()` at the end. Remember that testing is *asynchronous* so | |
we cannot assume the test is complete by the time the test method has finished executing like | |
in standard synchronous tests | |
*/ | |
testComplete(); | |
} | |
}); | |
} | |
@Override | |
public void start() { | |
// Make sure we call initialize() - this sets up the assert stuff so assert functionality works correctly | |
initialize(); | |
// Deploy the module - the System property `vertx.modulename` will contain the name of the module so you | |
// don't have to hardecode it in your tests | |
container.deployModule(System.getProperty("vertx.modulename"), new AsyncResultHandler<String>() { | |
@Override | |
public void handle(AsyncResult<String> asyncResult) { | |
// Deployment is asynchronous and this this handler will be called when it's complete (or failed) | |
assertTrue(asyncResult.succeeded()); | |
assertNotNull("deploymentID should not be null", asyncResult.result()); | |
// If deployed correctly then start the tests! | |
startTests(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment