use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class TestVertxToServletMockRequest method testGetLocalPort.
@Test
public void testGetLocalPort() {
try {
init();
HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
Mockito.when(httpServerRequest.localAddress()).thenReturn(socketAddress);
Mockito.when(socketAddress.port()).thenReturn(8080);
instance.getLocalPort();
} catch (Exception e) {
Assert.assertNotNull(e);
} catch (Error e) {
Assert.assertNotNull(e);
}
}
use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class TestVertxToServletMockRequest method testGetRemotePort.
@Test
public void testGetRemotePort() {
try {
init();
HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
Mockito.when(httpServerRequest.remoteAddress()).thenReturn(socketAddress);
Mockito.when(socketAddress.port()).thenReturn(8080);
Assert.assertEquals(8080, instance.getRemotePort());
} catch (Exception e) {
Assert.assertNotNull(e);
} catch (Error e) {
Assert.assertNotNull(e);
}
}
use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class TestVertxToServletMockRequest method testGetParameterValues.
@Test
public void testGetParameterValues() {
boolean validAssert = true;
try {
HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
MultiMap multiMap = Mockito.mock(MultiMap.class);
Mockito.when(httpServerRequest.params()).thenReturn(multiMap);
List<String> stringList = new ArrayList<String>();
stringList.add("sters");
Mockito.when(multiMap.getAll("key")).thenReturn(stringList);
Assert.assertNotNull(instance.getParameterValues("param"));
} catch (Exception e) {
Assert.assertNotNull(e);
validAssert = false;
} catch (Error e) {
Assert.assertNotNull(e);
validAssert = false;
}
Assert.assertTrue(validAssert);
}
use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class TestVertxToServletMockRequest method testGetParameterMap.
@Test
public void testGetParameterMap() {
boolean validAssert = true;
try {
init();
@SuppressWarnings("unused") Map<String, String[]> paramMap = new HashMap<>();
HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
MultiMap multiMap = Mockito.mock(MultiMap.class);
Mockito.when(httpServerRequest.params()).thenReturn(multiMap);
Set<String> stringSet = new HashSet<String>();
stringSet.add("sters");
Mockito.when(multiMap.names()).thenReturn(stringSet);
Assert.assertNotNull(instance.getParameterMap());
} catch (Exception e) {
Assert.assertNotNull(e);
validAssert = false;
} catch (Error e) {
Assert.assertNotNull(e);
validAssert = false;
}
Assert.assertTrue(validAssert);
}
use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.
the class TestGrpcCodec method testEncodeResponse.
@Test
public void testEncodeResponse() {
boolean status = false;
try {
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
Invocation invocation = Mockito.mock(Invocation.class);
Response response = Mockito.mock(Response.class);
Mockito.when(response.getResult()).thenReturn("test");
Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
GrpcCodec.encodeResponse(invocation, response, operationProtobuf);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
Aggregations