@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); }
@org.junit.Test public void testDefaultJsonTestOptions() { TestOptions def = new TestOptions(); TestOptions json = new TestOptions(new JsonObject()); assertEquals(json.getTimeout(), def.getTimeout()); assertEquals(json.isUseEventLoop(), def.isUseEventLoop()); assertEquals(json.getReporters(), def.getReporters()); }
@org.junit.Test public void testReportWithDefaultOptions() { String s = testSystemOut(() -> { suite.run(new TestOptions().addReporter(new ReportOptions())); }); assertTrue(s.length() > 0); }
public static io.vertx.ext.unit.TestCompletion run(io.vertx.ext.unit.TestSuite j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.run(vertx, options != null ? new io.vertx.ext.unit.TestOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } }
@org.junit.Test public void testReportToLog() { String s = testLog("mylogger", () -> { Reporter<?> reporter = Reporter.reporter(vertx, new ReportOptions().setTo("log:mylogger")); assertTrue(reporter instanceof SimpleFormatter); suite.run(new TestOptions().addReporter(new ReportOptions().setTo("log:mylogger"))); }); assertTrue(s.length() > 0); }
@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()); } }
public static io.vertx.ext.unit.TestCompletion run(io.vertx.ext.unit.TestSuite j_receiver, java.util.Map<String, Object> options) { return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.run(options != null ? new io.vertx.ext.unit.TestOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null)); } public static io.vertx.ext.unit.TestCompletion run(io.vertx.ext.unit.TestSuite j_receiver, io.vertx.core.Vertx vertx, java.util.Map<String, Object> options) {
@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()); }
@org.junit.Test public void testReportToConsole() { String s = testSystemOut(() -> { Reporter<?> reporter = Reporter.reporter(vertx, new ReportOptions().setTo("console")); assertTrue(reporter instanceof SimpleFormatter); suite.run(new TestOptions().addReporter(new ReportOptions().setTo("console"))); }); assertTrue(s.length() > 0); }
@org.junit.Test public void testReportSucceededToCompletionHandler() { TestSuite suite = TestSuite.create("my_suite").test("first_test", context -> {}); suite.run(new TestOptions()).handler(ar -> { assertTrue(ar.succeeded()); testComplete(); }); await(); }
@org.junit.Test public void testReportToEventBus() { MessageConsumer<JsonObject> consumer = vertx.eventBus().<JsonObject>consumer("the_address"); consumer.handler(msg -> { if (msg.body().getString("type").equals(EventBusCollector.EVENT_TEST_SUITE_END)) { consumer.unregister(); testComplete(); } }); consumer.completionHandler(ar -> { assertTrue(ar.succeeded()); suite.run(vertx, new TestOptions().addReporter(new ReportOptions().setTo("bus:the_address"))); }); await(); }
@org.junit.Test public void testReportToFailureCompletionHandler() { RuntimeException e = new RuntimeException(); Handler<TestContext> fails = context -> { throw e; }; Handler<TestContext> pass = context -> { }; TestSuite[] suites = { TestSuite.create("my_suite").test("first_test", fails), TestSuite.create("my_suite").before(fails).test("first_test", pass), TestSuite.create("my_suite").test("first_test", pass).after(fails) }; AtomicInteger count = new AtomicInteger(); for (TestSuite suite : suites) { suite.run(new TestOptions()).handler(ar -> { assertTrue(ar.failed()); assertSame(e, ar.cause()); if (count.incrementAndGet() == 3) { testComplete(); } }); } await(); } }
throw error; }); suite.run(vertx, new TestOptions().addReporter(new ReportOptions().setTo("bus:" + address))); }); testReporter.await();
@org.junit.Test public void testReportToFile() { FileSystem fs = vertx.fileSystem(); String file = "target"; assertTrue(fs.existsBlocking(file)); assertTrue(fs.propsBlocking(file).isDirectory()); suite.run(vertx, new TestOptions().addReporter(new ReportOptions().setTo("file:" + file))); String path = file + File.separator + "my_suite.txt"; assertTrue(fs.existsBlocking(path)); int count = 1000; while (true) { FileProps props = fs.propsBlocking(path); if (props.isRegularFile() && props.size() > 0) { break; } else { if (count-- > 0) { try { Thread.sleep(1); } catch (InterruptedException ignore) { } } else { fail(); } } } }
}).run(vertx, new TestOptions().addReporter(new ReportOptions().setTo("bus:" + address))); }); await();
@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(); }
}).test(testCaseName3, context -> { throw new RuntimeException(); }).run(vertx, new TestOptions().addReporter(new ReportOptions().setTo("bus:" + address))); }); await();