use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class HTTPConduitTest method testHandleResponseOnWorkqueueAllowCurrentThread.
@Test
public void testHandleResponseOnWorkqueueAllowCurrentThread() throws Exception {
Message m = getNewMessage();
Exchange exchange = new ExchangeImpl();
Bus bus = new ExtensionManagerBus();
exchange.put(Bus.class, bus);
EndpointInfo endpointInfo = new EndpointInfo();
Endpoint endpoint = new EndpointImpl(null, null, endpointInfo);
exchange.put(Endpoint.class, endpoint);
m.setExchange(exchange);
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAsyncExecuteTimeoutRejection(true);
m.put(HTTPClientPolicy.class, policy);
exchange.put(Executor.class, new Executor() {
@Override
public void execute(Runnable command) {
// forces us to use current thread
throw new RejectedExecutionException("expected");
}
});
HTTPConduit conduit = new MockHTTPConduit(bus, endpointInfo, policy);
OutputStream os = conduit.createOutputStream(m, false, false, 0);
assertTrue(os instanceof WrappedOutputStream);
WrappedOutputStream wos = (WrappedOutputStream) os;
try {
wos.handleResponseOnWorkqueue(true, false);
assertEquals(Thread.currentThread(), m.get(Thread.class));
try {
wos.handleResponseOnWorkqueue(false, false);
fail("Expected RejectedExecutionException not thrown");
} catch (RejectedExecutionException ex) {
assertEquals("expected", ex.getMessage());
}
} catch (Exception ex) {
throw ex;
}
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class PolicyUtilsTest method testAssertClientPolicy.
void testAssertClientPolicy(boolean outbound) {
Message message = control.createMock(Message.class);
HTTPClientPolicy ep = new HTTPClientPolicy();
HTTPClientPolicy cmp = new HTTPClientPolicy();
cmp.setConnectionTimeout(60000L);
HTTPClientPolicy icmp = new HTTPClientPolicy();
icmp.setAllowChunking(false);
AssertionInfo eai = getClientPolicyAssertionInfo(ep);
AssertionInfo cmai = getClientPolicyAssertionInfo(cmp);
AssertionInfo icmai = getClientPolicyAssertionInfo(icmp);
AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
Collection<AssertionInfo> ais = new ArrayList<>();
ais.add(eai);
ais.add(cmai);
ais.add(icmai);
aim.put(new ClientPolicyCalculator().getDataClassName(), ais);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
Exchange ex = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
if (!outbound) {
EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
}
control.replay();
PolicyDataEngine pde = new PolicyDataEngineImpl(null);
pde.assertMessage(message, ep, new ClientPolicyCalculator());
assertTrue(eai.isAsserted());
assertTrue(cmai.isAsserted());
assertTrue(icmai.isAsserted());
control.verify();
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class HTTPClientAssertionBuilderTest method testHTTPCLientPolicyAssertionEqual.
@Test
public void testHTTPCLientPolicyAssertionEqual() throws Exception {
HTTPClientAssertionBuilder ab = new HTTPClientAssertionBuilder();
JaxbAssertion<HTTPClientPolicy> a = ab.buildAssertion();
a.setData(new HTTPClientPolicy());
assertTrue(a.equal(a));
JaxbAssertion<HTTPClientPolicy> b = ab.buildAssertion();
b.setData(new HTTPClientPolicy());
assertTrue(a.equal(b));
HTTPClientPolicy pa = new HTTPClientPolicy();
a.setData(pa);
assertTrue(a.equal(a));
HTTPClientPolicy pb = new HTTPClientPolicy();
b.setData(pb);
assertTrue(a.equal(b));
pa.setDecoupledEndpoint("http://localhost:9999/decoupled_endpoint");
assertFalse(a.equal(b));
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class ClientPolicyCalculatorTest method testEqualClientPolicies.
@Test
public void testEqualClientPolicies() {
ClientPolicyCalculator calc = new ClientPolicyCalculator();
HTTPClientPolicy p1 = new HTTPClientPolicy();
assertTrue(calc.equals(p1, p1));
HTTPClientPolicy p2 = new HTTPClientPolicy();
assertTrue(calc.equals(p1, p2));
p1.setDecoupledEndpoint("http://localhost:8080/decoupled");
assertFalse(calc.equals(p1, p2));
p2.setDecoupledEndpoint("http://localhost:8080/decoupled");
assertTrue(calc.equals(p1, p2));
p1.setReceiveTimeout(10000L);
assertFalse(calc.equals(p1, p2));
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class ClientPolicyCalculatorTest method testIntersectClientPolicies.
@Test
public void testIntersectClientPolicies() {
ThreadLocalRandom random = ThreadLocalRandom.current();
ClientPolicyCalculator calc = new ClientPolicyCalculator();
HTTPClientPolicy p1 = new HTTPClientPolicy();
HTTPClientPolicy p2 = new HTTPClientPolicy();
p1.setBrowserType("browser");
HTTPClientPolicy p = calc.intersect(p1, p2);
assertEquals("browser", p.getBrowserType());
p1.setBrowserType(null);
long connectionRequestTimeout = random.nextLong(0, 10000);
p1.setConnectionRequestTimeout(connectionRequestTimeout);
p = calc.intersect(p1, p2);
assertEquals(connectionRequestTimeout, p.getConnectionRequestTimeout());
long receiveTimeout = random.nextLong(0, 10000);
p1.setReceiveTimeout(receiveTimeout);
p = calc.intersect(p1, p2);
assertEquals(receiveTimeout, p.getReceiveTimeout());
long connectionTimeout = random.nextLong(0, 10000);
p1.setConnectionTimeout(connectionTimeout);
p = calc.intersect(p1, p2);
assertEquals(connectionTimeout, p.getConnectionTimeout());
p1.setAllowChunking(false);
p2.setAllowChunking(false);
p = calc.intersect(p1, p2);
assertFalse(p.isAllowChunking());
}
Aggregations