use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestResponse method testAr.
@Test
public void testAr() {
ar.success(Status.ACCEPTED, 1);
Assert.assertEquals(true, response.isSucceed());
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());
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method sendResponseQuietlyExceptionOnNullInvocation.
@Test
public void sendResponseQuietlyExceptionOnNullInvocation(@Mocked Response response) {
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void doInvoke() {
}
@Override
protected void sendResponse(Response response) {
throw new RuntimeExceptionWithoutStackTrace("");
}
};
initRestInvocation();
restInvocation.invocation = null;
restInvocation.sendResponseQuietly(response);
// just log, check nothing, and should not throw NPE
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method testDoSendResponseHeaderNormal.
@Test
public void testDoSendResponseHeaderNormal(@Mocked Response response) {
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
headers.add("h1", "h1v1");
headers.add("h1", "h1v2");
headers.add("h2", "h2v");
new Expectations() {
{
response.getResult();
result = new RuntimeExceptionWithoutStackTrace("stop");
response.getHeaders();
result = headers;
}
};
MultiMap resultHeaders = MultiMap.caseInsensitiveMultiMap();
responseEx = new MockUp<HttpServletResponseEx>() {
private Map<String, Object> attributes = new HashMap<>();
@Mock
public void setAttribute(String key, Object value) {
this.attributes.put(key, value);
}
@Mock
public Object getAttribute(String key) {
return this.attributes.get(key);
}
@Mock
void addHeader(String name, String value) {
resultHeaders.add(name, value);
}
}.getMockInstance();
invocation.onStart(0);
initRestInvocation();
try {
restInvocation.sendResponse(response);
Assert.fail("must throw exception");
} catch (Error e) {
assertEquals(headers.toString(), resultHeaders.toString());
}
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestClassPathStaticResourceHandler method readContentFailed.
@Test
public void readContentFailed() throws IOException {
new Expectations(handler) {
{
handler.findResource(anyString);
result = new RuntimeExceptionWithoutStackTrace("read content failed.");
}
};
try (LogCollector logCollector = new LogCollector()) {
Response response = handler.handle("index.html");
Assert.assertEquals("failed to process static resource, path=web-root/index.html", logCollector.getLastEvents().getMessage());
InvocationException invocationException = response.getResult();
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR, invocationException.getStatus());
Assert.assertEquals("failed to process static resource.", ((CommonExceptionData) invocationException.getErrorData()).getMessage());
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
Assert.assertEquals(Status.INTERNAL_SERVER_ERROR.getReasonPhrase(), response.getReasonPhrase());
}
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestSwaggerUtils method parseSwaggerUrlException.
@Test
public void parseSwaggerUrlException(@Mocked URL url) throws IOException {
new Expectations(IOUtils.class) {
{
IOUtils.toString(url, StandardCharsets.UTF_8);
result = new RuntimeExceptionWithoutStackTrace("failed");
}
};
expectedException.expect(ServiceCombException.class);
expectedException.expectMessage("Parse swagger from url failed, ");
SwaggerUtils.parseSwagger(url);
}
Aggregations