io.vertx.test.core.TestUtils Java Examples

The following examples show how to use io.vertx.test.core.TestUtils. 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: SockJSWriteTest.java    From vertx-web with 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 #2
Source File: OptionsTest.java    From vertx-unit with 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 #3
Source File: MetricsOptionsTest.java    From vertx-dropwizard-metrics with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: OptionsTest.java    From vertx-unit with 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 #5
Source File: SockJSWriteTest.java    From vertx-web with 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
Source File: SockJSWriteTest.java    From vertx-web with 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 #7
Source File: ClusteredSessionHandlerTest.java    From vertx-web with 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 #8
Source File: MongoClientBulkWriteResultTest.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: OptionsTest.java    From vertx-unit with 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 #10
Source File: MetricsOptionsTest.java    From vertx-dropwizard-metrics with Apache License 2.0 6 votes vote down vote up
@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 #11
Source File: BodyHandlerTest.java    From vertx-web with 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 #12
Source File: FindOptionsTest.java    From vertx-mongo-client with 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 #13
Source File: FindOptionsTest.java    From vertx-mongo-client with 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 #14
Source File: UpdateOptionsTest.java    From vertx-mongo-client with 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 #15
Source File: MongoClientTestBase.java    From vertx-mongo-client with 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 #16
Source File: SocketSettingsParserTest.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
@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 #17
Source File: SockJSWriteTest.java    From vertx-web with 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 #18
Source File: CredentialListParserTest.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
@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 #19
Source File: CredentialListParserTest.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
@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 #20
Source File: WebClientTest.java    From vertx-web with 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 #21
Source File: SockJSWriteTest.java    From vertx-web with 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 #22
Source File: EventbusBridgeTest.java    From vertx-web with 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 #23
Source File: CredentialListParserTest.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
@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 #24
Source File: WebClientTest.java    From vertx-web with 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 #25
Source File: CredentialListParserTest.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
@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 #26
Source File: CredentialListParserTest.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
@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 #27
Source File: WebClientTest.java    From vertx-web with 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 File: MongoClientUpdateResultTest.java    From vertx-mongo-client with Apache License 2.0 5 votes vote down vote up
private JsonObject randomMongoClientUpdateResultJson() {
  JsonObject mongoClientUpdateResultJson = new JsonObject();

  mongoClientUpdateResultJson.put(MongoClientUpdateResult.DOC_MATCHED, TestUtils.randomLong());
  mongoClientUpdateResultJson.put(MongoClientUpdateResult.UPSERTED_ID, randomUpsertId());
  mongoClientUpdateResultJson.put(MongoClientUpdateResult.DOC_MODIFIED, TestUtils.randomLong());

  return mongoClientUpdateResultJson;
}
 
Example #29
Source File: MongoClientUpdateResultTest.java    From vertx-mongo-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyMongoClientUpdateResult() {
  MongoClientUpdateResult mongoClientUpdateResultOrigin = new MongoClientUpdateResult(TestUtils.randomLong(),
    randomUpsertId(), TestUtils.randomLong());
  MongoClientUpdateResult mongoClientUpdateResultCopy = new MongoClientUpdateResult(mongoClientUpdateResultOrigin);

  assertEquals(mongoClientUpdateResultOrigin.getDocMatched(), mongoClientUpdateResultCopy.getDocMatched());
  assertEquals(mongoClientUpdateResultOrigin.getDocUpsertedId(), mongoClientUpdateResultCopy.getDocUpsertedId());
  assertEquals(mongoClientUpdateResultOrigin.getDocModified(), mongoClientUpdateResultCopy.getDocModified());
}
 
Example #30
Source File: WebClientTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testResponseBodyAsBuffer() throws Exception {
  Buffer expected = TestUtils.randomBuffer(2000);
  server.requestHandler(req -> req.response().end(expected));
  startServer();
  HttpRequest<Buffer> get = webClient.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
  get.send(onSuccess(resp -> {
    assertEquals(200, resp.statusCode());
    assertEquals(expected, resp.body());
    testComplete();
  }));
  await();
}