Java Code Examples for org.apache.servicecomb.swagger.invocation.Response#succResp()
The following examples show how to use
org.apache.servicecomb.swagger.invocation.Response#succResp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestConfig.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testHttpResponse() { String objectString = new String("Unit Testing"); Response oResponse = Response.success(objectString, Status.OK); Assert.assertEquals(true, oResponse.isSuccessed()); oResponse = Response.succResp(objectString); Assert.assertEquals(true, oResponse.isSuccessed()); Assert.assertEquals(200, oResponse.getStatusCode()); Throwable oThrowable = new Throwable("Error"); oResponse = Response.consumerFailResp(oThrowable); Assert.assertEquals(true, oResponse.isFailed()); oResponse = Response.providerFailResp(oThrowable); Assert.assertEquals(true, oResponse.isFailed()); }
Example 2
Source File: FromCacheFallbackPolicy.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Override public Response getFallbackResponse(Invocation invocation, Throwable error) { if (cachedResponse.get(invocation.getInvocationQualifiedName()) != null) { return cachedResponse.get(invocation.getInvocationQualifiedName()); } else { return Response.succResp(null); } }
Example 3
Source File: TestInvocation.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void onFinish() { mockNonaTime(); Holder<InvocationFinishEvent> result = new Holder<>(); Object subscriber = new Object() { @Subscribe public void onStart(InvocationFinishEvent event) { result.value = event; } }; EventManager.register(subscriber); Invocation invocation = new Invocation(endpoint, operationMeta, arguments); Assert.assertFalse(invocation.isFinished()); Response response = Response.succResp(null); invocation.onFinish(response); Assert.assertEquals(nanoTime, result.value.getNanoCurrent()); Assert.assertSame(invocation, result.value.getInvocation()); Assert.assertSame(response, result.value.getResponse()); Assert.assertTrue(invocation.isFinished()); // should not post event again InvocationFinishEvent oldEvent = result.value; invocation.onFinish(null); Assert.assertSame(oldEvent, result.value); EventManager.unregister(subscriber); }
Example 4
Source File: MockedFallbackExample.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Override public Response getFallbackResponse(Invocation invocation, Throwable error) { return Response.succResp("mockedreslut"); }
Example 5
Source File: TestResponse.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Test public void testAr() { ar.success(Status.ACCEPTED, 1); Assert.assertEquals(true, response.isSuccessed()); Assert.assertEquals(false, response.isFailed()); Assert.assertEquals(1, (int) response.getResult()); Assert.assertEquals(Status.ACCEPTED.getStatusCode(), response.getStatusCode()); Assert.assertEquals(Status.ACCEPTED.getReasonPhrase(), response.getReasonPhrase()); Assert.assertEquals(Status.ACCEPTED, response.getStatus()); ar.success(2); Assert.assertEquals(2, (int) response.getResult()); Assert.assertEquals(Status.OK.getStatusCode(), response.getStatusCode()); Response r = Response.succResp(3); ar.complete(r); Assert.assertEquals(r, response); ar.consumerFail(new RuntimeExceptionWithoutStackTrace("abc")); CommonExceptionData data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData(); Assert.assertEquals("Unexpected consumer error, please check logs for details", data.getMessage()); Assert.assertEquals(ExceptionFactory.CONSUMER_INNER_STATUS_CODE, response.getStatusCode()); ar.fail(InvocationType.CONSUMER, new RuntimeExceptionWithoutStackTrace("abc")); data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData(); Assert.assertEquals("Unexpected consumer error, please check logs for details", data.getMessage()); Assert.assertEquals(ExceptionFactory.CONSUMER_INNER_STATUS_CODE, response.getStatusCode()); InvocationException consumerException = new InvocationException(300, "abc", "def"); ar.consumerFail(consumerException); Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData()); Assert.assertEquals(300, response.getStatusCode()); ar.fail(InvocationType.CONSUMER, consumerException); Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData()); Assert.assertEquals(300, response.getStatusCode()); ar.producerFail(new RuntimeExceptionWithoutStackTrace("abc")); data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData(); Assert.assertEquals("Unexpected producer error, please check logs for details", data.getMessage()); Assert.assertEquals(ExceptionFactory.PRODUCER_INNER_STATUS_CODE, response.getStatusCode()); ar.fail(InvocationType.PRODUCER, new RuntimeExceptionWithoutStackTrace("abc")); data = (CommonExceptionData) ((InvocationException) response.getResult()).getErrorData(); Assert.assertEquals("Unexpected producer error, please check logs for details", data.getMessage()); Assert.assertEquals(ExceptionFactory.PRODUCER_INNER_STATUS_CODE, response.getStatusCode()); InvocationException producerException = new InvocationException(500, "abc", "def"); ar.producerFail(producerException); Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData()); Assert.assertEquals(500, response.getStatusCode()); ar.fail(InvocationType.PRODUCER, producerException); Assert.assertEquals("def", ((InvocationException) response.getResult()).getErrorData()); Assert.assertEquals(500, response.getStatusCode()); }
Example 6
Source File: ReturnNullFallbackPolicy.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
@Override public Response getFallbackResponse(Invocation invocation, Throwable error) { return Response.succResp(null); }