Java Code Examples for io.vertx.test.core.TestUtils

The following examples show how to use io.vertx.test.core.TestUtils. These examples are extracted from open source projects. 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 Project: vertx-web   Source File: ClusteredSessionHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
private void checkSession(Session session) {
  assertEquals(123456L, (long) session.get("somelong"));
  assertEquals(1234, (int) session.get("someint"));
  assertEquals((short) 123, (short) session.get("someshort"));
  assertEquals((byte) 12, (byte) session.get("somebyte"));
  assertEquals(123.456d, (double) session.get("somedouble"), 0);
  assertEquals(123.456f, (float) session.get("somefloat"), 0);
  assertEquals('X', (char) session.get("somechar"));
  assertTrue(session.get("somebooleantrue"));
  assertFalse(session.get("somebooleanfalse"));
  assertEquals("wibble", session.get("somestring"));
  assertTrue(TestUtils.byteArraysEqual(bytes, session.get("somebytes")));
  assertEquals(buffer, session.get("somebuffer"));
  JsonObject json = session.get("someclusterserializable");
  assertNotNull(json);
  assertEquals("bar", json.getString("foo"));
}
 
Example 2
Source Project: vertx-unit   Source File: OptionsTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testTestOptions() {
  TestOptions options = new TestOptions();
  assertEquals(TestOptions.DEFAULT_TIMEOUT, options.getTimeout());
  assertEquals(TestOptions.DEFAULT_USE_EVENT_LOOP, options.isUseEventLoop());
  assertEquals(Collections.<ReportOptions>emptyList(), options.getReporters());
  long timeout = TestUtils.randomLong();
  Boolean useEventLoop = randomBoolean();
  assertSame(options, options.setTimeout(timeout));
  assertSame(options, options.setUseEventLoop(useEventLoop));
  assertEquals(timeout, options.getTimeout());
  assertEquals(useEventLoop, options.isUseEventLoop());
  List<ReportOptions> reporters = new ArrayList<>();
  ReportOptions reporter1 = new ReportOptions();
  reporters.add(reporter1);
  assertSame(options, options.setReporters(reporters));
  assertEquals(reporters, options.getReporters());
  ReportOptions reporter2 = new ReportOptions();
  assertSame(options, options.addReporter(reporter2));
  assertEquals(reporters, options.getReporters());
  assertEquals(2, reporters.size());
  assertEquals(Arrays.asList(reporter1, reporter2), reporters);
}
 
Example 3
Source Project: vertx-unit   Source File: OptionsTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testCopyOptions() {
  TestOptions options = new TestOptions();
  long timeout = TestUtils.randomLong();
  Boolean useEventLoop = randomBoolean();
  String to = TestUtils.randomAlphaString(10);
  String at = TestUtils.randomAlphaString(10);
  String format = TestUtils.randomAlphaString(10);
  ReportOptions reporter = new ReportOptions().setTo(to).setFormat(format);
  options.setUseEventLoop(useEventLoop).setTimeout(timeout).addReporter(reporter);
  TestOptions copy = new TestOptions(options);
  options.setTimeout(TestUtils.randomLong());
  options.setUseEventLoop(randomBoolean());
  reporter.setTo(TestUtils.randomAlphaString(10));
  reporter.setFormat(TestUtils.randomAlphaString(10));
  options.getReporters().clear();
  assertEquals(timeout, copy.getTimeout());
  assertEquals(useEventLoop, copy.isUseEventLoop());
  assertEquals(1, copy.getReporters().size());
  assertEquals(to, copy.getReporters().get(0).getTo());
  assertEquals(format, copy.getReporters().get(0).getFormat());
}
 
Example 4
Source Project: vertx-unit   Source File: OptionsTest.java    License: Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testJsonOptions() {
  JsonObject json = new JsonObject();
  long timeout = TestUtils.randomLong();
  Boolean useEventLoop = randomBoolean();
  String to = TestUtils.randomAlphaString(10);
  String at = TestUtils.randomAlphaString(10);
  String format = TestUtils.randomAlphaString(10);
  json.put("timeout", timeout);
  if (useEventLoop != null) {
    json.put("useEventLoop", useEventLoop);
  }
  json.put("reporters", new JsonArray().
      add(new JsonObject().
          put("to", to).
          put("at", at).
          put("format", format)));
  TestOptions options = new TestOptions(json);
  assertEquals(timeout, options.getTimeout());
  assertEquals(useEventLoop, options.isUseEventLoop());
  assertEquals(1, options.getReporters().size());
  assertEquals(to, options.getReporters().get(0).getTo());
  assertEquals(format, options.getReporters().get(0).getFormat());
}
 
Example 5
Source Project: vertx-web   Source File: SockJSWriteTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWebSocket() throws Exception {
  waitFor(2);
  String expected = TestUtils.randomAlphaString(64);
  socketHandler = () -> socket -> {
    socket.write(Buffer.buffer(expected), onSuccess(v -> {
      complete();
    }));
  };
  startServers();
  client.webSocket("/test/400/8ne8e94a/websocket", onSuccess(ws -> {
    ws.handler(buffer -> {
      if (buffer.toString().equals("a[\"" + expected + "\"]")) {
        complete();
      }
    });
  }));
  await();
}
 
Example 6
@Test
public void testCopyOptions() {
  DropwizardMetricsOptions options = new DropwizardMetricsOptions();

  Random rand = new Random();
  boolean metricsEnabled = rand.nextBoolean();
  boolean jmxEnabled = rand.nextBoolean();
  String jmxDomain = TestUtils.randomAlphaString(100);
  String name = TestUtils.randomAlphaString(100);
  String configPath = TestUtils.randomAlphaString(100);
  options.setEnabled(metricsEnabled);
  options.setJmxEnabled(jmxEnabled);
  options.setJmxDomain(jmxDomain);
  options.setRegistryName(name);
  options.setConfigPath(configPath);
  options = new DropwizardMetricsOptions(options);
  assertEquals(metricsEnabled || jmxEnabled, options.isEnabled());
  assertEquals(jmxEnabled, options.isJmxEnabled());
  assertEquals(jmxDomain, options.getJmxDomain());
  assertEquals(name, options.getRegistryName());
  assertEquals(configPath, options.getConfigPath());
}
 
Example 7
@Test
public void testJsonOptions() {
  DropwizardMetricsOptions options = new DropwizardMetricsOptions(new JsonObject());
  assertFalse(options.isEnabled());
  assertFalse(options.isJmxEnabled());
  assertNull(options.getJmxDomain());
  assertNull(options.getRegistryName());
  Random rand = new Random();
  boolean metricsEnabled = rand.nextBoolean();
  boolean jmxEnabled = rand.nextBoolean();
  String jmxDomain = TestUtils.randomAlphaString(100);
  String registryName = TestUtils.randomAlphaString(100);
  String configPath = TestUtils.randomAlphaString(100);
  options = new DropwizardMetricsOptions(new JsonObject().
    put("enabled", metricsEnabled).
    put("registryName", registryName).
    put("jmxEnabled", jmxEnabled).
    put("jmxDomain", jmxDomain).
    put("configPath", configPath)
  );
  assertEquals(metricsEnabled || jmxEnabled, options.isEnabled());
  assertEquals(registryName, options.getRegistryName());
  assertEquals(jmxEnabled, options.isJmxEnabled());
  assertEquals(jmxDomain, options.getJmxDomain());
}
 
Example 8
Source Project: vertx-web   Source File: BodyHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFileDeleteOnLargeUpload() throws Exception {
    String uploadsDirectory = tempUploads.newFolder().getPath();
    router.clear();
    router.route().handler(BodyHandler.create()
      .setDeleteUploadedFilesOnEnd(true)
      .setBodyLimit(10000)
      .setUploadsDirectory(uploadsDirectory));
    router.route().handler(ctx -> {
      fail();
      ctx.fail(500);
    });

    sendFileUploadRequest(TestUtils.randomBuffer(20000), 413, "Request Entity Too Large");

    assertWaitUntil(() -> vertx.fileSystem().readDirBlocking(uploadsDirectory).isEmpty());
}
 
Example 9
Source Project: vertx-mongo-client   Source File: MongoClientTestBase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInsertNoCollection() {
  String collection = randomCollection();
  String random = TestUtils.randomAlphaString(20);
  mongoClient.insert(collection, new JsonObject().put("foo", random), onSuccess(id -> {
    assertNotNull(id);
    mongoClient.find(collection, new JsonObject(), onSuccess(docs -> {
      assertNotNull(docs);
      assertEquals(1, docs.size());
      assertEquals(random, docs.get(0).getString("foo"));
      testComplete();
    }));
  }));

  await();
}
 
Example 10
Source Project: vertx-web   Source File: WebClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFileUploadsSameNameFormMultipart() throws Exception {
  Buffer content1 = Buffer.buffer(TestUtils.randomAlphaString(16));
  Buffer content2 = Buffer.buffer(TestUtils.randomAlphaString(16));
  List<Upload> toUpload = Arrays.asList(
    new Upload("test", "test1.txt", content1),
    new Upload("test", "test2.txt", content2)
  );
  testFileUploadFormMultipart(MultipartForm.create(), toUpload, true, (req, uploads) -> {
    assertEquals(2, uploads.size());
    assertEquals("test", uploads.get(0).name);
    assertEquals("test1.txt", uploads.get(0).filename);
    assertEquals(content1, uploads.get(0).data);
    assertEquals("test", uploads.get(1).name);
    assertEquals("test2.txt", uploads.get(1).filename);
    assertEquals(content2, uploads.get(1).data);
  });
}
 
Example 11
Source Project: vertx-web   Source File: EventbusBridgeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPermittedOptionsJson() {
  String address = TestUtils.randomAlphaString(10);
  String addressRegex = TestUtils.randomAlphaString(10);
  String requiredAuthority = TestUtils.randomAlphaString(10);
  JsonObject match = new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10));
  JsonObject json = new JsonObject().
    put("address", address).
    put("addressRegex", addressRegex).
    put("requiredAuthority", requiredAuthority).
    put("match", match);
  PermittedOptions options = new PermittedOptions(json);
  assertEquals(address, options.getAddress());
  assertEquals(addressRegex, options.getAddressRegex());
  assertEquals(requiredAuthority, options.getRequiredAuthority());
  assertEquals(match, options.getMatch());
}
 
Example 12
Source Project: vertx-web   Source File: SockJSWriteTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testXHRStreaming() throws Exception {
  waitFor(2);
  String expected = TestUtils.randomAlphaString(64);
  socketHandler = () -> socket -> {
    socket.write(Buffer.buffer(expected), onSuccess(v -> {
      complete();
    }));
  };
  startServers();
  client.post("/test/400/8ne8e94a/xhr_streaming", Buffer.buffer(), onSuccess(resp -> {
    assertEquals(200, resp.statusCode());
    resp.handler(buffer -> {
      if (buffer.toString().equals("a[\"" + expected + "\"]\n")) {
        complete();
      }
    });
  }));
  await();
}
 
Example 13
@Test
public void testSimpleAuthWithSource() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String password = TestUtils.randomAlphaString(20);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("password", password);
  config.put("authSource", authSource);

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertArrayEquals(password.toCharArray(), credential.getPassword());
  assertEquals(authSource, credential.getSource());
}
 
Example 14
@Test
public void testAuth_GSSAPI() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("authSource", authSource);
  config.put("authMechanism", "GSSAPI");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertNotEquals(authSource, credential.getSource()); // It should ignore the source we pass in

  assertEquals(AuthenticationMechanism.GSSAPI, credential.getAuthenticationMechanism());
}
 
Example 15
Source Project: vertx-web   Source File: WebClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFileUploadsFormMultipart() throws Exception {
  Buffer content1 = Buffer.buffer(TestUtils.randomAlphaString(16));
  Buffer content2 = Buffer.buffer(TestUtils.randomAlphaString(16));
  List<Upload> toUpload = Arrays.asList(
    new Upload("test1", "test1.txt", content1),
    new Upload("test2", "test2.txt", content2)
  );
  testFileUploadFormMultipart(MultipartForm.create(), toUpload, true, (req, uploads) -> {
    assertEquals(2, uploads.size());
    assertEquals("test1", uploads.get(0).name);
    assertEquals("test1.txt", uploads.get(0).filename);
    assertEquals(content1, uploads.get(0).data);
    assertEquals("test2", uploads.get(1).name);
    assertEquals("test2.txt", uploads.get(1).filename);
    assertEquals(content2, uploads.get(1).data);
  });
}
 
Example 16
@Test
public void testAuth_PLAIN() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String password = TestUtils.randomAlphaString(20);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("password", password);
  config.put("authSource", authSource);
  config.put("authMechanism", "PLAIN");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertArrayEquals(password.toCharArray(), credential.getPassword());
  assertEquals(authSource, credential.getSource());

  assertEquals(AuthenticationMechanism.PLAIN, credential.getAuthenticationMechanism());
}
 
Example 17
Source Project: vertx-web   Source File: SockJSWriteTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventSource() throws Exception {
  waitFor(2);
  String expected = TestUtils.randomAlphaString(64);
  socketHandler = () -> socket -> {
    socket.write(Buffer.buffer(expected), onSuccess(v -> {
      complete();
    }));
  };
  startServers();
  client.get("/test/400/8ne8e94a/eventsource", onSuccess(resp -> {
    resp.handler(buffer -> {
      if (buffer.toString().equals("data: a[\"" + expected + "\"]\r\n\r\n")) {
        complete();
      }
    });
  }));
  await();
}
 
Example 18
@Test
public void testAuth_SCRAM_SHA_1() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String password = TestUtils.randomAlphaString(20);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("password", password);
  config.put("authSource", authSource);
  config.put("authMechanism", "SCRAM-SHA-1");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertArrayEquals(password.toCharArray(), credential.getPassword());
  assertEquals(authSource, credential.getSource());

  assertEquals(AuthenticationMechanism.SCRAM_SHA_1, credential.getAuthenticationMechanism());
}
 
Example 19
@Test
public void testAuth_SCRAM_SHA_256() {
  JsonObject config = new JsonObject();
  String username = TestUtils.randomAlphaString(8);
  String password = TestUtils.randomAlphaString(20);
  String authSource = TestUtils.randomAlphaString(10);
  config.put("username", username);
  config.put("password", password);
  config.put("authSource", authSource);
  config.put("authMechanism", "SCRAM-SHA-256");

  List<MongoCredential> credentials = new CredentialListParser(config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertArrayEquals(password.toCharArray(), credential.getPassword());
  assertEquals(authSource, credential.getSource());

  assertEquals(AuthenticationMechanism.SCRAM_SHA_256, credential.getAuthenticationMechanism());
}
 
Example 20
Source Project: vertx-web   Source File: SockJSWriteTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testXHRPollingShutdown() throws Exception {
  // Take 5 seconds which is the hearbeat timeout
  waitFor(3);
  String expected = TestUtils.randomAlphaString(64);
  socketHandler = () -> socket -> {
    socket.write(Buffer.buffer(expected), onFailure(err -> {
      complete();
    }));
    socket.endHandler(v -> {
      socket.write(Buffer.buffer(expected), onFailure(err -> {
        complete();
      }));
    });
  };
  startServers();
  client.post("/test/400/8ne8e94a/xhr", Buffer.buffer(), onSuccess(resp -> {
    assertEquals(200, resp.statusCode());
    complete();
  }));
  await();
}
 
Example 21
@Test
public void testSocketSettings() {
  int connectTimeoutMS = Math.abs(TestUtils.randomInt());
  int socketTimeoutMS = Math.abs(TestUtils.randomInt());
  int receiveBufferSize = Math.abs(TestUtils.randomInt());
  int sendBufferSize = Math.abs(TestUtils.randomInt());

  JsonObject config = new JsonObject();
  config.put("connectTimeoutMS", connectTimeoutMS);
  config.put("socketTimeoutMS", socketTimeoutMS);
  config.put("receiveBufferSize", receiveBufferSize);
  config.put("sendBufferSize", sendBufferSize);

  SocketSettings settings = new SocketSettingsParser(null, config).settings();
  assertEquals(connectTimeoutMS, settings.getConnectTimeout(TimeUnit.MILLISECONDS));
  assertEquals(socketTimeoutMS, settings.getReadTimeout(TimeUnit.MILLISECONDS));
  assertEquals(receiveBufferSize, settings.getReceiveBufferSize());
  assertEquals(sendBufferSize, settings.getSendBufferSize());
}
 
Example 22
Source Project: vertx-mongo-client   Source File: UpdateOptionsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOptionsJson() {
  JsonObject json = new JsonObject();

  WriteOption writeOption = JOURNALED;
  json.put("writeOption", writeOption.name());

  boolean multi = TestUtils.randomBoolean();
  json.put("multi", multi);

  boolean upsert = TestUtils.randomBoolean();
  json.put("upsert", upsert);

  JsonArray arrayFilters = new JsonArray().add(new JsonObject().put(TestUtils.randomAlphaString(5), TestUtils.randomAlphaString(5)));
  json.put("arrayFilters", arrayFilters);

  UpdateOptions options = new UpdateOptions(json);
  assertEquals(writeOption, options.getWriteOption());
  assertEquals(multi, options.isMulti());
  assertEquals(upsert, options.isUpsert());
  assertEquals(arrayFilters, options.getArrayFilters());
}
 
Example 23
Source Project: vertx-mongo-client   Source File: FindOptionsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOptionsJson() {
  JsonObject json = new JsonObject();

  JsonObject fields = randomJsonObject();
  json.put("fields", fields);

  JsonObject sort = randomJsonObject();
  json.put("sort", sort);

  int limit = TestUtils.randomInt();
  json.put("limit", limit);

  int skip = TestUtils.randomInt();
  json.put("skip", skip);

  FindOptions options = new FindOptions(json);
  assertEquals(fields, options.getFields());
  assertEquals(sort, options.getSort());
  assertEquals(limit, options.getLimit());
  assertEquals(skip, options.getSkip());
}
 
Example 24
Source Project: vertx-mongo-client   Source File: FindOptionsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCopyOptions() {
  FindOptions options = new FindOptions();
  JsonObject fields = randomJsonObject();
  JsonObject sort = randomJsonObject();
  int limit = TestUtils.randomInt();
  int skip = TestUtils.randomInt();
  options.setFields(fields);
  options.setSort(sort);
  options.setLimit(limit);
  options.setSkip(skip);

  FindOptions copy = new FindOptions(options);
  assertEquals(options.getFields(), copy.getFields());
  assertEquals(options.getSort(), copy.getSort());
  assertEquals(options.getLimit(), copy.getLimit());
  assertEquals(options.getSkip(), copy.getSkip());
}
 
Example 25
@Test
public void testMongoClientBulkWriteStatuses() {
  long randomMatched = TestUtils.randomLong();
  long randomModified = TestUtils.randomLong();
  long randomInserted = TestUtils.randomLong();
  long randomDeleted = TestUtils.randomLong();
  List<JsonObject> upserts = randomUpsertIds();

  MongoClientBulkWriteResult mongoClientBulkWriteResult = new MongoClientBulkWriteResult(randomInserted,
      randomMatched, randomDeleted, randomModified, upserts);

  assertEquals(randomMatched, mongoClientBulkWriteResult.getMatchedCount());
  assertEquals(randomModified, mongoClientBulkWriteResult.getModifiedCount());
  assertEquals(randomInserted, mongoClientBulkWriteResult.getInsertedCount());
  assertEquals(randomDeleted, mongoClientBulkWriteResult.getDeletedCount());
  assertEquals(upserts, mongoClientBulkWriteResult.getUpserts());
}
 
Example 26
Source Project: vertx-web   Source File: SockJSWriteTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testXHRPollingClose() throws Exception {
  // Take 5 seconds which is the hearbeat timeout
  waitFor(3);
  String expected = TestUtils.randomAlphaString(64);
  socketHandler = () -> socket -> {
    socket.write(Buffer.buffer(expected), onFailure(err -> {
      complete();
    }));
    socket.endHandler(v -> {
      socket.write(Buffer.buffer(expected), onFailure(err -> {
        complete();
      }));
    });
    socket.close();
  };
  startServers();
  client.post("/test/400/8ne8e94a/xhr", Buffer.buffer(), onSuccess(resp -> {
    assertEquals(200, resp.statusCode());
    complete();
  }));
  await();
}
 
Example 27
Source Project: vertx-web   Source File: WebClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseBodyCodecErrorBeforeResponseIsReceived() throws Exception {
  server.requestHandler(req -> {
    HttpServerResponse resp = req.response();
    resp.setChunked(true);
    resp.end(TestUtils.randomBuffer(2048));
  });
  startServer();
  RuntimeException cause = new RuntimeException();
  WriteStreamBase stream = new WriteStreamBase() {
  };
  HttpRequest<Buffer> get = webClient.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
  HttpRequest<Void> request = get.as(BodyCodec.pipe(stream));
  assertNotNull(stream.exceptionHandler);
  stream.exceptionHandler.handle(cause);
  request.send(onFailure(err -> {
    assertSame(cause, err);
    testComplete();
  }));
  await();
}
 
Example 28
Source Project: vertx-consul-client   Source File: RandomObjects.java    License: Apache License 2.0 5 votes vote down vote up
public static Coordinate randomCoordinate() {
  return new Coordinate()
    .setNode(randomAlphaString(10))
    .setAdj(randomFloat())
    .setHeight(randomFloat())
    .setErr(randomFloat())
    .setVec(randomObjectList(6, TestUtils::randomFloat));
}
 
Example 29
Source Project: vertx-web   Source File: EventbusBridgeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPermittedOptions() {
  PermittedOptions options = new PermittedOptions();
  assertEquals(PermittedOptions.DEFAULT_ADDRESS, options.getAddress());
  assertEquals(PermittedOptions.DEFAULT_ADDRESS_REGEX, options.getAddressRegex());
  assertEquals(PermittedOptions.DEFAULT_REQUIRED_AUTHORITY, options.getRequiredAuthority());
  assertEquals(PermittedOptions.DEFAULT_MATCH, options.getMatch());
  String address = TestUtils.randomAlphaString(10);
  String addressRegex = TestUtils.randomAlphaString(10);
  String requiredAuthority = TestUtils.randomAlphaString(10);
  JsonObject match = new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10));
  assertSame(options, options.setAddress(address));
  assertSame(options, options.setAddressRegex(addressRegex));
  assertSame(options, options.setRequiredAuthority(requiredAuthority));
  assertSame(options, options.setMatch(match));
  assertEquals(address, options.getAddress());
  assertEquals(addressRegex, options.getAddressRegex());
  assertEquals(requiredAuthority, options.getRequiredAuthority());
  assertEquals(match, options.getMatch());
  PermittedOptions copy = new PermittedOptions(options);
  assertEquals(address, copy.getAddress());
  assertEquals(addressRegex, copy.getAddressRegex());
  assertEquals(requiredAuthority, copy.getRequiredAuthority());
  assertEquals(match, copy.getMatch());
  assertSame(copy, copy.setAddress(TestUtils.randomAlphaString(10)));
  assertSame(copy, copy.setAddressRegex(TestUtils.randomAlphaString(10)));
  assertSame(copy, copy.setRequiredAuthority(TestUtils.randomAlphaString(10)));
  assertSame(copy, copy.setMatch(new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10))));
  assertSame(options, options.setAddress(address));
  assertSame(options, options.setAddressRegex(addressRegex));
  assertSame(options, options.setRequiredAuthority(requiredAuthority));
  assertSame(options, options.setMatch(match));
}
 
Example 30
Source Project: vertx-unit   Source File: EventBusTest.java    License: Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testEndToEnd() {
  String testSuiteName = TestUtils.randomAlphaString(10);
  String testCaseName1 = TestUtils.randomAlphaString(10);
  String testCaseName2 = TestUtils.randomAlphaString(10);
  TestReporter testReporter = new TestReporter();
  EventBusCollector collector = EventBusCollector.create(vertx, testReporter);
  MessageConsumer<JsonObject> consumer = vertx.eventBus().consumer("the-address", collector.asMessageHandler());
  consumer.completionHandler(ar -> {
    assertTrue(ar.succeeded());
    TestSuite suite = TestSuite.create(testSuiteName).
        test(testCaseName1, context -> {
        }).test(testCaseName2, context -> context.fail("the_failure"));
    suite.run(vertx, new TestOptions().addReporter(new ReportOptions().setTo("bus:the-address")));
  });
  testReporter.await();
  assertEquals(0, testReporter.exceptions.size());
  assertEquals(2, testReporter.results.size());
  TestResult result1 = testReporter.results.get(0);
  assertEquals(testCaseName1, result1.name());
  assertTrue(result1.succeeded());
  TestResult result2 = testReporter.results.get(1);
  assertEquals(testCaseName2, result2.name());
  assertTrue(result2.failed());
  assertEquals("the_failure", result2.failure().message());
  consumer.unregister();
}