use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestGeneric method testHolderUser_rest.
@SuppressWarnings("unchecked")
private void testHolderUser_rest() {
Holder<User> holder = new Holder<>(new User());
Holder<User> result = intf.testHolderUser(holder);
TestMgr.check("{\"name\":\"nameA\",\"age\":100,\"index\":0,\"names\":null}", result.value.jsonString());
result = restTemplate.postForObject(prefix + "/holderUser", holder, Holder.class);
TestMgr.check("{\"name\":\"nameA\",\"age\":100,\"index\":0,\"names\":null}", result.value.jsonString());
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestObject method testObject.
@SuppressWarnings("unchecked")
private void testObject() {
// int
Object result = intf.testObject(1);
TestMgr.check(1, result);
TestMgr.check(Integer.class, result.getClass());
result = restTemplate.postForObject(prefix + "/object", 1, Integer.class);
TestMgr.check(1, result);
TestMgr.check(Integer.class, result.getClass());
// string
result = intf.testObject("str");
TestMgr.check("str", result);
TestMgr.check(String.class, result.getClass());
result = restTemplate.postForObject(prefix + "/object", "str", String.class);
TestMgr.check("str", result);
TestMgr.check(String.class, result.getClass());
// emptyObject
result = intf.testObject(new EmptyObject());
// result may not be an empty map in highway
// TestMgr.check("{}", result);
TestMgr.check(true, Map.class.isAssignableFrom(result.getClass()));
result = restTemplate.postForObject(prefix + "/object", new EmptyObject(), EmptyObject.class);
TestMgr.check(EmptyObject.class, result.getClass());
result = restTemplate.postForObject(prefix + "/object", new EmptyObject(), EmptyObject.class);
TestMgr.check(EmptyObject.class, result.getClass());
// map
Map<String, String> map = Collections.singletonMap("k", "v");
result = intf.testObject(map);
TestMgr.check("{k=v}", result);
TestMgr.check(true, Map.class.isAssignableFrom(result.getClass()));
result = restTemplate.postForObject(prefix + "/object", map, Map.class);
TestMgr.check("{k=v}", result);
TestMgr.check(true, Map.class.isAssignableFrom(result.getClass()));
// list
List<String> list = Collections.singletonList("v");
result = intf.testObject(list);
TestMgr.check("[v]", result);
TestMgr.check(true, List.class.isAssignableFrom(result.getClass()));
result = restTemplate.postForObject(prefix + "/object", list, List.class);
TestMgr.check("[v]", result);
TestMgr.check(true, List.class.isAssignableFrom(result.getClass()));
// generic
Holder<String> holder = new Holder<>("v");
result = intf.testObject(holder);
TestMgr.check("v", ((Map<String, String>) result).get("value"));
TestMgr.check(LinkedHashMap.class, result.getClass());
result = restTemplate.postForObject(prefix + "/object", holder, Holder.class);
TestMgr.check("v", ((Map<String, String>) result).get("value"));
TestMgr.check(LinkedHashMap.class, result.getClass());
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestVertxServerRequestToHttpServletRequest method setBodyBuffer.
@Test
public void setBodyBuffer() {
Holder<Buffer> bodyHolder = new Holder<>();
context = new MockUp<RoutingContext>() {
@Mock
HttpServerRequest request() {
return vertxRequest;
}
@Mock
void setBody(Buffer body) {
bodyHolder.value = body;
}
}.getMockInstance();
request = new VertxServerRequestToHttpServletRequest(context);
Buffer bodyBuffer = Buffer.buffer();
request.setBodyBuffer(bodyBuffer);
Assert.assertSame(bodyBuffer, bodyHolder.value);
Assert.assertSame(bodyBuffer, request.getBodyBuffer());
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestVertxUtils method testGetOrCreateVertx.
@Test
public void testGetOrCreateVertx() throws InterruptedException {
Vertx vertx = VertxUtils.getOrCreateVertxByName("ut", null);
Holder<String> name = new Holder<>();
CountDownLatch latch = new CountDownLatch(1);
vertx.runOnContext(v -> {
name.value = Thread.currentThread().getName();
latch.countDown();
});
latch.await();
Assert.assertEquals(name.value, "ut-vert.x-eventloop-thread-0");
VertxUtils.blockCloseVertxByName("ut");
}
use of org.apache.servicecomb.foundation.common.Holder in project java-chassis by ServiceComb.
the class TestInspectorBootListener method enabled.
@Test
public void enabled() {
Holder<Object> holder = new Holder<>();
SCBEngine scbEngine = SCBBootstrap.createSCBEngineForTest();
scbEngine.setProducerMicroserviceMeta(new MicroserviceMeta(scbEngine, "ms", false));
scbEngine.setProducerProviderManager(new ProducerProviderManager(scbEngine) {
@Override
public SchemaMeta registerSchema(String schemaId, Object instance) {
if ("inspector".equals(schemaId)) {
holder.value = instance;
}
return null;
}
});
InspectorConfig inspectorConfig = new InspectorConfig().setEnabled(true);
new InspectorBootListener(inspectorConfig, null).onAfterTransport(new BootEvent(scbEngine, EventType.AFTER_TRANSPORT));
Assert.assertNotNull(holder.value);
}
Aggregations