use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method testDoSendResponseResultOKFilter.
@Test
public void testDoSendResponseResultOKFilter(@Mocked Response response) {
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
headers.set("Content-Type", "application/json");
new Expectations() {
{
response.getHeaders();
result = headers;
response.getStatusCode();
result = 123;
response.getReasonPhrase();
result = "reason";
response.getResult();
result = "ok";
}
};
Buffer buffer = Buffer.buffer();
responseEx = new MockUp<HttpServletResponseEx>() {
private Map<String, Object> attributes = new HashMap<>();
@Mock
public void setAttribute(String key, Object value) {
this.attributes.put(key, value);
}
@Mock
public Object getAttribute(String key) {
return this.attributes.get(key);
}
@Mock
void setBodyBuffer(Buffer bodyBuffer) {
buffer.appendBuffer(bodyBuffer);
}
}.getMockInstance();
HttpServerFilter filter = new HttpServerFilterBaseForTest() {
@Override
public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
buffer.appendString("-filter");
}
};
invocation.onStart(0);
initRestInvocation();
List<HttpServerFilter> httpServerFilters = SPIServiceUtils.loadSortedService(HttpServerFilter.class);
httpServerFilters.add(filter);
restInvocation.setHttpServerFilters(httpServerFilters);
restInvocation.sendResponse(response);
assertEquals("\"ok\"-filter", buffer.toString());
}
use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class VertxRestInvocationTest method testCreateInvocation.
@Test
public void testCreateInvocation() {
new MockUp<RestProducerInvocation>() {
/**
* Mock this method to avoid error
*/
@Mock
void createInvocation() {
}
};
VertxRestInvocation vertxRestInvocation = new VertxRestInvocation();
VertxServerRequestToHttpServletRequest requestEx = Mockito.mock(VertxServerRequestToHttpServletRequest.class);
RoutingContext routingContext = Mockito.mock(RoutingContext.class);
Invocation invocation = Mockito.mock(Invocation.class);
Deencapsulation.setField(vertxRestInvocation, "requestEx", requestEx);
Deencapsulation.setField(vertxRestInvocation, "invocation", invocation);
Mockito.when(requestEx.getContext()).thenReturn(routingContext);
Deencapsulation.invoke(vertxRestInvocation, "createInvocation");
Mockito.verify(routingContext, Mockito.times(1)).put(RestConst.REST_INVOCATION_CONTEXT, invocation);
}
use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestHttpServerFilterBeforeSendResponseExecutor method runFail.
@Test
public void runFail() throws InterruptedException, ExecutionException {
httpServerFilters.add(new HttpServerFilterBaseForTest() {
@Override
public CompletableFuture<Void> beforeSendResponseAsync(Invocation invocation, HttpServletResponseEx responseEx) {
throw new RuntimeExceptionWithoutStackTrace();
}
});
CompletableFuture<Void> result = executor.run();
expectedException.expect(ExecutionException.class);
expectedException.expectCause(Matchers.instanceOf(RuntimeExceptionWithoutStackTrace.class));
result.get();
}
use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class EdgeInvocationCreator method createInstance.
@Override
protected Invocation createInstance() {
ReferenceConfig referenceConfig = microserviceReferenceConfig.createReferenceConfig(restOperationMeta.getOperationMeta());
Invocation invocation = InvocationFactory.forConsumer(referenceConfig, restOperationMeta.getOperationMeta(), restOperationMeta.getOperationMeta().buildBaseConsumerRuntimeType(), null);
invocation.setSync(false);
invocation.setEdge(true);
invocation.addLocalContext(EDGE_INVOCATION_CONTEXT, Vertx.currentContext());
return invocation;
}
use of org.apache.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestCustomCommandGroupKey method testOOM.
@Test
public void testOOM() {
Invocation invocation1 = Mockito.mock(Invocation.class);
Invocation invocation2 = Mockito.mock(Invocation.class);
CustomizeCommandGroupKey customizeCommandGroupKey1 = (CustomizeCommandGroupKey) CustomizeCommandGroupKey.asKey("key", invocation1);
CustomizeCommandGroupKey customizeCommandGroupKey2 = (CustomizeCommandGroupKey) CustomizeCommandGroupKey.asKey("key", invocation2);
Assert.assertEquals(customizeCommandGroupKey1, customizeCommandGroupKey2);
}
Aggregations