use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestSwaggerUtils method swaggerToStringException.
@Test
public void swaggerToStringException(@Mocked Swagger swagger) {
new Expectations() {
{
swagger.getBasePath();
result = new RuntimeExceptionWithoutStackTrace();
}
};
expectedException.expect(ServiceCombException.class);
expectedException.expectMessage("Convert swagger to string failed, ");
SwaggerUtils.swaggerToString(swagger);
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method sendResponseQuietlyException.
@Test
public void sendResponseQuietlyException(@Mocked Response response) {
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void doInvoke() {
}
@Override
protected void sendResponse(Response response) {
throw new RuntimeExceptionWithoutStackTrace();
}
};
initRestInvocation();
restInvocation.sendResponseQuietly(response);
// just log, check nothing
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method should_ignore_content_length_and_transfer_encoding_when_copy_header_to_http_response.
@Test
public void should_ignore_content_length_and_transfer_encoding_when_copy_header_to_http_response(@Mocked Response response) {
MultiMap headers = MultiMap.caseInsensitiveMultiMap().set(CONTENT_LENGTH, "10").set(TRANSFER_ENCODING, "encoding");
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();
restInvocation.sendResponse(response);
assertThat(headers).isEmpty();
assertThat(resultHeaders).isEmpty();
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method scheduleInvocationException.
@Test
public void scheduleInvocationException(@Mocked OperationMeta operationMeta) {
Executor executor = new ReactiveExecutor();
requestEx = new AbstractHttpServletRequestForTest();
requestEx.setAttribute(RestConst.REST_REQUEST, requestEx);
new Expectations() {
{
restOperation.getOperationMeta();
result = operationMeta;
operationMeta.getExecutor();
result = executor;
}
};
Holder<Throwable> result = new Holder<>();
RuntimeException error = new RuntimeExceptionWithoutStackTrace("run on executor");
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void runOnExecutor() {
throw error;
}
@Override
public void sendFailResponse(Throwable throwable) {
result.value = throwable;
invocation.onFinish(Response.ok(null));
}
};
restInvocation.requestEx = requestEx;
restInvocation.restOperationMeta = restOperation;
restInvocation.scheduleInvocation();
Assert.assertSame(error, result.value);
}
use of org.apache.servicecomb.foundation.test.scaffolding.exception.RuntimeExceptionWithoutStackTrace in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method invokeFilterException.
@Test
public void invokeFilterException(@Mocked HttpServerFilter filter) {
Exception error = new RuntimeExceptionWithoutStackTrace();
new Expectations() {
{
filter.enabled();
result = true;
filter.afterReceiveRequest(invocation, requestEx);
result = error;
}
};
Holder<Throwable> result = new Holder<>();
restInvocation = new AbstractRestInvocationForTest() {
@Override
public void sendFailResponse(Throwable throwable) {
result.value = throwable;
}
@Override
protected void doInvoke() {
}
};
initRestInvocation();
restInvocation.httpServerFilters = Arrays.asList(filter);
restInvocation.invoke();
Assert.assertSame(error, result.value);
}
Aggregations