use of org.apache.cxf.io.AbstractThresholdOutputStream in project cxf by apache.
the class HTTPConduitURLEasyMockTest method verifyRequestHeaders.
private OutputStream verifyRequestHeaders(Message message, boolean expectHeaders, String method) throws IOException {
Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
assertNotNull("expected request headers set", headers);
assertTrue("expected output stream format", message.getContentFormats().contains(OutputStream.class));
connection.getRequestMethod();
EasyMock.expectLastCall().andReturn(method).anyTimes();
if (!"GET".equals(method)) {
os = EasyMock.createMock(OutputStream.class);
connection.getOutputStream();
EasyMock.expectLastCall().andReturn(os);
}
message.put(HTTPConduit.KEY_HTTP_CONNECTION, connection);
if (expectHeaders) {
connection.setRequestProperty(EasyMock.eq("Authorization"), EasyMock.eq("Basic Qko6dmFsdWU="));
EasyMock.expectLastCall();
connection.setRequestProperty(EasyMock.eq("Content-Type"), EasyMock.eq("text/xml;charset=utf8"));
EasyMock.expectLastCall();
connection.setRequestProperty(EasyMock.eq("Accept"), EasyMock.eq("text/xml;charset=utf8,text/plain"));
EasyMock.expectLastCall();
}
connection.getRequestProperties();
EasyMock.expectLastCall().andReturn(new HashMap<String, List<String>>()).anyTimes();
control.replay();
AbstractThresholdOutputStream wrappedOS = (AbstractThresholdOutputStream) message.getContent(OutputStream.class);
assertNotNull("expected output stream", wrappedOS);
wrappedOS.write(PAYLOAD.getBytes());
wrappedOS.unBuffer();
control.verify();
control.reset();
return wrappedOS;
}
Aggregations