use of io.vertx.core.Context in project java-chassis by ServiceComb.
the class TestVertxHttpMethod method testDoMethod.
@Test
public void testDoMethod(@Mocked HttpClient httpClient) throws Exception {
Context context = new MockUp<Context>() {
@Mock
public void runOnContext(Handler<Void> action) {
action.handle(null);
}
}.getMockInstance();
HttpClientWithContext httpClientWithContext = new HttpClientWithContext(httpClient, context);
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = Mockito.mock(RestOperationMeta.class);
Endpoint endpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = Mockito.mock(URLPathBuilder.class);
Mockito.when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
Mockito.when(request.exceptionHandler(Mockito.any())).then(answer -> null);
this.doMethod(httpClientWithContext, invocation, asyncResp);
Assert.assertTrue(true);
}
use of io.vertx.core.Context in project java-chassis by ServiceComb.
the class TestTcp method testTcpClient.
@Test
public void testTcpClient() throws Exception {
NetClient oNetClient = new NetClient() {
@Override
public boolean isMetricsEnabled() {
// TODO Auto-generated method stub
return true;
}
@Override
public NetClient connect(int port, String host, Handler<AsyncResult<NetSocket>> connectHandler) {
return Mockito.mock(NetClient.class);
}
@Override
public void close() {
// TODO Auto-generated method stub
}
};
TcpClient oTcpClient = new TcpClient(Mockito.mock(Context.class), oNetClient, "highway://127.2.0.1:8080", new TcpClientConfig());
oTcpClient.checkTimeout();
oTcpClient.send(new TcpOutputStream(), 123, Mockito.mock(TcpResonseCallback.class));
oTcpClient.send(new TcpOutputStream(), 123, Mockito.mock(TcpResonseCallback.class));
Assert.assertNotEquals(null, oTcpClient.getContext());
new MockUp<TcpClientPool>() {
@Mock
protected void startCheckTimeout(TcpClientConfig clientConfig, Context context) {
}
};
TcpClientConfig config = new TcpClientConfig();
TcpClientPool oClientPool = new TcpClientPool(config, Vertx.vertx().getOrCreateContext(), oNetClient);
oClientPool.send("highway://152.2.2.3:8080", new TcpOutputStream(), Mockito.mock(TcpResonseCallback.class));
oClientPool.send("highway://152.2.2.3:8080", new TcpOutputStream(), Mockito.mock(TcpResonseCallback.class));
Assert.assertNotNull(oClientPool);
TcpRequest oTcpRequest = new TcpRequest(1234, Mockito.mock(TcpResonseCallback.class));
oTcpRequest.isTimeout();
oTcpRequest.onReply(Buffer.buffer(), Buffer.buffer(("test").getBytes()));
oTcpRequest.onSendError(new Throwable("test Errorsss"));
Assert.assertNotNull(oTcpRequest);
TcpClientVerticle oTcpClientVerticle = new TcpClientVerticle();
oTcpClientVerticle.init(Vertx.vertx(), Vertx.vertx().getOrCreateContext());
oTcpClientVerticle.createClientPool();
oTcpClientVerticle.createClientPool();
Assert.assertNotNull(oTcpClientVerticle.getVertx());
NetSocket socket = Mockito.mock(NetSocket.class);
Throwable e = Mockito.mock(Throwable.class);
Buffer hBuffer = Mockito.mock(Buffer.class);
Buffer bBuffer = Mockito.mock(Buffer.class);
Deencapsulation.invoke(oTcpClient, "connect");
Deencapsulation.invoke(oTcpClient, "onConnectSuccess", socket);
Mockito.when(socket.localAddress()).thenReturn(new SocketAddressImpl(0, "127.0.0.1"));
Deencapsulation.setField(oTcpClient, "netSocket", socket);
Deencapsulation.invoke(oTcpClient, "onDisconnected", e);
Deencapsulation.invoke(oTcpClient, "tryLogin");
Deencapsulation.invoke(oTcpClient, "onLoginSuccess");
Deencapsulation.invoke(oTcpClient, "onConnectFailed", e);
long l = 10;
Deencapsulation.invoke(oTcpClient, "onReply", l, hBuffer, bBuffer);
oTcpClient.checkTimeout();
Assert.assertNotNull(oTcpClient);
}
use of io.vertx.core.Context in project java-chassis by ServiceComb.
the class TcpClientTest method setUp.
@Before
public void setUp() throws Exception {
Context context = Mockito.mock(Context.class);
NetClient netClient = Mockito.mock(NetClient.class);
InetSocketAddress socketAddress = Mockito.mock(InetSocketAddress.class);
mockTestCases();
Mockito.when(NetUtils.parseIpPort("sss").getSocketAddress()).thenReturn(socketAddress);
instance = new TcpClient(context, netClient, "highway://127.0.0.1:80", new TcpClientConfig());
}
use of io.vertx.core.Context in project vertx-proton by vert-x3.
the class ProtonServerImplTest method testCustomAuthenticatorHasInitCalled.
@Test(timeout = 20000)
public void testCustomAuthenticatorHasInitCalled(TestContext context) {
Async initCalledAsync = context.async();
ProtonServer.create(vertx).saslAuthenticatorFactory(new ProtonSaslAuthenticatorFactory() {
@Override
public ProtonSaslAuthenticator create() {
return new ProtonSaslAuthenticator() {
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
initCalledAsync.complete();
}
@Override
public void process(Handler<Boolean> completionHandler) {
completionHandler.handle(false);
}
@Override
public boolean succeeded() {
return false;
}
};
}
}).connectHandler(protonConnection -> {
}).listen(server -> ProtonClient.create(vertx).connect("localhost", server.result().actualPort(), protonConnectionAsyncResult -> {
}));
}
use of io.vertx.core.Context in project vertx-proton by vert-x3.
the class ProtonServerImplTest method testCustomAuthenticatorSuceedsAuthentication.
@Test(timeout = 20000)
public void testCustomAuthenticatorSuceedsAuthentication(TestContext context) {
Async connectedAsync = context.async();
Async authenticatedAsync = context.async();
ProtonServer.create(vertx).saslAuthenticatorFactory(new TestPlainAuthenticatorFactory()).connectHandler(protonConnection -> {
// Verify the expected auth detail was recorded in the connection attachments, just using a String here.
String authValue = protonConnection.attachments().get(AUTH_KEY, String.class);
context.assertEquals(AUTH_VALUE, authValue);
authenticatedAsync.complete();
}).listen(server -> ProtonClient.create(vertx).connect("localhost", server.result().actualPort(), GOOD_USER, PASSWD, protonConnectionAsyncResult -> {
context.assertTrue(protonConnectionAsyncResult.succeeded());
protonConnectionAsyncResult.result().disconnect();
connectedAsync.complete();
}));
authenticatedAsync.awaitSuccess();
connectedAsync.awaitSuccess();
}
Aggregations