Search in sources :

Example 31 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class DeploymentTest method testOptions.

@Test
public void testOptions() {
    DeploymentOptions options = new DeploymentOptions();
    assertNull(options.getConfig());
    JsonObject config = new JsonObject().put("foo", "bar").put("obj", new JsonObject().put("quux", 123));
    assertEquals(options, options.setConfig(config));
    assertEquals(config, options.getConfig());
    assertFalse(options.isWorker());
    assertEquals(options, options.setWorker(true));
    assertTrue(options.isWorker());
    assertFalse(options.isMultiThreaded());
    assertEquals(options, options.setMultiThreaded(true));
    assertTrue(options.isMultiThreaded());
    assertNull(options.getIsolationGroup());
    String rand = TestUtils.randomUnicodeString(1000);
    assertEquals(options, options.setIsolationGroup(rand));
    assertEquals(rand, options.getIsolationGroup());
    assertFalse(options.isHa());
    assertEquals(options, options.setHa(true));
    assertTrue(options.isHa());
    assertNull(options.getExtraClasspath());
    List<String> cp = Arrays.asList("foo", "bar");
    assertEquals(options, options.setExtraClasspath(cp));
    assertNull(options.getIsolatedClasses());
    List<String> isol = Arrays.asList("com.foo.MyClass", "org.foo.*");
    assertEquals(options, options.setIsolatedClasses(isol));
    assertSame(isol, options.getIsolatedClasses());
    String workerPoolName = TestUtils.randomAlphaString(10);
    assertEquals(options, options.setWorkerPoolName(workerPoolName));
    assertEquals(workerPoolName, options.getWorkerPoolName());
    int workerPoolSize = TestUtils.randomPositiveInt();
    assertEquals(options, options.setWorkerPoolSize(workerPoolSize));
    assertEquals(workerPoolSize, options.getWorkerPoolSize());
    long maxWorkerExecuteTime = TestUtils.randomPositiveLong();
    assertEquals(options, options.setMaxWorkerExecuteTime(maxWorkerExecuteTime));
    assertEquals(maxWorkerExecuteTime, options.getMaxWorkerExecuteTime());
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 32 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class DeploymentTest method testJsonOptions.

@Test
public void testJsonOptions() {
    JsonObject config = new JsonObject().put("foo", "bar");
    Random rand = new Random();
    boolean worker = rand.nextBoolean();
    boolean multiThreaded = rand.nextBoolean();
    String isolationGroup = TestUtils.randomAlphaString(100);
    boolean ha = rand.nextBoolean();
    List<String> cp = Arrays.asList("foo", "bar");
    List<String> isol = Arrays.asList("com.foo.MyClass", "org.foo.*");
    String poolName = TestUtils.randomAlphaString(10);
    int poolSize = TestUtils.randomPositiveInt();
    long maxWorkerExecuteTime = TestUtils.randomPositiveLong();
    JsonObject json = new JsonObject();
    json.put("config", config);
    json.put("worker", worker);
    json.put("multiThreaded", multiThreaded);
    json.put("isolationGroup", isolationGroup);
    json.put("ha", ha);
    json.put("extraClasspath", new JsonArray(cp));
    json.put("isolatedClasses", new JsonArray(isol));
    json.put("workerPoolName", poolName);
    json.put("workerPoolSize", poolSize);
    json.put("maxWorkerExecuteTime", maxWorkerExecuteTime);
    DeploymentOptions options = new DeploymentOptions(json);
    assertEquals(worker, options.isWorker());
    assertEquals(multiThreaded, options.isMultiThreaded());
    assertEquals(isolationGroup, options.getIsolationGroup());
    assertEquals("bar", options.getConfig().getString("foo"));
    assertEquals(ha, options.isHa());
    assertEquals(cp, options.getExtraClasspath());
    assertEquals(isol, options.getIsolatedClasses());
    assertEquals(poolName, options.getWorkerPoolName());
    assertEquals(poolSize, options.getWorkerPoolSize());
    assertEquals(maxWorkerExecuteTime, options.getMaxWorkerExecuteTime());
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 33 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class DeploymentTest method testDeployWorkerWithConfig.

@Test
public void testDeployWorkerWithConfig() throws Exception {
    MyVerticle verticle = new MyVerticle();
    JsonObject conf = generateJSONObject();
    vertx.deployVerticle(verticle, new DeploymentOptions().setConfig(conf).setWorker(true), ar -> {
        assertDeployment(1, verticle, conf, ar);
        assertFalse(verticle.startContext.isMultiThreadedWorkerContext());
        assertTrue(verticle.startContext.isWorkerContext());
        assertFalse(verticle.startContext.isEventLoopContext());
        vertx.undeploy(ar.result(), ar2 -> {
            assertTrue(ar2.succeeded());
            assertEquals(verticle.startContext, verticle.stopContext);
            testComplete();
        });
    });
    await();
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 34 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class ConversionHelperTest method testWrapObject.

/**
   * Confirm that when we convert to map/list form we do so recursively.
   */
@Test
public void testWrapObject() {
    // Create a JsonObject with nested JsonObject and JsonArray values
    JsonObject obj = new JsonObject().put("nestedObj", new JsonObject().put("key", "value")).put("nestedList", new JsonArray().add(new JsonObject().put("key", "value")));
    // Get the wrapped form and confirm that it acted recursively
    Map<String, Object> wrapped = ConversionHelper.fromObject(obj);
    assertTrue(wrapped.get("nestedObj") instanceof Map);
    List<Object> theList = (List<Object>) wrapped.get("nestedList");
    assertTrue(theList.get(0) instanceof Map);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) AsciiString(io.netty.util.AsciiString) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 35 with JsonObject

use of io.vertx.core.json.JsonObject in project vert.x by eclipse.

the class ConversionHelperTest method testFromJsonArray.

@Test
public void testFromJsonArray() {
    JsonArray object = new JsonArray();
    object.add("the_string");
    object.add(4);
    object.add(true);
    object.add("hello".getBytes());
    object.add(new JsonObject().put("nested", 4));
    object.add(new JsonArray().add(1).add(2).add(3));
    List<Object> map = ConversionHelper.fromObject(object);
    assertEquals(6, map.size());
    assertEquals("the_string", map.get(0));
    assertEquals(4, map.get(1));
    assertEquals(true, map.get(2));
    assertEquals("hello", new String(Base64.getDecoder().decode((String) map.get(3))));
    assertEquals(Collections.singletonMap("nested", 4), map.get(4));
    assertEquals(Arrays.asList(1, 2, 3), map.get(5));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)383 Test (org.junit.Test)210 JsonArray (io.vertx.core.json.JsonArray)89 HttpURLConnection (java.net.HttpURLConnection)68 Future (io.vertx.core.Future)55 Handler (io.vertx.core.Handler)51 Async (io.vertx.ext.unit.Async)50 Vertx (io.vertx.core.Vertx)48 TestContext (io.vertx.ext.unit.TestContext)48 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)47 RunWith (org.junit.runner.RunWith)47 Timeout (org.junit.rules.Timeout)43 Before (org.junit.Before)41 Rule (org.junit.Rule)33 EventBusMessage (org.eclipse.hono.util.EventBusMessage)27 AsyncResult (io.vertx.core.AsyncResult)26 Buffer (io.vertx.core.buffer.Buffer)26 Constants (org.eclipse.hono.util.Constants)25 Mockito (org.mockito.Mockito)25 Objects (java.util.Objects)23