use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestCompletableFutureConsumerResponseMapperFactory method completableFuture.
@Test
public void completableFuture() {
Method consumerMethod = ReflectUtils.findMethod(this.getClass(), "consumer");
Method swaggerMethod = ReflectUtils.findMethod(this.getClass(), "swagger");
ConsumerResponseMapper mapper = factory.createResponseMapper(factorys, swaggerMethod.getGenericReturnType(), consumerMethod.getGenericReturnType());
Response response = Response.ok(Arrays.asList("a", "b"));
String[] arr = (String[]) mapper.mapResponse(response);
Assert.assertThat(arr, Matchers.arrayContaining("a", "b"));
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestCseResponseConsumerResponseMapperFactory method createResponseMapper.
@Test
public void createResponseMapper() {
ConsumerResponseMapper mapper = factory.createResponseMapper(null, null, Response.class);
Response response = Response.ok(null);
Assert.assertSame(response, mapper.mapResponse(response));
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class SwaggerProducerOperation method doInvoke.
public Response doInvoke(SwaggerInvocation invocation) {
Response response = null;
try {
Object[] args = argumentsMapper.toProducerArgs(invocation);
Object result = producerMethod.invoke(producerInstance, args);
response = responseMapper.mapResponse(invocation.getStatus(), result);
} catch (Throwable e) {
response = processException(invocation, e);
}
return response;
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestResponse method test.
@Test
public void test() {
Response r = Response.create(200, "200", 2);
Assert.assertEquals(200, r.getStatusCode());
Assert.assertEquals(2, (int) r.getResult());
Response r1 = r.build();
Assert.assertEquals(r, r1);
r = Response.create(300, "300", 3);
Assert.assertEquals(300, r.getStatusCode());
Assert.assertEquals("300", r.getReasonPhrase());
Assert.assertEquals(3, ((InvocationException) r.getResult()).getErrorData());
r = Response.createSuccess(Status.OK, 2);
Assert.assertEquals(200, r.getStatusCode());
Assert.assertEquals(2, (int) r.getResult());
r = Response.success(2, Status.OK);
Assert.assertEquals(200, r.getStatusCode());
Assert.assertEquals(2, (int) r.getResult());
r = Response.createFail(InvocationType.CONSUMER, "abc");
Assert.assertEquals("CommonExceptionData [message=abc]", ((InvocationException) r.getResult()).getErrorData().toString());
Assert.assertEquals(490, r.getStatusCode());
r = Response.createFail(InvocationType.PRODUCER, "def");
Assert.assertEquals("CommonExceptionData [message=def]", ((InvocationException) r.getResult()).getErrorData().toString());
Assert.assertEquals(590, r.getStatusCode());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestExceptionFactory method convertExceptionToResponse.
@Test
public void convertExceptionToResponse() {
Error error = new Error("test");
Response response = ExceptionFactory.convertExceptionToResponse(null, error);
Assert.assertSame(Status.OK, response.getStatus());
Assert.assertEquals("response from error: test", response.getResult());
}
Aggregations