Search in sources :

Example 1 with PolicyDataEngineImpl

use of org.apache.cxf.ws.policy.PolicyDataEngineImpl in project cxf by apache.

the class PolicyUtilsTest method testAssertPolicyNoop.

void testAssertPolicyNoop(boolean isRequestor) {
    PolicyDataEngine pde = new PolicyDataEngineImpl(null);
    Message message = control.createMock(Message.class);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
    control.replay();
    pde.assertMessage(message, null, new ClientPolicyCalculator());
    control.verify();
    control.reset();
    Collection<PolicyAssertion> as = new ArrayList<>();
    AssertionInfoMap aim = new AssertionInfoMap(as);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
    control.replay();
    if (isRequestor) {
        pde.assertMessage(message, null, new ClientPolicyCalculator());
    } else {
        pde.assertMessage(message, null, new ServerPolicyCalculator());
    }
    control.verify();
}
Also used : PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 2 with PolicyDataEngineImpl

use of org.apache.cxf.ws.policy.PolicyDataEngineImpl in project cxf by apache.

the class PolicyUtilsTest method testAssertServerPolicy.

void testAssertServerPolicy(boolean outbound) {
    Message message = control.createMock(Message.class);
    HTTPServerPolicy ep = new HTTPServerPolicy();
    HTTPServerPolicy mp = new HTTPServerPolicy();
    HTTPServerPolicy cmp = new HTTPServerPolicy();
    cmp.setReceiveTimeout(60000L);
    HTTPServerPolicy icmp = new HTTPServerPolicy();
    icmp.setSuppressClientSendErrors(true);
    AssertionInfo eai = getServerPolicyAssertionInfo(ep);
    AssertionInfo mai = getServerPolicyAssertionInfo(mp);
    AssertionInfo cmai = getServerPolicyAssertionInfo(cmp);
    AssertionInfo icmai = getServerPolicyAssertionInfo(icmp);
    Collection<AssertionInfo> ais = new ArrayList<>();
    ais.add(eai);
    ais.add(mai);
    ais.add(cmai);
    ais.add(icmai);
    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
    aim.put(new ServerPolicyCalculator().getDataClassName(), ais);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).atLeastOnce();
    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();
    new PolicyDataEngineImpl(null).assertMessage(message, ep, new ServerPolicyCalculator());
    assertTrue(eai.isAsserted());
    assertTrue(mai.isAsserted());
    assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());
    assertTrue(outbound ? icmai.isAsserted() : !icmai.isAsserted());
    control.verify();
}
Also used : Exchange(org.apache.cxf.message.Exchange) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 3 with PolicyDataEngineImpl

use of org.apache.cxf.ws.policy.PolicyDataEngineImpl 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();
}
Also used : Exchange(org.apache.cxf.message.Exchange) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ArrayList(java.util.ArrayList) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)

Aggregations

ArrayList (java.util.ArrayList)3 Message (org.apache.cxf.message.Message)3 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)3 PolicyAssertion (org.apache.cxf.ws.policy.PolicyAssertion)3 PolicyDataEngineImpl (org.apache.cxf.ws.policy.PolicyDataEngineImpl)3 Exchange (org.apache.cxf.message.Exchange)2 PolicyDataEngine (org.apache.cxf.policy.PolicyDataEngine)2 ClientPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)2 ServerPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator)2 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)2 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)1 HTTPServerPolicy (org.apache.cxf.transports.http.configuration.HTTPServerPolicy)1