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

The following examples show how to use io.vertx.ext.unit.TestContext#assertNotNull() . 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: VaultClientWithCertTest.java    From vertx-config with Apache License 2.0 6 votes vote down vote up
public static Handler<AsyncResult<Auth>> getLoginTestHandler(SlimVaultClient client, TestContext tc) {
  Async async = tc.async();
  String rw_path = "secret/app/hello-" + UUID.randomUUID().toString();
  String value = "world " + UUID.randomUUID().toString();
  return ar -> {
    tc.assertTrue(ar.succeeded());
    String token = ar.result().getToken();
    tc.assertNotNull(token);

    client.setToken(token);

    // Try to write and read some secrets - using the "user" policy
    client.write(rw_path, new JsonObject().put("value", value), x -> {
      if (x.failed()) {
        x.cause().printStackTrace();
      }
      tc.assertTrue(x.succeeded());
      client.read(rw_path, y -> {
        tc.assertTrue(y.succeeded());
        tc.assertEquals(value, y.result().getData().getString("value"));
        async.complete();
      });
    });
  };
}
 
Example 2
Source File: MqttServerConnectionTest.java    From vertx-mqtt with Apache License 2.0 6 votes vote down vote up
@Test
public void refusedClientIdZeroBytes(TestContext context) {

  this.expectedReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED;

  try {
    MemoryPersistence persistence = new MemoryPersistence();
    MqttConnectOptions options = new MqttConnectOptions();
    options.setCleanSession(false);
    options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
    MqttClient client = new MqttClient(String.format("tcp://%s:%d", MQTT_SERVER_HOST, MQTT_SERVER_PORT), "", persistence);
    client.connect(options);
    context.fail();
  } catch (MqttException e) {
    context.assertTrue(e.getReasonCode() == MqttException.REASON_CODE_INVALID_CLIENT_ID);
    context.assertNotNull(rejection);
  }
}
 
Example 3
Source File: BatchInputParserMultiRecordTest.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void runAdd(TestContext testContext) throws Exception {
    BatchInputArrowParserVerticle verticleRef = (BatchInputArrowParserVerticle) verticle;
    Schema irisInputSchema = TrainUtils.getIrisInputSchema();
    ArrowRecordWriter arrowRecordWriter = new ArrowRecordWriter(irisInputSchema);
    CSVRecordReader reader = new CSVRecordReader();
    reader.initialize(new FileSplit(new ClassPathResource("iris.txt").getFile()));
    List<List<Writable>> writables = reader.next(150);

    File tmpFile = new File(temporary.getRoot(), "tmp.arrow");
    FileSplit fileSplit = new FileSplit(tmpFile);
    arrowRecordWriter.initialize(fileSplit, new NumberOfRecordsPartitioner());
    arrowRecordWriter.writeBatch(writables);

    given().port(port)
            .multiPart("input1", tmpFile)
            .when().post("/")
            .then().statusCode(200);

    testContext.assertNotNull(verticleRef.getBatch(), "Inputs were null. This means parsing failed.");
    testContext.assertTrue(verticleRef.getBatch().length >= 1);
    testContext.assertNotNull(verticleRef.getBatch());
    testContext.assertEquals(150, verticleRef.getBatch().length);
}
 
Example 4
Source File: MailWithDKIMSignTest.java    From vertx-mail-client with Apache License 2.0 5 votes vote down vote up
private void testDKIMSign(DKIMSignOptions dkimOps, List<String> signHeaders, TestContext ctx) throws Exception {
  Message jamesMessage = new Message(new ByteArrayInputStream(wiser.getMessages().get(0).getData()));
  List<String> dkimHeaders = jamesMessage.getFields(DKIMSigner.DKIM_SIGNATURE_HEADER);
  ctx.assertEquals(1, dkimHeaders.size());
  String dkimSignTagsList = dkimHeaders.get(0);
  ctx.assertNotNull(dkimSignTagsList);
  Map<String, String> signTags = new HashMap<>();
  Arrays.stream(dkimSignTagsList.substring(dkimSignTagsList.indexOf(":") + 1).split(";")).map(String::trim).forEach(part -> {
    int idx = part.indexOf("=");
    signTags.put(part.substring(0, idx), part.substring(idx + 1));
  });
  ctx.assertEquals("1", signTags.get("v"));
  ctx.assertEquals(DKIMSignAlgorithm.RSA_SHA256.dkimAlgoName(), signTags.get("a"));
  ctx.assertEquals(dkimOps.getHeaderCanonAlgo().algoName() + "/" + dkimOps.getBodyCanonAlgo().algoName(), signTags.get("c"));
  ctx.assertEquals("example.com", signTags.get("d"));
  ctx.assertEquals("lgao", signTags.get("s"));
  ctx.assertEquals(String.join(":", signHeaders), signTags.get("h"));

  MockPublicKeyRecordRetriever recordRetriever = new MockPublicKeyRecordRetriever();
  recordRetriever.addRecord("lgao", "example.com", "v=DKIM1; k=rsa; p=" + pubKeyStr);
  DKIMVerifier dkimVerifier = new DKIMVerifier(recordRetriever);
  List<SignatureRecord> records = dkimVerifier.verify(jamesMessage, jamesMessage.getBodyInputStream());
  SignatureRecord record = records.get(0);
  ctx.assertNotNull(record);
  ctx.assertEquals("lgao", record.getSelector());
  ctx.assertEquals(IDENTITY, record.getIdentity());
  ctx.assertEquals("example.com", record.getDToken());
  ctx.assertEquals("sha-256", record.getHashAlgo());
}
 
Example 5
Source File: ProtonClientTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
private Object getMessageBody(TestContext context, Message msg) {
  Section body = msg.getBody();

  context.assertNotNull(body);
  context.assertTrue(body instanceof AmqpValue);

  return ((AmqpValue) body).getValue();
}
 
Example 6
Source File: PetStoreTest.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 2000)
public void testSwaggerManager(TestContext context) {
    Async async = context.async(2);
    SwaggerManager instance = SwaggerManager.getInstance();
    context.assertNotNull(instance.getSwagger());
    context.assertEquals("Swagger Petstore", instance.getSwagger().getInfo().getTitle());
    async.complete();
}
 
Example 7
Source File: ProtonSubscriberIntTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
private Object getMessageBody(TestContext context, Message msg) {
  Section body = msg.getBody();

  context.assertNotNull(body);
  context.assertTrue(body instanceof AmqpValue);

  return ((AmqpValue) body).getValue();
}
 
Example 8
Source File: RxPetStoreTest.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 2000)
public void testSwaggerManager(TestContext context) {
    Async async = context.async(2);
    SwaggerManager instance = SwaggerManager.getInstance();
    context.assertNotNull(instance.getSwagger());
    context.assertEquals("Swagger Petstore", instance.getSwagger().getInfo().getTitle());
    async.complete();
}
 
Example 9
Source File: MutinySessionTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testMetamodel(TestContext context) {
	EntityType<GuineaPig> pig = getSessionFactory().getMetamodel().entity(GuineaPig.class);
	context.assertNotNull(pig);
	context.assertEquals( 2, pig.getAttributes().size() );
	context.assertEquals( "GuineaPig", pig.getName() );
}
 
Example 10
Source File: QueryVariationsTest.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
private int assertSequenceResult(TestContext ctx, RowSet<Row> rowSet, Consumer<Integer> validation) {
  ctx.assertEquals(1, rowSet.size());
  RowIterator<Row> rows = rowSet.iterator();
      ctx.assertTrue(rows.hasNext());
      Row row = rows.next();
      ctx.assertNotNull(row);
      int seqVal = row.getInteger(0);
      validation.accept(seqVal);
      return seqVal;
}
 
Example 11
Source File: DeployVerticleTest.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 12
Source File: PostgresClientIT.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
public void closeClientTwiceTenant(TestContext context) {
  PostgresClient c = PostgresClient.getInstance(vertx, TENANT);
  context.assertNotNull(PostgresClientHelper.getClient(c), "getClient()");
  c.closeClient(context.asyncAssertSuccess());
  context.assertNull(PostgresClientHelper.getClient(c), "getClient()");
  c.closeClient(context.asyncAssertSuccess());
  context.assertNull(PostgresClientHelper.getClient(c), "getClient()");
}
 
Example 13
Source File: DeployVerticleTest.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeploy(TestContext context) {
  String cmd = "verticle-deploy io.vertx.ext.shell.command.base.DeployVerticleTest$SomeVerticle";
  String result = testDeployCmd(context, cmd);
  context.assertNotNull(ctx.get());
  context.assertEquals(result, "Deployed " + ctx.get().deploymentID());
  context.assertEquals(1, ctx.get().getInstanceCount());
}
 
Example 14
Source File: PostgresClientIT.java    From raml-module-builder with Apache License 2.0 5 votes vote down vote up
@Test
public void closeClientGetInstance(TestContext context) {
  PostgresClient c = PostgresClient.getInstance(vertx, TENANT);
  context.assertNotNull(PostgresClientHelper.getClient(c), "getClient()");
  c.closeClient(context.asyncAssertSuccess());
  context.assertNull(PostgresClientHelper.getClient(c), "getClient()");
  c = PostgresClient.getInstance(vertx, TENANT);
  context.assertNotNull(PostgresClientHelper.getClient(c), "getClient()");
  c.closeClient(context.asyncAssertSuccess());
  context.assertNull(PostgresClientHelper.getClient(c), "getClient()");
}
 
Example 15
Source File: DeployVerticleTest.java    From vertx-shell with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeployWithOptionsAsEmptyJsonString(TestContext context) {
  String cmd = "verticle-deploy io.vertx.ext.shell.command.base.DeployVerticleTest$SomeVerticle '{}'";
  String result = testDeployCmd(context, cmd);
  context.assertNotNull(ctx.get());
  context.assertEquals(result, "Deployed " + ctx.get().deploymentID());
  context.assertEquals(1, ctx.get().getInstanceCount());
}
 
Example 16
Source File: TestConfiguration.java    From excelastic with MIT License 4 votes vote down vote up
@Test
public void shouldLoadConfiguration(TestContext context) {
    context.assertNotNull(Configuration.getWebPort());
    context.assertNotNull(Configuration.getElasticPort());
    context.assertNotNull(Configuration.getElasticHost());
}
 
Example 17
Source File: MailClientImplTest.java    From vertx-mail-client with Apache License 2.0 4 votes vote down vote up
@Test
public final void testMailClientImpl(TestContext testContext) {
  MailClient mailClient = new MailClientImpl(vertx, new MailConfig(), "foo");
  testContext.assertNotNull(mailClient);
}
 
Example 18
Source File: PostgresClientIT.java    From raml-module-builder with Apache License 2.0 4 votes vote down vote up
@Test
public void closeAllClients(TestContext context) {
  PostgresClient c = PostgresClient.getInstance(vertx);
  context.assertNotNull(PostgresClientHelper.getClient(c), "getClient()");
  PostgresClient.closeAllClients();
}
 
Example 19
Source File: SchemaRegistrarTest.java    From vertx-graphql-service-discovery with Apache License 2.0 4 votes vote down vote up
@Test
public void should_Manage_Schema_Registration_And_Close_Properly(TestContext context) {
    Async async = context.async();
    context.assertNotNull(schemaRegistrar.getPublisherId());
    schemaRegistrar = SchemaRegistrar.create(vertx, "thePublisherId");
    context.assertEquals("thePublisherId", schemaRegistrar.getPublisherId());

    ServiceDiscovery discovery = schemaRegistrar.getOrCreateDiscovery(options);
    context.assertNotNull(discovery);
    context.assertNotNull(schemaRegistrar.registrations());
    context.assertEquals(0, schemaRegistrar.registrations().size());

    // Fans of nested handlers, take note! ;)
    // Publish 1
    schemaPublisher.publish(options, droidsSchema, rh -> {
        context.assertTrue(rh.succeeded());
        context.assertEquals(1, schemaPublisher.registeredSchemas().size());

        // Publish 2
        schemaPublisher.publish(options, starWarsSchema, rh2 -> {
            context.assertTrue(rh2.succeeded());
            context.assertEquals(2, schemaPublisher.registeredSchemas().size());

            // Re-publish 1. No change, already published
            schemaPublisher.publish(options, droidsSchema, rh3 -> {
                context.assertFalse(rh3.succeeded());
                context.assertEquals(2, schemaPublisher.registeredSchemas().size());

                // Publish 1 to different repository. Creates new registrations 1'
                schemaPublisher.publish(new ServiceDiscoveryOptions(options).setName("theOtherRegistry"),
                        droidsSchema, rh4 -> {
                    context.assertTrue(rh4.succeeded());
                    context.assertEquals(3, schemaPublisher.registeredSchemas().size());

                    // Unpublish 1. Discovery still in use
                    schemaPublisher.unpublish(rh.result(), rh5 -> {
                        context.assertTrue(rh5.succeeded());
                        context.assertEquals(2, schemaPublisher.registeredSchemas().size());
                        context.assertEquals(2, schemaPublisher.managedDiscoveries().size());

                        // Unpublish 2. Discovery now closed
                        schemaPublisher.unpublish(rh2.result(), rh6 -> {
                            assertTrue(rh6.succeeded());
                            assertEquals(1, schemaPublisher.registeredSchemas().size());
                            assertEquals(1, schemaPublisher.managedDiscoveries().size());

                            // Publish 1 again
                            schemaPublisher.publish(options, droidsSchema, rh7 -> {
                                context.assertTrue(rh7.succeeded());
                                assertEquals(2, schemaPublisher.managedDiscoveries().size());

                                schemaPublisher.registrar.close((registration, handler) ->
                                        handler.handle(Future.succeededFuture()), rh8 ->
                                        {
                                            assertEquals(0, schemaPublisher.managedDiscoveries().size());
                                            async.complete();
                                        });
                            });
                        });
                    });
                });
            });
        });
    });
}
 
Example 20
Source File: CompositeIdTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void assertThatPigsAreEqual(TestContext context, GuineaPig expected, GuineaPig actual) {
	context.assertNotNull( actual );
	context.assertEquals( expected.getId(), actual.getId() );
	context.assertEquals( expected.getName(), actual.getName() );
	context.assertEquals( expected.getWeight(), actual.getWeight() );
}