use of io.vertx.ext.web.RoutingContext in project yyl_example by Relucent.
the class HelloVertxVerticle method start.
/** 运行 */
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.get("/hello").handler(new Handler<RoutingContext>() {
public void handle(RoutingContext event) {
event.response().putHeader("content-type", "text/html").end("Hello Vert.x");
}
});
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest event) {
router.accept(event);
}
}).listen(//监听端口号
8080);
}
use of io.vertx.ext.web.RoutingContext in project java-chassis by ServiceComb.
the class TestGrpcCodec method testDecodeResponse.
@Test
public void testDecodeResponse() {
boolean status = false;
try {
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Buffer bodyBuffer = Mockito.mock(Buffer.class);
Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(routingContext.request()).thenReturn(request);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
Buffer buffer = Mockito.mock(Buffer.class);
GrpcCodec.decodeResponse(invocation, operationProtobuf, httpResponse, buffer);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.vertx.ext.web.RoutingContext in project java-chassis by ServiceComb.
the class TestGrpcCodec method testDecodeRequest.
@Test
public void testDecodeRequest() {
boolean status = false;
try {
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Buffer bodyBuffer = Mockito.mock(Buffer.class);
Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(routingContext.request()).thenReturn(request);
SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
GrpcCodec.setGrpcTransport(new GrpcTransport());
GrpcCodec.decodeRequest(routingContext, operationMeta);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.vertx.ext.web.RoutingContext in project java-chassis by ServiceComb.
the class TestRestVertxHttpRequest method testGetCookieParam.
@Test
public void testGetCookieParam() {
Cookie cookie = Mockito.mock(Cookie.class);
RoutingContext context = Mockito.mock(RoutingContext.class);
Deencapsulation.setField(instance, "context", context);
Mockito.when(context.getCookie("key")).thenReturn(cookie);
Assert.assertNull(instance.getCookieParam("key"));
}
use of io.vertx.ext.web.RoutingContext in project java-chassis by ServiceComb.
the class TestVertxRestServer method testFailureHandler.
@Test
public void testFailureHandler() {
RoutingContext context = Mockito.mock(RoutingContext.class);
Mockito.when(context.response()).thenReturn(Mockito.mock(HttpServerResponse.class));
boolean status = false;
try {
Deencapsulation.invoke(instance, "failureHandler", context);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
Aggregations