use of org.apache.servicecomb.common.rest.codec.produce.ProduceJsonProcessor in project incubator-servicecomb-java-chassis by apache.
the class TestDefaultHttpClientFilter method extractResult_decodeError.
@Test
public void extractResult_decodeError(@Mocked Invocation invocation, @Mocked ReadStreamPart part, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation, @Mocked HttpServletResponseEx responseEx) {
Map<String, Object> handlerContext = new HashMap<>();
new Expectations() {
{
invocation.getHandlerContext();
result = handlerContext;
invocation.getOperationMeta();
result = operationMeta;
invocation.findResponseType(400);
result = SimpleType.constructUnsafe(Date.class);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
result = swaggerRestOperation;
responseEx.getStatus();
result = 400;
responseEx.getBodyBuffer();
result = new BufferImpl().appendString("abc");
}
};
new MockUp<DefaultHttpClientFilter>() {
@Mock
ProduceProcessor findProduceProcessor(RestOperationMeta restOperation, HttpServletResponseEx responseEx) {
return new ProduceJsonProcessor();
}
};
Response response = filter.extractResponse(invocation, responseEx);
Assert.assertEquals(400, response.getStatusCode());
Assert.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
InvocationException invocationException = response.getResult();
Assert.assertEquals("InvocationException: code=400;msg=CommonExceptionData [message=method null, path null, statusCode 400, reasonPhrase null, response content-type null is not supported]", invocationException.getMessage());
Assert.assertEquals("Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" + " at [Source: (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream); line: 1, column: 4]", invocationException.getCause().getMessage());
Assert.assertEquals(CommonExceptionData.class, invocationException.getErrorData().getClass());
CommonExceptionData commonExceptionData = (CommonExceptionData) invocationException.getErrorData();
Assert.assertEquals("method null, path null, statusCode 400, reasonPhrase null, response content-type null is not supported", commonExceptionData.getMessage());
}
use of org.apache.servicecomb.common.rest.codec.produce.ProduceJsonProcessor in project incubator-servicecomb-java-chassis by apache.
the class TestDefaultHttpClientFilter method extractResult_decodeError200.
@Test
public void extractResult_decodeError200(@Mocked Invocation invocation, @Mocked ReadStreamPart part, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation, @Mocked HttpServletResponseEx responseEx) {
Map<String, Object> handlerContext = new HashMap<>();
new Expectations() {
{
invocation.getHandlerContext();
result = handlerContext;
invocation.getOperationMeta();
result = operationMeta;
invocation.findResponseType(200);
result = SimpleType.constructUnsafe(Date.class);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
result = swaggerRestOperation;
responseEx.getStatus();
result = 200;
responseEx.getBodyBuffer();
result = new BufferImpl().appendString("abc");
}
};
new MockUp<DefaultHttpClientFilter>() {
@Mock
ProduceProcessor findProduceProcessor(RestOperationMeta restOperation, HttpServletResponseEx responseEx) {
return new ProduceJsonProcessor();
}
};
Response response = filter.extractResponse(invocation, responseEx);
Assert.assertEquals(400, response.getStatusCode());
Assert.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
InvocationException invocationException = response.getResult();
Assert.assertEquals("InvocationException: code=400;msg=CommonExceptionData [message=method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported]", invocationException.getMessage());
Assert.assertEquals("Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" + " at [Source: (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream); line: 1, column: 4]", invocationException.getCause().getMessage());
Assert.assertEquals(CommonExceptionData.class, invocationException.getErrorData().getClass());
CommonExceptionData commonExceptionData = (CommonExceptionData) invocationException.getErrorData();
Assert.assertEquals("method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported", commonExceptionData.getMessage());
}
use of org.apache.servicecomb.common.rest.codec.produce.ProduceJsonProcessor in project java-chassis by ServiceComb.
the class TestDefaultHttpClientFilter method extractResult_decodeError.
@Test
public void extractResult_decodeError(@Mocked Invocation invocation, @Mocked ReadStreamPart part, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation, @Mocked HttpServletResponseEx responseEx) {
Map<String, Object> handlerContext = new HashMap<>();
new Expectations() {
{
invocation.getHandlerContext();
result = handlerContext;
invocation.getOperationMeta();
result = operationMeta;
invocation.findResponseType(400);
result = SimpleType.constructUnsafe(Date.class);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
result = swaggerRestOperation;
responseEx.getStatus();
result = 400;
responseEx.getBodyBuffer();
result = new BufferImpl().appendString("abc");
}
};
new MockUp<DefaultHttpClientFilter>() {
@Mock
ProduceProcessor findProduceProcessor(RestOperationMeta restOperation, HttpServletResponseEx responseEx) {
return new ProduceJsonProcessor();
}
};
Response response = filter.extractResponse(invocation, responseEx);
Assert.assertEquals(400, response.getStatusCode());
Assert.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
InvocationException invocationException = response.getResult();
Assert.assertEquals("InvocationException: code=400;msg=CommonExceptionData [message=method null, path null, statusCode 400, reasonPhrase null, response content-type null is not supported]", invocationException.getMessage());
Assert.assertEquals("Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" + " at [Source: (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream); line: 1, column: 4]", invocationException.getCause().getMessage());
Assert.assertEquals(CommonExceptionData.class, invocationException.getErrorData().getClass());
CommonExceptionData commonExceptionData = (CommonExceptionData) invocationException.getErrorData();
Assert.assertEquals("method null, path null, statusCode 400, reasonPhrase null, response content-type null is not supported", commonExceptionData.getMessage());
}
use of org.apache.servicecomb.common.rest.codec.produce.ProduceJsonProcessor in project java-chassis by ServiceComb.
the class TestDefaultHttpClientFilter method extractResult_decodeError200.
@Test
public void extractResult_decodeError200(@Mocked Invocation invocation, @Mocked ReadStreamPart part, @Mocked OperationMeta operationMeta, @Mocked RestOperationMeta swaggerRestOperation, @Mocked HttpServletResponseEx responseEx) {
Map<String, Object> handlerContext = new HashMap<>();
new Expectations() {
{
invocation.getHandlerContext();
result = handlerContext;
invocation.getOperationMeta();
result = operationMeta;
invocation.findResponseType(200);
result = SimpleType.constructUnsafe(Date.class);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
result = swaggerRestOperation;
responseEx.getStatus();
result = 200;
responseEx.getBodyBuffer();
result = new BufferImpl().appendString("abc");
}
};
new MockUp<DefaultHttpClientFilter>() {
@Mock
ProduceProcessor findProduceProcessor(RestOperationMeta restOperation, HttpServletResponseEx responseEx) {
return new ProduceJsonProcessor();
}
};
Response response = filter.extractResponse(invocation, responseEx);
Assert.assertEquals(400, response.getStatusCode());
Assert.assertEquals(InvocationException.class, response.<InvocationException>getResult().getClass());
InvocationException invocationException = response.getResult();
Assert.assertEquals("InvocationException: code=400;msg=CommonExceptionData [message=method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported]", invocationException.getMessage());
Assert.assertEquals("Unrecognized token 'abc': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" + " at [Source: (org.apache.servicecomb.foundation.vertx.stream.BufferInputStream); line: 1, column: 4]", invocationException.getCause().getMessage());
Assert.assertEquals(CommonExceptionData.class, invocationException.getErrorData().getClass());
CommonExceptionData commonExceptionData = (CommonExceptionData) invocationException.getErrorData();
Assert.assertEquals("method null, path null, statusCode 200, reasonPhrase null, response content-type null is not supported", commonExceptionData.getMessage());
}
Aggregations