use of org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method testDoSendResponseResultOKFilter.
@Test
public void testDoSendResponseResultOKFilter(@Mocked Response response) {
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
headers.set("Content-Type", "application/json");
new Expectations() {
{
response.getHeaders();
result = headers;
response.getStatusCode();
result = 123;
response.getReasonPhrase();
result = "reason";
response.getResult();
result = "ok";
}
};
Buffer buffer = Buffer.buffer();
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 setBodyBuffer(Buffer bodyBuffer) {
buffer.appendBuffer(bodyBuffer);
}
}.getMockInstance();
HttpServerFilter filter = new HttpServerFilterBaseForTest() {
@Override
public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
buffer.appendString("-filter");
}
};
invocation.onStart(0);
initRestInvocation();
List<HttpServerFilter> httpServerFilters = SPIServiceUtils.loadSortedService(HttpServerFilter.class);
httpServerFilters.add(filter);
restInvocation.setHttpServerFilters(httpServerFilters);
restInvocation.sendResponse(response);
assertEquals("\"ok\"-filter", buffer.toString());
}
use of org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method testDoSendResponseResultOKFilter.
@Test
public void testDoSendResponseResultOKFilter(@Mocked Response response) {
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
headers.set("Content-Type", "application/json");
new Expectations() {
{
response.getHeaders();
result = headers;
response.getStatusCode();
result = 123;
response.getReasonPhrase();
result = "reason";
response.getResult();
result = "ok";
}
};
Buffer buffer = Buffer.buffer();
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 setBodyBuffer(Buffer bodyBuffer) {
buffer.appendBuffer(bodyBuffer);
}
}.getMockInstance();
HttpServerFilter filter = new HttpServerFilterBaseForTest() {
@Override
public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
buffer.appendString("-filter");
}
};
invocation.onStart(0);
initRestInvocation();
List<HttpServerFilter> httpServerFilters = SPIServiceUtils.loadSortedService(HttpServerFilter.class);
httpServerFilters.add(filter);
restInvocation.setHttpServerFilters(httpServerFilters);
restInvocation.sendResponse(response);
assertEquals("\"ok\"-filter", buffer.toString());
}
use of org.apache.servicecomb.common.rest.filter.HttpServerFilterBaseForTest in project servicecomb-java-chassis by apache.
the class TestAbstractRestInvocation method testDoSendResponseResultOKFilter.
@Test
public void testDoSendResponseResultOKFilter(@Mocked Response response) {
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
headers.set("Content-Type", "application/json");
new Expectations() {
{
response.getHeaders();
result = headers;
response.getStatusCode();
result = 123;
response.getReasonPhrase();
result = "reason";
response.getResult();
result = "ok";
}
};
Buffer buffer = Buffer.buffer();
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 setBodyBuffer(Buffer bodyBuffer) {
buffer.appendBuffer(bodyBuffer);
}
}.getMockInstance();
HttpServerFilter filter = new HttpServerFilterBaseForTest() {
@Override
public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
buffer.appendString("-filter");
}
};
invocation.onStart(0);
initRestInvocation();
List<HttpServerFilter> httpServerFilters = SPIServiceUtils.loadSortedService(HttpServerFilter.class);
httpServerFilters.add(filter);
restInvocation.setHttpServerFilters(httpServerFilters);
restInvocation.sendResponse(response);
assertEquals("\"ok\"-filter", buffer.toString());
}
Aggregations