use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestResponse method testCseResponse.
private void testCseResponse() {
String srcName = RegistryUtils.getMicroservice().getServiceName();
Response cseResponse = intf.cseResponse();
TestMgr.check("User [name=nameA, age=100, index=0]", cseResponse.getResult());
TestMgr.check("h1v " + srcName, cseResponse.getHeaders().getFirst("h1"));
TestMgr.check("h2v " + srcName, cseResponse.getHeaders().getFirst("h2"));
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestConfig method testHttpResponse.
@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());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestConfig method testResponse.
@Test
public void testResponse() {
Response response = Response.create(400, "test", null);
InvocationException exception = response.getResult();
Assert.assertEquals(null, exception.getErrorData());
response = Response.create(400, "test", "errorData");
exception = response.getResult();
Assert.assertEquals("errorData", exception.getErrorData());
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class TestSyncResponseExecutor method testSyncResponseExecutor.
@Test
public void testSyncResponseExecutor() {
SyncResponseExecutor executor = new SyncResponseExecutor();
Runnable cmd = Mockito.mock(Runnable.class);
Response response = Mockito.mock(Response.class);
executor.execute(cmd);
executor.setResponse(response);
try {
Response responseValue = executor.waitResponse();
Assert.assertNotNull(responseValue);
} catch (Exception e) {
Assert.assertNotNull(e);
}
}
use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.
the class InvokerUtils method innerSyncInvoke.
public static Response innerSyncInvoke(Invocation invocation) {
try {
invocation.onStart();
SyncResponseExecutor respExecutor = new SyncResponseExecutor();
invocation.setResponseExecutor(respExecutor);
invocation.next(respExecutor::setResponse);
Response response = respExecutor.waitResponse();
invocation.onFinish(response);
return response;
} catch (Throwable e) {
String msg = String.format("invoke failed, %s", invocation.getOperationMeta().getMicroserviceQualifiedName());
LOGGER.debug(msg, e);
Response response = Response.createConsumerFail(e);
invocation.onFinish(response);
return response;
}
}
Aggregations