/** * Assert the specified <code>condition</code> is <code>true</code>. If the condition is <code>false</code>, an assertion error is thrown * otherwise the execution continue. * @param condition the condition to assert * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.unit.TestContext assertTrue(boolean condition) { delegate.assertTrue(condition); return this; }
/** * Assert the specified <code>condition</code> is <code>true</code>. If the condition is <code>false</code>, an assertion error is thrown * otherwise the execution continue. * @param condition the condition to assert * @param message the failure message * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.unit.TestContext assertTrue(boolean condition, String message) { delegate.assertTrue(condition, message); return this; }
private static <T> void compare(TestContext ctx, T expected, T actual) { if (expected != null && expected.getClass().isArray()) { ctx.assertNotNull(actual); ctx.assertTrue(actual.getClass().isArray()); List expectedList = Arrays.asList((Object[]) expected); List actualList = Arrays.asList((Object[]) actual); ctx.assertEquals(expectedList, actualList); } else { ctx.assertEquals(expected, actual); } }
@Override public void complete(String value, boolean terminal) { context.assertTrue(terminal); context.assertEquals("oo", value); async.complete(); } });
@Override public void complete(String value, boolean terminal) { context.assertTrue(terminal); context.assertEquals("", value); async.complete(); } });
private void tryClient(TestContext tc, ConsulClient client, String expectedExceptionMessageSubstring) { client.agentInfo(tc.asyncAssertFailure(t -> { tc.assertTrue(t.getMessage().contains(expectedExceptionMessageSubstring)); ctx.closeClient(client); })); } }
@Test public void getEmptyConfig(TestContext tc) { Async async = tc.async(); createRetriever(); retriever.getConfig(json -> { tc.assertTrue(json.succeeded()); tc.assertTrue(json.result().isEmpty()); async.complete(); }); }
@Test public void connected(TestContext context) { try { MemoryPersistence persistence = new MemoryPersistence(); MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence); client.connect(); context.assertTrue(client.isConnected() && this.endpoint.isConnected()); } catch (MqttException e) { context.assertTrue(false); e.printStackTrace(); } }
/** * Verifies that the provider fails to authenticate a device when not * running on a vert.x Context. * * @param ctx The vert.x test context. */ @Test public void testAuthenticateRequiresVertxContext(final TestContext ctx) { provider.authenticate(deviceCredentials, null, ctx.asyncAssertFailure(e -> { ctx.assertTrue(e instanceof IllegalStateException); })); }
@Test public void noLocaleShouldUseDefaultLocale(TestContext should) { final Async test = should.async(); Locale.setDefault(Locale.US); final TemplateEngine engine = PebbleTemplateEngine.create(vertx); engine.render(new JsonObject(), "src/test/filesystemtemplates/test-pebble-template-i18n.peb", render2 -> { should.assertTrue(render2.succeeded()); should.assertEquals("Hi", render2.result().toString()); test.complete(); }); test.await(); }
@Test public void testNoSuchTemplate(TestContext should) { final Async test = should.async(); TemplateEngine engine = FreeMarkerTemplateEngine.create(vertx); engine.render(new JsonObject(), "not-found", render -> { should.assertTrue(render.failed()); test.complete(); }); test.await(); }
@Override public void start() throws Exception { vertx.eventBus().consumer("test", m -> { client.get(host, uri).send(ar -> { testContext.assertTrue(ar.succeeded()); async.countDown(); }); }); } };
@Test public void testDeployWithOptionsAsJsonConfig(TestContext context) { String cmd = "verticle-deploy io.vertx.ext.shell.command.base.DeployVerticleTest$SomeVerticle '{\"config\":{\"ok\":true}}'"; String result = testDeployCmd(context, cmd); context.assertNotNull(ctx.get()); context.assertEquals(result, "Deployed " + ctx.get().deploymentID()); context.assertEquals(1, ctx.get().getInstanceCount()); context.assertNotNull(ctx.get().config()); context.assertTrue(ctx.get().config().containsKey("ok")); context.assertEquals(true, ctx.get().config().getBoolean("ok")); }
private void createKV(TestContext tc, String key, String value, Handler<Long> resultHandler) { ctx.writeClient().putValue(key, value, tc.asyncAssertSuccess(b -> { tc.assertTrue(b); ctx.readClient().getValue(key, tc.asyncAssertSuccess(pair -> { resultHandler.handle(pair.getModifyIndex()); })); })); } }
@Test public void testEOF(TestContext context) throws Exception { TestTtyConnection conn = new TestTtyConnection(vertx); ShellImpl shell = createShell(conn); shell.init().readline(); conn.read("\u0004"); context.assertTrue(conn.getCloseLatch().await(2, TimeUnit.SECONDS)); }
@Test public void testProcessor(TestContext context) throws Exception { try { Async async = context.async(); DemoProcessor.async = async; context.assertEquals(DEMO_PROPERTY, demoProperty, "init does not seem to be handled"); async.await(WAITTIME); context.assertTrue(eventProcessed, "the event wasn't processed"); } catch (Exception e) { context.fail(e); } }
@Test public void closedConnection(TestContext tc) { BrokenHttpServer brokenConsul = new BrokenHttpServer(vertx); ConsulClient client = ctx.createClient(new ConsulClientOptions().setPort(brokenConsul.port())); client.agentInfo(tc.asyncAssertFailure(t -> { ctx.closeClient(client); brokenConsul.close(); tc.assertTrue(t.getMessage().contains("Connection was closed")); })); }
@Test public void timeout(TestContext tc) { SlowHttpServer slowConsul = new SlowHttpServer(vertx, 10000); ConsulClient client = ctx.createClient(new ConsulClientOptions().setPort(slowConsul.port()).setTimeout(1000)); client.agentInfo(tc.asyncAssertFailure(t -> { ctx.closeClient(client); slowConsul.close(); tc.assertTrue(t.getMessage().contains("The timeout period of 1000ms")); })); }
@Test public void testTLSTrustAll(TestContext ctx) { Async async = ctx.async(); PgClient.connect(vertx, new PgConnectOptions(options).setSslMode(SslMode.REQUIRE).setTrustAll(true), ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); async.complete(); })); }
@Test public void testSslModePrefer(TestContext ctx) { Async async = ctx.async(); PgConnectOptions options = new PgConnectOptions(TLSTest.options) .setSslMode(SslMode.PREFER) .setTrustAll(true); PgClient.connect(vertx, new PgConnectOptions(options), ctx.asyncAssertSuccess(conn -> { ctx.assertTrue(conn.isSSL()); async.complete(); })); }