use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestVertxPostMethod method testVertxPostMethod.
@Test
public void testVertxPostMethod() {
Invocation invocation = Mockito.mock(Invocation.class);
HttpClient client = Mockito.mock(HttpClient.class);
IpPort ipPort = Mockito.mock(IpPort.class);
RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
Mockito.when(ipPort.getPort()).thenReturn(23);
assertEquals(23, ipPort.getPort());
Mockito.when(ipPort.getHostOrIp()).thenReturn("testCall");
assertNotNull("testCall", ipPort.getHostOrIp());
HttpClientRequest obj = VertxPostMethod.INSTANCE.createRequest(client, invocation, ipPort, "test", operation, asyncResp);
Assert.assertNull(obj);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestServletRestTransport method testSendException.
@Test
public void testSendException() {
boolean status = true;
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
Endpoint endpoint1 = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(endpoint1);
Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
try {
transport.send(invocation, asyncResp);
} catch (Exception exce) {
Assert.assertNotNull(exce);
status = false;
}
Assert.assertFalse(status);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestBizkeeperCommand method testGetCacheKeyWithContextInitializedProvider.
@Test
public void testGetCacheKeyWithContextInitializedProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation, HystrixObservableCommand.Setter.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation)).andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation)).andCommandPropertiesDefaults(setter));
HystrixRequestContext.initializeContext();
String cacheKey = bizkeeperCommand.getCacheKey();
Assert.assertNotNull(cacheKey);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestBizkeeperCommand method testGetCacheKeyConsumer.
@Test
public void testGetCacheKeyConsumer() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation, HystrixObservableCommand.Setter.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation)).andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation)).andCommandPropertiesDefaults(setter));
String str = bizkeeperCommand.getCacheKey();
Assert.assertNull(str);
Response resp = Mockito.mock(Response.class);
Mockito.when(resp.isFailed()).thenReturn(false);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.isFailed()).thenReturn(true);
InvocationException excp = Mockito.mock(InvocationException.class);
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(400);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(490);
Assert.assertEquals(true, bizkeeperCommand.isFailedResponse(resp));
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestBizkeeperCommand method testResumeWithFallbackConsumer.
@Test
public void testResumeWithFallbackConsumer() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation, HystrixObservableCommand.Setter.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation)).andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation)).andCommandPropertiesDefaults(setter));
Observable<Response> observe = bizkeeperCommand.resumeWithFallback();
Assert.assertNotNull(observe);
}
Aggregations