Java Code Examples for io.vertx.ext.unit.TestContext#assertFalse()

The following examples show how to use io.vertx.ext.unit.TestContext#assertFalse() . 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: MySQLConnectionTest.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
@Override
protected void validateDatabaseMetaData(TestContext ctx, DatabaseMetadata md) {
  if (rule.isUsingMariaDB()) {
    ctx.assertEquals("MariaDB", md.productName());
    ctx.assertTrue(md.majorVersion() >= 10, "Expected DB major version >= 10 but was " + md.majorVersion());
  } else if (rule.isUsingMySQL5_6()) {
    ctx.assertEquals("MySQL", md.productName());
    ctx.assertEquals(5, md.majorVersion());
    ctx.assertEquals(6, md.minorVersion());
  }
  else if (rule.isUsingMySQL8()) {
    ctx.assertEquals("MySQL", md.productName());
    ctx.assertEquals(8, md.majorVersion());
    ctx.assertEquals(0, md.minorVersion());
  }
  else {
    ctx.assertFalse(md.fullVersion().isEmpty());
  }
}
 
Example 2
Source File: TopicPartitionTest.java    From vertx-kafka-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnequality(final TestContext context) {
  final TopicPartition t1 = new TopicPartition("topic1", 0);
  final TopicPartition t2 = new TopicPartition("topic1", 1);
  final TopicPartition t3 = new TopicPartition("topic2", 0);
  final TopicPartition t4 = new TopicPartition("topic2", 1);
  final JsonObject t5 = new JsonObject();

  context.assertNotEquals(t1, t2);
  context.assertNotEquals(t1.hashCode(), t2.hashCode());

  context.assertNotEquals(t3, t4);
  context.assertNotEquals(t3.hashCode(), t4.hashCode());

  context.assertNotEquals(t3, t5);
  context.assertNotEquals(t3.hashCode(), t5.hashCode());

  context.assertFalse(t1.equals(null));
  context.assertFalse(t1.equals(t5));
}
 
Example 3
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testLastLine(TestContext testContext) {
  MultilineParser multilineParser = new MultilineParser(b -> logger.debug(b.toString()));
  testContext.assertTrue(multilineParser.isFinalLine(Buffer.buffer("250 welcome OK")));
  testContext.assertFalse(multilineParser.isFinalLine(Buffer.buffer("250-welcome OK")));

  testContext.assertTrue(multilineParser.isFinalLine(Buffer.buffer("250-welcome OK\r\n250 2.1.0 OK")));
  testContext.assertTrue(multilineParser.isFinalLine(Buffer.buffer("250 welcome OK\n250 2.1.0 OK")));

  testContext.assertFalse(multilineParser.isFinalLine(Buffer.buffer("250-welcome OK\n250-2.1.0 OK")));
  testContext.assertFalse(multilineParser.isFinalLine(Buffer.buffer("250-welcome OK\r\n250-2.1.0 OK")));

  testContext.assertTrue(multilineParser.isFinalLine(Buffer.buffer("250-welcome OK\n250-2.1.0 OK\n250 2.1.1 OK")));
  testContext.assertTrue(multilineParser.isFinalLine(Buffer.buffer("250-welcome OK\r\n250-2.1.0 OK\r\n250 2.1.1 OK")));

}
 
Example 4
Source File: CommandRegistryTest.java    From vertx-shell with Apache License 2.0 6 votes vote down vote up
@Test
public void testUndeployCommands(TestContext context) throws Exception {
  Async async = context.async();
  registry.registerCommands(
      Arrays.asList(CommandBuilder.command("a").build(vertx), CommandBuilder.command("b").build(vertx)),
      context.asyncAssertSuccess(list -> async.complete()));
  async.awaitSuccess(2000);
  Set<String> afterIds = new HashSet<>(vertx.deploymentIDs());
  System.out.println(afterIds);
  context.assertEquals(1, afterIds.size());
  String deploymentId = afterIds.iterator().next();
  Async async2 = context.async();
  registry.unregisterCommand("a", context.asyncAssertSuccess(v -> async2.complete()));
  async2.awaitSuccess(2000);
  context.assertTrue(vertx.deploymentIDs().contains(deploymentId));
  Async async3 = context.async();
  registry.unregisterCommand("b", context.asyncAssertSuccess(v -> async3.complete()));
  async3.awaitSuccess(2000);
  context.assertFalse(vertx.deploymentIDs().contains(deploymentId));
}
 
Example 5
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
/**
 * Tests one response with multiple lines.
 *
 * Capabilities declared by SMTP server are good example here.
 */
@Test
public void testOneResponseMultiLines(TestContext testContext) {
  Async async = testContext.async(2);
  final String ehloBanner = "220 hello from smtp server";
  final AtomicBoolean init = new AtomicBoolean(false);
  final String capaMessage = "250-smtp.gmail.com at your service, [209.132.188.80]\n" +
    "250-AUTH LOGIN PLAIN\n" +
    "250 PIPELINING";
  Handler<Buffer> dataHandler = b -> {
    if (!init.get()) {
      testContext.assertEquals(ehloBanner, b.toString());
      async.countDown();
    } else {
      String message = b.toString();
      testContext.assertTrue(StatusCode.isStatusOk(message));
      testContext.assertEquals(capaMessage, message);
      Capabilities capa = new Capabilities();
      capa.parseCapabilities(message);
      testContext.assertTrue(capa.isCapaPipelining());
      testContext.assertFalse(capa.isStartTLS());
      testContext.assertEquals(2, capa.getCapaAuth().size());
      testContext.assertTrue(capa.getCapaAuth().contains("LOGIN"));
      testContext.assertTrue(capa.getCapaAuth().contains("PLAIN"));
      async.countDown();
    }
  };
  MultilineParser multilineParser = new MultilineParser(dataHandler);
  multilineParser.setExpected(1);
  // simulate the ehlo banner on connection
  multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n"));
  init.set(true);
  multilineParser.handle(Buffer.buffer(capaMessage + "\r\n"));
}
 
Example 6
Source File: MultilineParserTest.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
/**
 * Tests one response with multiple lines with crlf ends for each line
 *
 * Capabilities declared by SMTP server are good example here.
 */
@Test
public void testOneResponseMultiLinesEndwithCRLF(TestContext testContext) {
  Async async = testContext.async(2);
  final String ehloBanner = "220 hello from smtp server";
  final AtomicBoolean init = new AtomicBoolean(false);
  final String capaMessage = "250-smtp.gmail.com at your service, [209.132.188.80]\r\n" +
    "250-AUTH LOGIN PLAIN\r\n" +
    "250 PIPELINING";
  final String expected = "250-smtp.gmail.com at your service, [209.132.188.80]\n" +
    "250-AUTH LOGIN PLAIN\n" +
    "250 PIPELINING";
  Handler<Buffer> dataHandler = b -> {
    if (!init.get()) {
      testContext.assertEquals(ehloBanner, b.toString());
      async.countDown();
    } else {
      String message = b.toString();
      testContext.assertTrue(StatusCode.isStatusOk(message));
      testContext.assertEquals(expected, message);
      Capabilities capa = new Capabilities();
      capa.parseCapabilities(message);
      testContext.assertTrue(capa.isCapaPipelining());
      testContext.assertFalse(capa.isStartTLS());
      testContext.assertEquals(2, capa.getCapaAuth().size());
      testContext.assertTrue(capa.getCapaAuth().contains("LOGIN"));
      testContext.assertTrue(capa.getCapaAuth().contains("PLAIN"));
      async.countDown();
    }
  };
  MultilineParser multilineParser = new MultilineParser(dataHandler);
  multilineParser.setExpected(1);
  // simulate the ehlo banner on connection
  multilineParser.handle(Buffer.buffer(ehloBanner + "\r\n"));
  init.set(true);
  multilineParser.handle(Buffer.buffer(capaMessage + "\r\n"));
}
 
Example 7
Source File: ShellCloseTest.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@Test
public void testLastAccessed(TestContext context) throws Exception {
  startShellServer(context, 100, 100);
  TestTtyConnection conn = termServer.openConnection();
  for (int i = 0; i < 100; i++) {
    conn.read("" + i);
    Thread.sleep(10);
    context.assertFalse(conn.isClosed());
  }
  context.assertTrue(conn.getCloseLatch().await(2, TimeUnit.SECONDS));
}
 
Example 8
Source File: CommandRegistryTest.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@Test
public void testCloseRegistryOnVertxClose(TestContext context) {
  Vertx vertx = Vertx.vertx();
  CommandRegistryImpl registry = (CommandRegistryImpl) CommandRegistry.getShared(vertx);
  context.assertFalse(registry.isClosed());
  vertx.close(context.asyncAssertSuccess(v -> {
    context.assertTrue(registry.isClosed());
  }));
}
 
Example 9
Source File: ProtonServerImplTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
private void doTestAsyncServerAuthenticatorTestImpl(TestContext context, boolean passAuthentication) {
  Async connectAsync = context.async();
  AtomicBoolean connectedServer = new AtomicBoolean();

  final long delay = 750;
  TestAsyncAuthenticator testAsyncAuthenticator = new TestAsyncAuthenticator(delay, passAuthentication);
  TestAsyncAuthenticatorFactory authenticatorFactory = new TestAsyncAuthenticatorFactory(testAsyncAuthenticator);

  ProtonServer.create(vertx).saslAuthenticatorFactory(authenticatorFactory).connectHandler(protonConnection -> {
    connectedServer.set(true);
  }).listen(server -> {
    final long startTime = System.currentTimeMillis();
    ProtonClient.create(vertx).connect("localhost", server.result().actualPort(), GOOD_USER, PASSWD, conResult -> {
      // Verify the process took expected time from auth delay.
      long actual = System.currentTimeMillis() - startTime;
      context.assertTrue(actual >= delay, "Connect completed before expected time delay elapsed! " + actual);

      if (passAuthentication) {
        context.assertTrue(conResult.succeeded(), "Expected connect to succeed");
        conResult.result().disconnect();
      } else {
        context.assertFalse(conResult.succeeded(), "Expected connect to fail");
      }

      connectAsync.complete();
    });
  });

  connectAsync.awaitSuccess();

  if(passAuthentication) {
    context.assertTrue(connectedServer.get(), "Server handler should have been called");
  } else {
    context.assertFalse(connectedServer.get(), "Server handler should not have been called");
  }

  context.assertEquals(1, authenticatorFactory.getCreateCount(), "unexpected authenticator creation count");
}
 
Example 10
Source File: TenantLoadingTest.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
private void assertGetIdBase(TestContext context, String path, String expectedBase) {
  Future<Void> future = Promise.<Void>promise().future();
  context.assertEquals(expectedBase, TenantLoading.getIdBase(path, future));
  context.assertFalse(future.isComplete());
}
 
Example 11
Source File: StompServerImplTest.java    From vertx-stomp with Apache License 2.0 4 votes vote down vote up
private void ensureClosed(TestContext context, AsyncResult<Void> ar, StompServer server) {
  context.assertTrue(ar.succeeded());
  context.assertFalse(server.isListening());
}
 
Example 12
Source File: JUnitTestSuite.java    From vertx-unit with Apache License 2.0 4 votes vote down vote up
@Test
public void testSomething(TestContext context) {
  context.assertFalse(false);
}
 
Example 13
Source File: MyTestSuite.java    From vertx-unit with Apache License 2.0 4 votes vote down vote up
public void testSomething(TestContext context) {
  context.assertFalse(false);
}
 
Example 14
Source File: ProtonSubscriberIntTest.java    From vertx-proton with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testSubCancelledOnConnectionEnd(TestContext context) throws Exception {
  server.close();

  final Async serverLinkOpenAsync = context.async();
  final Async subCancelled = context.async();

  ProtonServer protonServer = null;
  try {
    protonServer = createServer((serverConnection) -> {
      serverConnection.openHandler(result -> {
        serverConnection.open();
      });

      serverConnection.sessionOpenHandler(session -> session.open());

      serverConnection.receiverOpenHandler(serverReceiver -> {
        LOG.trace("Server receiver opened");
        // Set the local terminus details [naively]
        serverReceiver.setTarget(serverReceiver.getRemoteTarget().copy());

        serverReceiver.open();

        serverLinkOpenAsync.complete();
      });
    });

    // ===== Client Handling =====

    ProtonClient client = ProtonClient.create(vertx);
    client.connect("localhost", protonServer.actualPort(), res -> {
      context.assertTrue(res.succeeded());

      ProtonConnection connection = res.result();
      connection.open();

      ProtonSubscriber<Tracker> subscriber = ProtonStreams.createTrackerProducer(connection,"myAddress");

      // Create a Publisher that doesn't produce elements, but indicates when its subscription is cancelled.
      Publisher<Tracker> producer = Flowable.<Tracker>never()
                                            .doOnCancel(() -> {
                                              LOG.trace("Cancelled!");
                                              subCancelled.complete();
                                            });
      producer.subscribe(subscriber);
    });

    serverLinkOpenAsync.awaitSuccess();
    context.assertFalse(subCancelled.isCompleted());
    protonServer.close();
    protonServer = null;
    subCancelled.awaitSuccess();
  } finally {
    if (protonServer != null) {
      protonServer.close();
    }
  }
}
 
Example 15
Source File: ProtonPublisherIntTest.java    From vertx-proton with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testSubscriberErrorOnConnectionEnd(TestContext context) throws Exception {
  server.close();

  final Async clientLinkOpenAsync = context.async();
  final Async serverLinkOpenAsync = context.async();
  final Async subErroredAsync = context.async();

  ProtonServer protonServer = null;
  try {
    protonServer = createServer((serverConnection) -> {
      serverConnection.openHandler(result -> {
        serverConnection.open();
      });

      serverConnection.sessionOpenHandler(session -> session.open());

      serverConnection.senderOpenHandler(serverSender -> {
        LOG.trace("Server sender opened");
        serverSender.open();
        serverLinkOpenAsync.complete();
      });
    });

    // ===== Client Handling =====

    ProtonClient client = ProtonClient.create(vertx);
    client.connect("localhost", protonServer.actualPort(), res -> {
      context.assertTrue(res.succeeded());

      ProtonConnection connection = res.result();
      connection.open();

      ProtonPublisher<Delivery> publisher = ProtonStreams.createDeliveryConsumer(connection,"myAddress");

      publisher.subscribe(new Subscriber<Delivery>() {
        @Override
        public void onSubscribe(Subscription s) {
          clientLinkOpenAsync.complete();
        }

        @Override
        public void onNext(Delivery e) {
          context.fail("onNext called");
        }

        @Override
        public void onError(Throwable t) {
          LOG.trace("onError called");
          subErroredAsync.complete();
        }

        @Override
        public void onComplete() {
          LOG.trace("onComplete called");
          context.fail("onComplete called");
        }
      });
    });

    serverLinkOpenAsync.awaitSuccess();
    clientLinkOpenAsync.awaitSuccess();
    context.assertFalse(subErroredAsync.isCompleted());
    protonServer.close();
    protonServer = null;
    subErroredAsync.awaitSuccess();
  } finally {
    if (protonServer != null) {
      protonServer.close();
    }
  }
}