@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end(new JsonObject().put("time", System.currentTimeMillis()).toString()); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end(new JsonObject().put("time", System.currentTimeMillis()).toString()); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end(new JsonObject().put("time", System.currentTimeMillis()).toString()); }); server.listen(8080); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toFlowable().subscribe(req -> { req.response().putHeader("content-type", "application/json").end(new JsonObject().put("time", System.currentTimeMillis()).toString()); }); server.listen(8080); } }
@Test public void testToString() { jsonObject.put("foo", "bar"); assertEquals(jsonObject.encode(), jsonObject.toString()); }
private void testCustomMetricsOptionsFromJson(boolean jsonFile) throws Exception { JsonObject json = new JsonObject() .put("metricsOptions", new JsonObject() .put("enabled", true) .put("customProperty", "customPropertyValue") .put("nestedOptions", new JsonObject().put("nestedProperty", "nestedValue"))); String optionsArg; if (jsonFile) { File file = testFolder.newFile(); Files.write(file.toPath(), json.toBuffer().getBytes()); optionsArg = file.getPath(); } else { optionsArg = json.toString(); } MyLauncher launcher = new MyLauncher(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName(), "-options", optionsArg}; ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(MetricsOptionsTest.createMetricsFromMetaInfLoader("io.vertx.core.CustomMetricsFactory")); try { launcher.dispatch(args); } finally { Thread.currentThread().setContextClassLoader(oldCL); } assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); CustomMetricsOptions custom = (CustomMetricsOptions) opts.getMetricsOptions(); assertEquals("customPropertyValue", custom.getCustomProperty()); assertEquals("nestedValue", custom.getNestedOptions().getNestedProperty()); }
private void testConfigureFromJson(boolean jsonFile) throws Exception { JsonObject json = new JsonObject() .put("eventLoopPoolSize", 123) .put("maxEventLoopExecuteTime", 123767667) .put("metricsOptions", new JsonObject().put("enabled", true)) .put("eventBusOptions", new JsonObject().put("clustered", true).put("clusterPublicHost", "mars")) .put("haGroup", "somegroup") .put("maxEventLoopExecuteTimeUnit", "SECONDS"); String optionsArg; if (jsonFile) { File file = testFolder.newFile(); Files.write(file.toPath(), json.toBuffer().getBytes()); optionsArg = file.getPath(); } else { optionsArg = json.toString(); } MyLauncher launcher = new MyLauncher(); String[] args = new String[]{"run", "java:" + TestVerticle.class.getCanonicalName(), "-options", optionsArg}; launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); assertEquals(123, opts.getEventLoopPoolSize(), 0); assertEquals(123767667L, opts.getMaxEventLoopExecuteTime()); assertEquals(true, opts.getMetricsOptions().isEnabled()); assertEquals(true, opts.isClustered()); assertEquals("mars", opts.getClusterPublicHost()); assertEquals("somegroup", opts.getHAGroup()); assertEquals(TimeUnit.SECONDS, opts.getMaxEventLoopExecuteTimeUnit()); }
@Test public void testWithBrokenConfProvidedInline() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); // There is a missing `}` in the json fragment. This is normal, as the test check that the configuration is not // read in this case. cli.dispatch(new Launcher(), new String[] {"--conf={\"name\":\"vertx\""}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getJsonObject("conf").toString()).isEqualToIgnoringCase("{}"); }
/** * Consumer will treat the response body as json by default, so it's necessary to wrap response body as Json string * to avoid deserialization error. * * @param message response body * @return response body wrapped as Json string */ String wrapResponseBody(String message) { if (isValidJson(message)) { return message; } JsonObject jsonObject = new JsonObject(); jsonObject.put("message", message); return jsonObject.toString(); }
@Test public void testToString() { jsonObject.put("foo", "bar"); assertEquals(jsonObject.encode(), jsonObject.toString()); }
private void testCustomMetricsOptionsFromJson(boolean jsonFile) throws Exception { JsonObject json = new JsonObject() .put("metricsOptions", new JsonObject() .put("enabled", true) .put("customProperty", "customPropertyValue") .put("nestedOptions", new JsonObject().put("nestedProperty", "nestedValue"))); String optionsArg; if (jsonFile) { File file = testFolder.newFile(); Files.write(file.toPath(), json.toBuffer().getBytes()); optionsArg = file.getPath(); } else { optionsArg = json.toString(); } MyLauncher launcher = new MyLauncher(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName(), "-options", optionsArg}; ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(MetricsOptionsTest.createMetricsFromMetaInfLoader("io.vertx.core.CustomMetricsFactory")); try { launcher.dispatch(args); } finally { Thread.currentThread().setContextClassLoader(oldCL); } assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); CustomMetricsOptions custom = (CustomMetricsOptions) opts.getMetricsOptions(); assertEquals("customPropertyValue", custom.getCustomProperty()); assertEquals("nestedValue", custom.getNestedOptions().getNestedProperty()); }
private void testConfigureFromJson(boolean jsonFile) throws Exception { JsonObject json = new JsonObject() .put("eventLoopPoolSize", 123) .put("maxEventLoopExecuteTime", 123767667) .put("metricsOptions", new JsonObject().put("enabled", true)) .put("eventBusOptions", new JsonObject().put("clustered", true).put("clusterPublicHost", "mars")) .put("haGroup", "somegroup") .put("maxEventLoopExecuteTimeUnit", "SECONDS"); String optionsArg; if (jsonFile) { File file = testFolder.newFile(); Files.write(file.toPath(), json.toBuffer().getBytes()); optionsArg = file.getPath(); } else { optionsArg = json.toString(); } MyLauncher launcher = new MyLauncher(); String[] args = new String[]{"run", "java:" + TestVerticle.class.getCanonicalName(), "-options", optionsArg}; launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); assertEquals(123, opts.getEventLoopPoolSize(), 0); assertEquals(123767667L, opts.getMaxEventLoopExecuteTime()); assertEquals(true, opts.getMetricsOptions().isEnabled()); assertEquals(true, opts.isClustered()); assertEquals("mars", opts.getClusterPublicHost()); assertEquals("somegroup", opts.getHAGroup()); assertEquals(TimeUnit.SECONDS, opts.getMaxEventLoopExecuteTimeUnit()); }
@Test public void testWithBrokenConfProvidedInline() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); // There is a missing `}` in the json fragment. This is normal, as the test check that the configuration is not // read in this case. cli.dispatch(new Launcher(), new String[] {"--conf={\"name\":\"vertx\""}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getJsonObject("conf").toString()).isEqualToIgnoringCase("{}"); }
/** * Resolve the given JSON path to load the value. * * @param jsonPath * the JSON path * @param <T> * expected return type * @return list of objects matched by the given path */ private <T> T getByPath(String jsonPath) { return JsonPath.read(actual.toString(), jsonPath); }
public JsonObjectAssert pathIsNull(String path, String msg) { if (msg == null) { msg = ""; } Object value = JsonPath.read(actual.toString(), path); assertNull("Value on the path {" + path + "} was expected to be null but was {" + value + "}: " + msg, value); return this; } }
@Override public Observable<Transaction> getTransaction(String transactionHash) { return this.client .getAbs(this.url + transactionHash) .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> new JsonObject(json.toString())) .map(new TransactionMapping()); }
@Test public void testParseJson() { HttpRequestBody httpRequestBody = HttpRequestBodyParser.parse( new JsonObject().put("key", "value").toString().getBytes(Charsets.UTF_8), JSON); assertThat(httpRequestBody.get("key")).isEqualTo("value"); assertThat(httpRequestBody.get("boo")).isNull(); }
@Test public void testPost_json() { String json = new JsonObject().put("hello", "world").toString(); given().body(json) .post("/anything") .then() .statusCode(equalTo(200)) .body("data", equalTo(json)); } }
@Test public void testDisposableEmailJson() { given() .contentType("application/json") .body(new JsonObject().put("email", "eddy@dispostable.com").toString()) .post("/anything") .then() .statusCode(equalTo(200)) .body("headers.X-Quarantyne-Labels", equalTo("DMX")); }
@Override public Completable deregisterPipeline(String name) { String fullname = installationPrefix() + name; return client.deregisterPlugin(fullname).async() .doOnSuccess(response -> { if (log.isDebugEnabled()) { log.debug("Deregistered pipeline {" + fullname + "} response: {" + response.toString() + "}"); } }).toCompletable() .onErrorResumeNext(ignore404) .compose(withTimeoutAndLog("Removed pipeline {" + fullname + "}", true)); }