Refine search
@Test public void shouldLoginWithUsernamePassword(TestContext should) { final Async test = should.async(); keycloak.authenticate(new JsonObject().put("username", "test-user").put("password", "tiger"), authn -> { should.assertTrue(authn.succeeded()); should.assertNotNull(authn.result()); test.complete(); }); }
@Test public void test(TestContext testContext) { HttpClient client = vertx.createHttpClient(new HttpClientOptions() .setConnectTimeout(10000)); Async async = testContext.async(); client.getNow(PORT, "127.0.0.1", "/test", testContext.asyncAssertSuccess(httpClientResponse -> { testContext.assertEquals(HttpURLConnection.HTTP_NO_CONTENT, httpClientResponse.statusCode()); async.complete(); })); }
public static void startKeyGeneratorVerticle(TestContext context) { if (keyGenVerticle == null) { logger.info("init Keygenerator"); Async async = context.async(); keyGenVerticle = createKeyGenerator(context); vertx.deployVerticle(keyGenVerticle, result -> { if (result.failed()) { context.fail(result.cause()); async.complete(); } else { async.complete(); } }); async.awaitSuccess(); } }
@Before public void before(TestContext context) { vertx = Vertx.vertx(); Async async = context.async(); vertx.deployVerticle(TestVerticle.class.getName(), context.asyncAssertSuccess(event -> async.complete())); }
@Test public void testLoadingFromEnvironmentVariables(TestContext context) { Async async = context.async(); getJsonConfiguration(vertx, store, ar -> { assertThat(ar.succeeded()).isTrue(); assertThat(ar.result().getString(KEY_1)).isEqualTo(VAL_1); assertThat(ar.result().getString(KEY_2)).isEqualTo(VAL_2); async.complete(); }); } }
@Test public void testWithNonExistingPath(TestContext tc) { Async async = tc.async(); store = factory.create(vertx, new JsonObject().put("path", "src/test/missing") .put("filesets", new JsonArray().add(new JsonObject().put("pattern", "*.json")))); store.get(ar -> { assertThat(ar.succeeded()).isTrue(); assertThat(ar.result()).isEqualTo(Buffer.buffer("{}")); async.complete(); }); }
@Test public void testWithOptionalAndSuccess(TestContext tc) { List<ConfigStoreOptions> options = new ArrayList<>(); options.add(new ConfigStoreOptions().setType("file") .setConfig(new JsonObject().put("path", "src/test/resources/file/regular.json")).setOptional(true)); retriever = ConfigRetriever.create(vertx, new ConfigRetrieverOptions().setStores(options)); AtomicReference<Throwable> reference = new AtomicReference<>(); vertx.exceptionHandler(reference::set); retriever.getConfig(ar -> { tc.assertTrue(ar.succeeded()); tc.assertNotNull(ar.result()); assertThat(ar.result().getString("key")).isEqualTo("value"); }); }
@Test public void testLoadingFromAJsonArrayFile(TestContext context) { Async async = context.async(); store = factory.create(vertx, new JsonObject().put("path", "src/test/resources/file/array.json")); getJsonConfiguration(vertx, store, ar -> { assertThat(ar.failed()).isTrue(); async.complete(); }); }
private void testEventBusConfigStore(TestContext tc, Object config, boolean send) { store = factory.create(vertx, new JsonObject().put("address", "config")); Async async = tc.async(2); getJsonConfiguration(vertx, store, ar -> { assertThat(ar.result().isEmpty()).isTrue(); async.countDown(); if (send) { vertx.eventBus().send("config", config); } else { vertx.eventBus().publish("config", config); } vertx.setTimer(10, tid -> getConfigAndCheck(tc, async)); }); }
@Test public void noLocaleShouldUseDefaultLocale(TestContext should) { final Async test = should.async(); Locale.setDefault(Locale.US); final TemplateEngine engine = PebbleTemplateEngine.create(vertx); engine.render(new JsonObject(), "src/test/filesystemtemplates/test-pebble-template-i18n.peb", render2 -> { should.assertTrue(render2.succeeded()); should.assertEquals("Hi", render2.result().toString()); test.complete(); }); test.await(); }
@Test public void testSendVoidMessage(TestContext context) { // Send a request and get a response NetClient client = vertx.createNetClient(); final Async async = context.async(); vertx.eventBus().consumer("test", (Message<JsonObject> msg) -> { client.close(); async.complete(); }); client.connect(7000, "localhost", conn -> { context.assertFalse(conn.failed()); NetSocket socket = conn.result(); FrameHelper.sendFrame("send", "test", new JsonObject().put("value", "vert.x"), socket); }); }
@Test public void testDefaultLoading(TestContext tc) { Async async = tc.async(); vertx.runOnContext(v -> { vertx.getOrCreateContext().config().put("hello", "hello"); System.setProperty("foo", "bar"); retriever = ConfigRetriever.create(vertx); retriever.getConfig(ar -> { assertThat(ar.result().getString("foo")).isEqualToIgnoringCase("bar"); assertThat(ar.result().getString("hello")).isEqualToIgnoringCase("hello"); assertThat(ar.result().getString("PATH")).isNotNull(); async.complete(); }); }); }
@Test public void testLoadingFromEnvironmentVariables(TestContext context) { Async async = context.async(); getJsonConfiguration(vertx, store, ar -> { assertThat(ar.succeeded()).isTrue(); assertThat(ar.result().getInteger(KEY_1)).isEqualTo(Integer.parseInt(VAL_1)); assertThat(ar.result().getBoolean(KEY_2)).isEqualTo(Boolean.parseBoolean(VAL_2)); async.complete(); }); } }
@Test public void testWrongSslConfiguration(TestContext context) { Async async = context.async(); client = createClient(vertx,new JsonObject() .put("sslMode", "verify-ca") .put("sslRootCert", "something-wrong.crt") ); client.getConnection(sqlConnectionAsyncResult -> { context.assertTrue(sqlConnectionAsyncResult.failed()); async.complete(); }); }
private void checkJsonConfig(TestContext tc, Async async) { store.get(ar -> { if (ar.failed()) { ar.cause().printStackTrace(); } tc.assertTrue(ar.succeeded()); JsonObject json = ar.result().toJsonObject(); tc.assertEquals(json.getString("foo"), "bar"); tc.assertEquals(json.getInteger("port"), 8080); tc.assertTrue(json.getBoolean("debug")); async.complete(); }); }
@Test public void testNoSuchTemplate(TestContext should) { final Async test = should.async(); TemplateEngine engine = MVELTemplateEngine.create(vertx); engine.render(new JsonObject(), "nosuchtemplate.templ", render -> { should.assertFalse(render.succeeded()); test.complete(); }); test.await(); }
@Before public void startVerticle(TestContext testContext) { Async async = testContext.async(); JsonObject config = new JsonObject("{\"config\":{\"address\":\"vertx.mail\",\"hostname\":\"localhost\",\"port\":1587}}"); DeploymentOptions deploymentOptions = new DeploymentOptions(config); vertx.deployVerticle("io.vertx.ext.mail.MailServiceVerticle", deploymentOptions ,r -> { if(r.succeeded()) { log.info(r.result()); async.complete(); } else { log.info("exception", r.cause()); testContext.fail(r.cause()); } }); }
@Before public void before(TestContext context) { vertx = Vertx.vertx(); final Async async = context.async(); vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value")))); TcpEventBusBridge bridge = TcpEventBusBridge.create( vertx, new BridgeOptions() .addInboundPermitted(new PermittedOptions()) .addOutboundPermitted(new PermittedOptions())); bridge.listen(7000, res -> { context.assertTrue(res.succeeded()); async.complete(); }); }
@Before public void init(TestContext context) { vertx = Vertx.vertx(); Async async = context.async(); vertx.deployVerticle(new WeldVerticle(), r -> { if (r.succeeded()) { async.complete(); } else { context.fail(r.cause()); } }); // We don't expect the tests to run in parallel VertxObservers.SYNCHRONIZER.clear(); }
@Test public void shouldFailLoginWithInvalidToken(TestContext should) { final Async test = should.async(); keycloak.authenticate(new JsonObject().put("access_token", "aaaaaaaaaaaaaaaaaa").put("token_type", "Bearer"), authn2 -> { should.assertTrue(authn2.failed()); should.assertNotNull(authn2.cause()); test.complete(); }); }