Search in sources :

Example 46 with Response

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"));
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response)

Example 47 with Response

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());
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) Test(org.junit.Test)

Example 48 with Response

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());
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) Test(org.junit.Test)

Example 49 with Response

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);
    }
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) SyncResponseExecutor(org.apache.servicecomb.core.provider.consumer.SyncResponseExecutor) Test(org.junit.Test)

Example 50 with Response

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;
    }
}
Also used : AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Response(org.apache.servicecomb.swagger.invocation.Response)

Aggregations

Response (org.apache.servicecomb.swagger.invocation.Response)65 Test (org.junit.Test)44 Invocation (org.apache.servicecomb.core.Invocation)17 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)14 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)11 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)8 Expectations (mockit.Expectations)7 ResponseEntity (org.springframework.http.ResponseEntity)7 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)6 MockUp (mockit.MockUp)6 Method (java.lang.reflect.Method)5 Headers (org.apache.servicecomb.swagger.invocation.response.Headers)5 Holder (javax.xml.ws.Holder)4 User (org.apache.servicecomb.demo.server.User)4 InvocationContext (org.apache.servicecomb.swagger.invocation.context.InvocationContext)4 CommonExceptionData (org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData)4 HttpHeaders (org.springframework.http.HttpHeaders)4 ApiResponse (io.swagger.annotations.ApiResponse)3 List (java.util.List)3 ResponseHeaders (org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders)3