/** * Throw a failure. */ public void fail() { delegate.fail(); }
/** * Throw a failure with the specified failure <code>message</code>. * @param message the failure message */ public void fail(String message) { delegate.fail(message); }
/** * Throw a failure with the specified failure <code>cause</code>. * @param cause the failure cause */ public void fail(Throwable cause) { delegate.fail(cause); }
@Override public void onError(Throwable err) { ctx.fail(err); } @Override
@Override public void complete(List<String> candidates) { context.fail(); } @Override
protected <A> Handler<AsyncResult<A>> onSuccess(TestContext context, Handler<A> fn) { return ar -> { if (ar.succeeded()) { fn.handle(ar.result()); } else { context.fail("Should have been a success"); } }; } }
@Test public void testFail(TestContext context) { context.fail("the_failure"); } }
/** * Matcher assertThat, this is usually in VertxTestBase, we pass the failure to testContext */ protected <T> void assertThat(T actual, Matcher<T> matcher) { try { super.assertThat(actual, matcher); } catch (AssertionError e) { testContext.fail(e); } }
@Override public void handle(IAsyncResult<T> result) { if (result.isSuccess()) { successHandler.handle(result.getResult()); } else { System.err.println("Operation failed"); //$NON-NLS-1$ context.fail(result.getError()); } } };
private BrokerView getBrokerAdminView(TestContext context) { try { return getBrokerService().getAdminView(); } catch (Exception e) { context.fail(e); // Above line throws, but satisfy the compiler. return null; } }
@Test public void testDisplayListAll(TestContext context) { try { String url = String.format("/products/%s/DISPLAY/list.html", NetRelayExt_FileBasedSettings.SIMPLEMAPPER_NAME); testRequest(context, HttpMethod.POST, url, null, resp -> { LOGGER.info("RESPONSE: " + resp.content); context.assertTrue(resp.content.toString().contains("success"), "Expected name not found"); }, 200, "OK", null); } catch (Exception e) { context.fail(e); } }
@Test public void testDisplayListAllAsParam(TestContext context) { try { String url = "/products/list.html?action=DISPLAY&entity=" + NetRelayExt_FileBasedSettings.SIMPLEMAPPER_NAME; testRequest(context, HttpMethod.POST, url, null, resp -> { LOGGER.info("RESPONSE: " + resp.content); context.assertTrue(resp.content.toString().contains("success"), "Expected name not found"); }, 200, "OK", null); } catch (Exception e) { context.fail(e); } }
@Test public void acceptedClientIdAutoGenerated(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; try { MemoryPersistence persistence = new MemoryPersistence(); MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "", persistence); client.connect(); } catch (MqttException e) { context.fail(e); } }
@Test public void accepted(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; try { MemoryPersistence persistence = new MemoryPersistence(); MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence); client.connect(); } catch (MqttException e) { context.fail(e); } }
@org.junit.Test public void testAssertFailure() { try { TestCase.create("my_test", context -> context.fail("the_failure")).awaitSuccess(); fail(); } catch (AssertionError err) { assertEquals("the_failure", err.getMessage()); } }
@Test public void refusedServerUnavailable(TestContext context) { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_SERVER_UNAVAILABLE; 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.fail(); } catch (MqttException e) { context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_BROKER_UNAVAILABLE); } }
private void testAwaitFailed(Consumer<Completion> consumer) { TestSuite suite = TestSuite.create("my_suite").test("my_test", context -> { context.fail(); }); Completion completion = suite.run(Vertx.vertx()); consumer.accept(completion); assertTrue(completion.isCompleted()); assertFalse(completion.isSucceeded()); assertTrue(completion.isFailed()); }
@Test public void testSuspendReadyProcess(TestContext context) { CommandBuilder builder = CommandBuilder.command("hello"); builder.processHandler(process -> context.fail()); Process process = builder.build(vertx).createProcess().setSession(Session.create()).setTty(Pty.create().slave()); try { process.suspend(); context.fail(); } catch (Exception ignore) { } }
@Test public void testRunWithExisting(TestContext ctx) { Async async = ctx.async(); vertx.runOnContext(v -> { try { PgClient.pool(new PgPoolOptions()); ctx.fail(); } catch (IllegalStateException ignore) { async.complete(); } }); }
@Test public void testBasicConsumeWithErrorHandler(TestContext ctx) throws Exception { int count = 3; Set<String> messages = createMessages(count); String q = setupQueue(ctx, messages, "application/json"); Async latch = ctx.async(count); vertx.eventBus().consumer("my.address", msg -> ctx.fail("Getting message with malformed json")); Handler<Throwable> errorHandler = throwable -> latch.countDown(); client.basicConsume(q, "my.address", true, ctx.asyncAssertSuccess(), errorHandler); }