Java Code Examples for io.vertx.ext.unit.TestContext#fail()
The following examples show how to use
io.vertx.ext.unit.TestContext#fail() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MqttServerConnectionTest.java From vertx-mqtt with Apache License 2.0 | 6 votes |
@Test public void connectionAlreadyAccepted(TestContext context) throws Exception { this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; MemoryPersistence persistence = new MemoryPersistence(); MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "12345", persistence); client.connect(); try { // try to accept a connection already accepted this.endpoint.accept(false); context.fail(); } catch (IllegalStateException e) { // Ok } }
Example 2
Source File: DemoRamlRestTest.java From raml-module-builder with Apache License 2.0 | 6 votes |
/** * @param context the test context. */ @BeforeClass public static void setUp(TestContext context) throws IOException { // some tests (withoutParameter, withoutYearParameter) fail under other locales like Locale.GERMANY Locale.setDefault(Locale.US); vertx = VertxUtils.getVertxWithExceptionHandler(); port = NetworkUtils.nextFreePort(); RestAssured.port = port; RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); tenant = new RequestSpecBuilder().addHeader("x-okapi-tenant", TENANT).build(); try { deployRestVerticle(context); } catch (Exception e) { context.fail(e); } }
Example 3
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertTrue(TestContext context, boolean condition) { try { Assert.assertTrue(condition); } catch (Throwable e) { context.fail(e); } }
Example 4
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertArrayEquals(TestContext context, double[] expected, double[] actual, double delta) { try { Assert.assertArrayEquals(expected, actual, delta); } catch (Throwable e) { context.fail(e); } }
Example 5
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertNotEquals(TestContext context, float expected, float actual, float delta) { try { Assert.assertNotEquals(expected, actual, delta); } catch (Throwable e) { context.fail(e); } }
Example 6
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertArrayEquals(TestContext context, String message, byte[] expected, byte[] actual) { try { Assert.assertArrayEquals(message, expected, actual); } catch (Throwable e) { context.fail(e); } }
Example 7
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertSame(TestContext context, Object expected, Object actual) { try { Assert.assertSame(expected, actual); } catch (Throwable e) { context.fail(e); } }
Example 8
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertEquals(TestContext context, double expected, double actual, double delta) { try { Assert.assertEquals(expected, actual, delta); } catch (Throwable e) { context.fail(e); } }
Example 9
Source File: VertxMatcherAssert.java From vertx-rest-client with Apache License 2.0 | 5 votes |
public static <T> void assertThat(TestContext context, String reason, T actual, Matcher<? super T> matcher) { if (!matcher.matches(actual)) { Description description = new StringDescription(); description.appendText(reason) .appendText("\nExpected: ") .appendDescriptionOf(matcher) .appendText("\n but: "); matcher.describeMismatch(actual, description); context.fail(description.toString()); } }
Example 10
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertArrayEquals(TestContext context, String message, int[] expected, int[] actual) { try { Assert.assertArrayEquals(message, expected, actual); } catch (Throwable e) { context.fail(e); } }
Example 11
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertNull(TestContext context, Object object) { try { Assert.assertNull(object); } catch (Throwable e) { context.fail(e); } }
Example 12
Source File: MailPoolServerClosesTest.java From vertx-mail-client with Apache License 2.0 | 5 votes |
/** * send two mails after each other when the server closes the connection immediately after the data send was * successfully * * @param context */ @Test public void mailConnectionCloseImmediatelyTest(TestContext context) { smtpServer.setCloseImmediately(true); Async mail1 = context.async(); Async mail2 = context.async(); MailClient mailClient = MailClient.create(vertx, configNoSSL()); MailMessage email = exampleMessage(); PassOnce pass1 = new PassOnce(s -> context.fail(s)); PassOnce pass2 = new PassOnce(s -> context.fail(s)); log.info("starting mail 1"); mailClient.sendMail(email, result -> { log.info("mail finished 1"); pass1.passOnce(); if (result.succeeded()) { log.info(result.result().toString()); mail1.complete(); log.info("starting mail 2"); mailClient.sendMail(email, result2 -> { pass2.passOnce(); log.info("mail finished 2"); if (result2.succeeded()) { log.info(result2.result().toString()); mailClient.close(); mail2.complete(); } else { log.warn("got exception 2", result2.cause()); context.fail(result2.cause()); } }); } else { log.warn("got exception 1", result.cause()); context.fail(result.cause()); } }); }
Example 13
Source File: CommandProcessTest.java From vertx-shell with Apache License 2.0 | 5 votes |
@Test public void testRunTerminatedProcess(TestContext context) { CommandBuilder builder = CommandBuilder.command("hello"); Async terminatedLatch = context.async(); builder.processHandler(CommandProcess::end); Process process = builder.build(vertx).createProcess().setSession(Session.create()).setTty(Pty.create().slave()); process.terminatedHandler(exitCode -> terminatedLatch.complete()); process.run(); terminatedLatch.awaitSuccess(10000); try { process.run(); context.fail(); } catch (IllegalStateException ignore) { } }
Example 14
Source File: TestUtil.java From vertx-sql-client with Apache License 2.0 | 5 votes |
public static void assertContains(TestContext ctx, String fullString, String... lookFor) { if (lookFor == null || lookFor.length == 0) throw new IllegalArgumentException("Must look for at least 1 token"); ctx.assertNotNull(fullString, "Expected to find '" + lookFor + "' in string, but was null"); for (String s : lookFor) if (fullString.contains(s)) return; // found if (lookFor.length == 1) ctx.fail("Expected to find '" + lookFor + "' in string, but was: " + fullString); else ctx.fail("Expected to find one of " + Arrays.toString(lookFor) + " in string, but was: " + fullString); }
Example 15
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertEquals(TestContext context, int expected, int actual) { try { Assert.assertEquals(expected, actual); } catch (Throwable e) { context.fail(e); } }
Example 16
Source File: DB2ErrorMessageTest.java From vertx-sql-client with Apache License 2.0 | 5 votes |
@Test public void testQueryBlankUsername(TestContext ctx) { try { options.setUser(""); ctx.fail("Expected a DB2Exception to be thrown"); } catch (DB2Exception ex) { assertContains(ctx, ex.getMessage(), "The user cannot be blank or null"); ctx.assertEquals(SqlCode.MISSING_CREDENTIALS, ex.getErrorCode()); ctx.assertEquals(SQLState.CONNECT_USERID_ISNULL, ex.getSqlState()); } }
Example 17
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertArrayEquals(TestContext context, String message, double[] expected, double[] actual, double delta) { try { Assert.assertArrayEquals(message, expected, actual, delta); } catch (Throwable e) { context.fail(e); } }
Example 18
Source File: VertxAssert.java From sfs with Apache License 2.0 | 5 votes |
public static void assertNotEquals(TestContext context, String message, Object expected, Object actual) { try { Assert.assertNotEquals(message, expected, actual); } catch (Throwable e) { context.fail(e); } }
Example 19
Source File: VertxMatcherAssert.java From vertx-s3-client with Apache License 2.0 | 4 votes |
public static void assertThat(TestContext context, String reason, boolean assertion) { if (!assertion) { context.fail(reason); } }
Example 20
Source File: AuthorizationTests.java From vertx-mqtt-broker with Apache License 2.0 | 4 votes |
@Test public void testPublishAuthentication(TestContext context) throws MqttException { Tester c = null; try { String serverURL = "tcp://localhost:"+config.getInteger("tcp_port"); c = new Tester(1, "Paho", serverURL); auth.setLoginRequired(true); auth.setDoSubscribeChecks(false); auth.setDoPublishChecks(true); MqttConnectOptions o = new MqttConnectOptions(); o.setUserName("user1"); o.setPassword("secret".toCharArray()); auth.setUserPass("user1", "secret"); c.connect(o); System.out.println("Check that publish to allowed topic works"); String topic = "valid/topic"; auth.setAllowedPubTopic(topic); c.subscribe(topic); int count = (int) c.getMessaggiArrivatiPerClient().values().toArray()[0]; c.publish(topic); count = (int) c.getMessaggiArrivatiPerClient().values().toArray()[0] - count; c.unsubcribe(topic); context.assertNotEquals(count, 0, "Publish to valid topic not received"); System.out.println("Check that publish to illegal topic does not send messages"); String illegalTopic = "illegal/topic"; c.subscribe(illegalTopic); count = (int) c.getMessaggiArrivatiPerClient().values().toArray()[0]; c.publish(illegalTopic); // Illegal publish fails silently count = (int) c.getMessaggiArrivatiPerClient().values().toArray()[0] - count; c.unsubcribe(illegalTopic); context.assertEquals(count, 0, "Publish to illegal topic sent message"); } catch (Throwable e) { context.fail(e.getMessage()); } finally { try {c.disconnect();} catch (Exception ex){} } }