Search in sources :

Example 31 with Response

use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.

the class TestDefaultProducerResponseMapper method mapResponse.

@Test
public void mapResponse() {
    Response result = mapper.mapResponse(Status.OK, 1);
    Assert.assertSame(Status.OK, result.getStatus());
    Assert.assertEquals("1", result.getResult());
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) Test(org.junit.Test)

Example 32 with Response

use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.

the class TestDefaultProducerResponseMapperFactory method createResponseMapper.

@Test
public void createResponseMapper() {
    ProducerResponseMapper mapper = factory.createResponseMapper(null, String.class, Integer.class);
    Response result = mapper.mapResponse(Status.OK, 1);
    Assert.assertSame(Status.OK, result.getStatus());
    Assert.assertEquals("1", result.getResult());
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) Test(org.junit.Test)

Example 33 with Response

use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.

the class TestJaxrsConsumerResponseMapper method mapResponse_withHeaders.

@SuppressWarnings("unchecked")
@Test
public void mapResponse_withHeaders() {
    Response response = Response.create(Status.OK, "ret");
    response.getHeaders().addHeader("h", "v");
    mapper.mapResponse(response);
    Assert.assertEquals(Status.OK.getStatusCode(), status);
    Assert.assertEquals("ret", entity);
    Assert.assertEquals(1, headers.size());
    Assert.assertThat((List<Object>) headers.get("h"), Matchers.contains("v"));
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) Test(org.junit.Test)

Example 34 with Response

use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.

the class TestJaxrsConsumerResponseMapper method mapResponse_withoutHeaders.

@Test
public void mapResponse_withoutHeaders() {
    Response response = Response.create(Status.OK, "ret");
    mapper.mapResponse(response);
    Assert.assertEquals(Status.OK.getStatusCode(), status);
    Assert.assertEquals("ret", entity);
    Assert.assertEquals(0, headers.size());
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) Test(org.junit.Test)

Example 35 with Response

use of org.apache.servicecomb.swagger.invocation.Response in project incubator-servicecomb-java-chassis by apache.

the class TestJaxrsProducerResponseMapper method mapResponse_withoutHeaders.

@Test
public void mapResponse_withoutHeaders() {
    new Expectations() {

        {
            jaxrsResponse.getStatusInfo();
            result = Status.OK;
            jaxrsResponse.getEntity();
            result = "result";
        }
    };
    Response response = mapper.mapResponse(null, jaxrsResponse);
    Assert.assertEquals(Status.OK, response.getStatus());
    Assert.assertEquals("result", response.getResult());
    Assert.assertNull(response.getHeaders().getHeaderMap());
}
Also used : Expectations(mockit.Expectations) Response(org.apache.servicecomb.swagger.invocation.Response) Test(org.junit.Test)

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