当前位置: 首页>>代码示例>>Java>>正文


Java TestUtils类代码示例

本文整理汇总了Java中io.vertx.test.core.TestUtils的典型用法代码示例。如果您正苦于以下问题:Java TestUtils类的具体用法?Java TestUtils怎么用?Java TestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TestUtils类属于io.vertx.test.core包,在下文中一共展示了TestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testVersionConflictUpload

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@Test
public void testVersionConflictUpload() {
	// 1. Upload a binary field
	String uuid = tx(() -> folder("2015").getUuid());
	Buffer buffer = TestUtils.randomBuffer(1000);
	VersionNumber version = tx(() -> folder("2015").getGraphFieldContainer("en").getVersion());
	NodeResponse responseA = call(() -> client().updateNodeBinaryField(PROJECT_NAME, uuid, "en", version.toString(), FIELD_NAME, buffer,
			"filename.txt", "application/binary"));

	assertThat(responseA.getVersion()).doesNotMatch(version.toString());

	// Upload again - A conflict should be detected since we provide the original outdated version
	call(() -> client().updateNodeBinaryField(PROJECT_NAME, uuid, "en", version.toString(), FIELD_NAME, buffer, "filename.txt",
			"application/binary"), CONFLICT, "node_error_conflict_detected");

	// Now use the correct version and verify that the upload succeeds
	call(() -> client().updateNodeBinaryField(PROJECT_NAME, uuid, "en", responseA.getVersion(), FIELD_NAME, buffer, "filename.txt",
			"application/binary"));

}
 
开发者ID:gentics,项目名称:mesh,代码行数:21,代码来源:BinaryFieldEndpointTest.java

示例2: testUpdateSameValue

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@Test
@Override
public void testUpdateSameValue() {
	try (Tx tx = tx()) {
		// 1. Upload a binary field
		String uuid = tx(() -> folder("2015").getUuid());
		Buffer buffer = TestUtils.randomBuffer(1000);
		VersionNumber version = tx(() -> folder("2015").getGraphFieldContainer("en").getVersion());
		call(() -> client().updateNodeBinaryField(PROJECT_NAME, uuid, "en", version.toString(), FIELD_NAME, buffer, "filename.txt",
				"application/binary"));

		NodeResponse firstResponse = call(() -> client().findNodeByUuid(PROJECT_NAME, uuid, new VersioningParametersImpl().setVersion("draft")));
		assertEquals("filename.txt", firstResponse.getFields().getBinaryField(FIELD_NAME).getFileName());
		String oldVersion = firstResponse.getVersion();
		BinaryField binaryField = firstResponse.getFields().getBinaryField(FIELD_NAME);

		// 2. Update the node using the loaded binary field data
		NodeResponse secondResponse = updateNode(FIELD_NAME, binaryField);
		assertThat(secondResponse.getFields().getBinaryField(FIELD_NAME)).as("Updated Field").isNotNull();
		assertThat(secondResponse.getVersion()).as("New version number should not be generated.").isEqualTo(oldVersion);
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:23,代码来源:BinaryFieldEndpointTest.java

示例3: testUpdateDelete

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@Test
public void testUpdateDelete() throws IOException {
	// 1. Upload a binary field
	String uuid = tx(() -> folder("2015").getUuid());
	Buffer buffer = TestUtils.randomBuffer(1000);
	VersionNumber version = tx(() -> folder("2015").getGraphFieldContainer("en").getVersion());
	call(() -> client().updateNodeBinaryField(PROJECT_NAME, uuid, "en", version.toString(), FIELD_NAME, buffer, "filename.txt",
			"application/binary"));

	// Clear the local binary storage directory to simulate a storage inconsistency
	FileUtils.deleteDirectory(new File(Mesh.mesh().getOptions().getUploadOptions().getDirectory()));

	// 2. Delete the node
	call(() -> client().deleteNode(PROJECT_NAME, uuid));

}
 
开发者ID:gentics,项目名称:mesh,代码行数:17,代码来源:BinaryFieldEndpointTest.java

示例4: testUpdateSetEmpty

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@Test
@Override
public void testUpdateSetEmpty() {
	try (Tx tx = tx()) {
		// 1. Upload a binary field
		String uuid = tx(() -> folder("2015").getUuid());
		Buffer buffer = TestUtils.randomBuffer(1000);
		VersionNumber version = tx(() -> folder("2015").getGraphFieldContainer("en").getVersion());
		call(() -> client().updateNodeBinaryField(PROJECT_NAME, uuid, "en", version.toString(), FIELD_NAME, buffer, "filename.txt",
				"application/binary"));

		NodeResponse firstResponse = call(() -> client().findNodeByUuid(PROJECT_NAME, uuid, new VersioningParametersImpl().setVersion("draft")));
		assertEquals("filename.txt", firstResponse.getFields().getBinaryField(FIELD_NAME).getFileName());
		String oldVersion = firstResponse.getVersion();

		// 2. Set the field to empty - Node should not be updated since nothing changes
		NodeResponse secondResponse = updateNode(FIELD_NAME, new BinaryFieldImpl());
		assertThat(secondResponse.getFields().getBinaryField(FIELD_NAME)).as("Updated Field").isNotNull();
		assertThat(secondResponse.getVersion()).as("New version number").isEqualTo(oldVersion);
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:22,代码来源:BinaryFieldEndpointTest.java

示例5: testUpdateSetEmptyFilename

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@Test
public void testUpdateSetEmptyFilename() {
	String uuid = tx(() -> folder("2015").getUuid());
	// 1. Upload a binary field
	Buffer buffer = TestUtils.randomBuffer(1000);
	VersionNumber version = tx(() -> folder("2015").getGraphFieldContainer("en").getVersion());
	call(() -> client().updateNodeBinaryField(PROJECT_NAME, uuid, "en", version.toString(), FIELD_NAME, buffer, "filename.txt",
			"application/binary"));

	NodeResponse firstResponse = call(() -> client().findNodeByUuid(PROJECT_NAME, uuid, new VersioningParametersImpl().setVersion("draft")));
	assertEquals("filename.txt", firstResponse.getFields().getBinaryField(FIELD_NAME).getFileName());

	// 2. Set the field to empty
	updateNodeFailure(FIELD_NAME, new BinaryFieldImpl().setFileName(""), BAD_REQUEST, "field_binary_error_emptyfilename", FIELD_NAME);
	updateNodeFailure(FIELD_NAME, new BinaryFieldImpl().setMimeType(""), BAD_REQUEST, "field_binary_error_emptymimetype", FIELD_NAME);
}
 
开发者ID:gentics,项目名称:mesh,代码行数:17,代码来源:BinaryFieldEndpointTest.java

示例6: testTestOptions

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@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);
}
 
开发者ID:vert-x3,项目名称:vertx-unit,代码行数:24,代码来源:OptionsTest.java

示例7: testCopyOptions

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@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());
}
 
开发者ID:vert-x3,项目名称:vertx-unit,代码行数:23,代码来源:OptionsTest.java

示例8: testJsonOptions

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@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());
}
 
开发者ID:vert-x3,项目名称:vertx-unit,代码行数:25,代码来源:OptionsTest.java

示例9: testNamedHttpClientMetrics

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@Test
public void testNamedHttpClientMetrics() throws Exception {
  String name = TestUtils.randomAlphaString(10);
  HttpClient client = vertx.createHttpClient(new HttpClientOptions().setMetricsName(name));
  HttpServer server = vertx.createHttpServer(new HttpServerOptions().setHost("localhost").setPort(8080)).requestHandler(req -> {
    req.response().end();
  }).listen(ar -> {
    assertTrue(ar.succeeded());
    client.request(HttpMethod.GET, 8080, "localhost", "/file", resp -> {
      resp.bodyHandler(buff -> {
        testComplete();
      });
    }).end();
  });

  await();

  String baseName = "vertx.http.clients." + name;
  JsonObject metrics = metricsService.getMetricsSnapshot(baseName);
  assertCount(metrics.getJsonObject(baseName + ".bytes-read"), 1L);

  cleanup(client);
  cleanup(server);
}
 
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:25,代码来源:MetricsTest.java

示例10: testCopyOptions

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@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());
}
 
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:23,代码来源:MetricsOptionsTest.java

示例11: testJsonOptions

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@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, options.isEnabled());
  assertEquals(registryName, options.getRegistryName());
  assertEquals(jmxEnabled, options.isJmxEnabled());
  assertEquals(jmxDomain, options.getJmxDomain());
}
 
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:26,代码来源:MetricsOptionsTest.java

示例12: testWriteQueueFullAndDrain

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
private void testWriteQueueFullAndDrain(ReactiveWriteStream<Buffer> rws, int writeQueueMaxSize) throws Exception {
  rws.setWriteQueueMaxSize(writeQueueMaxSize);
  MySubscriber subscriber = new MySubscriber();
  rws.subscribe(subscriber);
  for (int i = 0; i < writeQueueMaxSize - 1; i++) {
    rws.write(TestUtils.randomBuffer(50));
  }
  assertFalse(rws.writeQueueFull());
  Buffer buff2 = TestUtils.randomBuffer(100);
  rws.write(buff2);
  assertTrue(rws.writeQueueFull());
  rws.drainHandler(v -> {
    assertFalse(rws.writeQueueFull());
    testComplete();
  });
  assertWaitUntil(() -> subscriber.subscription != null);
  subscriber.subscription.request(2);
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-reactive-streams,代码行数:20,代码来源:ReactiveWriteStreamTest.java

示例13: testInsertNoCollection

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@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();
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:17,代码来源:MongoClientTestBase.java

示例14: testInsertRetrieve

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@Test
public void testInsertRetrieve() throws Exception {
  String collection = randomCollection();
  mongoClient.createCollection(collection, onSuccess(res -> {
    JsonObject doc = createDoc();
    String genID = TestUtils.randomAlphaString(100);
    doc.put("_id", genID);
    mongoClient.insert(collection, doc, onSuccess(id -> {
      assertNull(id);
      mongoClient.findOne(collection, new JsonObject(), null, onSuccess(retrieved -> {
        assertEquals(doc, retrieved);
        testComplete();
      }));
    }));
  }));
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:18,代码来源:MongoClientTestBase.java

示例15: testSimpleAuth

import io.vertx.test.core.TestUtils; //导入依赖的package包/类
@Test
public void testSimpleAuth() {
  JsonObject config = new JsonObject().put("db_name", "my-datasource");
  String username = TestUtils.randomAlphaString(8);
  String password = TestUtils.randomAlphaString(20);
  config.put("username", username);
  config.put("password", password);


  List<MongoCredential> credentials = new CredentialListParser(null, config).credentials();
  assertEquals(1, credentials.size());
  MongoCredential credential = credentials.get(0);
  assertEquals(username, credential.getUserName());
  assertArrayEquals(password.toCharArray(), credential.getPassword());
  // default source should be the database name - see https://github.com/vert-x3/vertx-mongo-client/issues/46.
  assertEquals("my-datasource", credential.getSource());
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:18,代码来源:CredentialListParserTest.java


注:本文中的io.vertx.test.core.TestUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。