@Before
public void setup() {
VertxOptions options = new VertxOptions();
System.setProperty("vertx.cwd", JAVA_DIR + TheVerticleToBeTested.class.getPackage().getName().replace(".", "/"));
Consumer<Vertx> runner = vertx -> {
try {
vertx.deployVerticle(TheVerticleToBeTested.class.getName());
} catch (Throwable t) {
t.printStackTrace();
}
};
if (options.isClustered()) {
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
runner.accept(vertx);
} else {
res.cause().printStackTrace();
}
});
} else {
Vertx vertx = Vertx.vertx(options);
runner.accept(vertx);
}
}
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On 30 Apr 2015 at 12:39:09, bvil...@northplains.com (bvil...@northplains.com) wrote:
Hi Julien,My code is based on those very same examples, however I'm not able to get around it for a couple of reasons.The first being that the example starts a HTTP server in the setup (@Before) method, whereas I want to take advantage of the verticle I have preconfigured in my TheVerticleToBeTested class, however it seems that the start of the verticle is handed off to a different process, and therefore not in the same context as my test suite.
it is not clear, what you mean by process / context . Can you clarify ?
my suggestion is that you replace the HTTP server by the TheVerticleToBeTested deployment, I don’t see why it wouldn’t work for this case.
The same goes for using the regular TestSuite class within a test verticle, even if I create a custom task in gradle to run this test Verticle (using ant.java, for example), this creates a different process, so how will I be able to know when an Assertion Error is thrown and make gradle fail?I should also mention that those examples are probably deprecated, because stuff like context.asyncAssertSuccess doesn't seem to exist in milestone4.
indeed, it will be in the next milestone5 . It can be done without it but it requires more boiler plate code (the same MyJUnitTest.java does that in milestone4)
@RunWith(VertxUnitRunner.class)
public class TestCase {
private Vertx vertx;
@Before
public void setup() {
vertx = Vertx.vertx();
JsonObject config = new JsonObject(ServerUtil.loadConfiguration("integration"));
DeploymentOptions options = new DeploymentOptions().setConfig(config);
vertx.deployVerticleObservable("com.test.vertx.FrontController", options)
.mergeWith(vertx.deployVerticleObservable("com.test.vertx.PermissionService"))
.mergeWith(vertx.deployVerticleObservable("com.test.vertx.EventHandler"))
.subscribe(next -> {},
error -> System.err.println("Error deploying verticles"),
() -> System.out.println("Finished deploying verticles!"));
}
@Test
public void testSomething(TestContext context) {
Async async = context.async();
HttpClient client = vertx.createHttpClient();
HttpClientRequest req = client.get(8888, "localhost", "/site/rest/account/123");
req.exceptionHandler(err -> {
context.fail(err.getMessage());
});
req.handler(resp -> {
context.assertEquals(200, resp.statusCode());
async.complete();
});
req.end();
}
}
{
"port": 8888,
"host": "localhost"
}