Search in sources :

Example 81 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class EffectivePolicyImplTest method doTestInitialisePolicy.

private void doTestInitialisePolicy(boolean requestor) {
    EndpointInfo ei = control.createMock(EndpointInfo.class);
    BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
    PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class);
    BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
    if (requestor) {
        EasyMock.expect(boi.getInput()).andReturn(bmi);
    } else {
        EasyMock.expect(boi.getOutput()).andReturn(bmi);
    }
    EndpointPolicy effectivePolicy = control.createMock(EndpointPolicy.class);
    if (requestor) {
        EasyMock.expect(engine.getClientEndpointPolicy(ei, (Conduit) null, null)).andReturn(effectivePolicy);
    } else {
        EasyMock.expect(engine.getServerEndpointPolicy(ei, (Destination) null, null)).andReturn(effectivePolicy);
    }
    Policy ep = control.createMock(Policy.class);
    EasyMock.expect(effectivePolicy.getPolicy()).andReturn(ep);
    Policy op = control.createMock(Policy.class);
    EasyMock.expect(engine.getAggregatedOperationPolicy(boi, null)).andReturn(op);
    Policy merged = control.createMock(Policy.class);
    EasyMock.expect(ep.merge(op)).andReturn(merged);
    Policy mp = control.createMock(Policy.class);
    EasyMock.expect(engine.getAggregatedMessagePolicy(bmi, null)).andReturn(mp);
    EasyMock.expect(merged.merge(mp)).andReturn(merged);
    EasyMock.expect(merged.normalize(null, true)).andReturn(merged);
    control.replay();
    EffectivePolicyImpl epi = new EffectivePolicyImpl();
    epi.initialisePolicy(ei, boi, engine, requestor, requestor, null, null);
    assertSame(merged, epi.getPolicy());
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Example 82 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class EffectivePolicyImplTest method testAccessors.

@Test
public void testAccessors() {
    EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
    assertNull(effectivePolicy.getPolicy());
    assertNull(effectivePolicy.getChosenAlternative());
    assertNull(effectivePolicy.getInterceptors());
    Policy p = control.createMock(Policy.class);
    Assertion a = control.createMock(Assertion.class);
    List<Assertion> la = Collections.singletonList(a);
    List<Interceptor<? extends Message>> li = createMockInterceptorList();
    control.replay();
    effectivePolicy.setPolicy(p);
    assertSame(p, effectivePolicy.getPolicy());
    effectivePolicy.setChosenAlternative(la);
    assertSame(la, effectivePolicy.getChosenAlternative());
    effectivePolicy.setInterceptors(li);
    assertSame(li, effectivePolicy.getInterceptors());
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 83 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class EndpointPolicyImplTest method testUpdatePolicyWithEmptyExactlyOneAndAll.

@Test
public void testUpdatePolicyWithEmptyExactlyOneAndAll() {
    Policy emptyPolicy = new Policy();
    PolicyOperator exactlyOne = new ExactlyOne();
    exactlyOne.addPolicyComponent(new All());
    exactlyOne.addPolicyComponent(new All());
    emptyPolicy.addPolicyComponent(exactlyOne);
    emptyPolicy.addPolicyComponent(new All());
    emptyPolicy.addPolicyComponent(new All());
    doTestUpdateWithEmptyPolicy(emptyPolicy);
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) PolicyOperator(org.apache.neethi.PolicyOperator) ExactlyOne(org.apache.neethi.ExactlyOne) Test(org.junit.Test)

Example 84 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class EndpointPolicyImplTest method testUpdatePolicy.

@Test
public void testUpdatePolicy() {
    EndpointPolicyImpl epi = new TestEndpointPolicy();
    Policy p1 = new Policy();
    QName aqn1 = new QName("http://x.y.z", "a");
    p1.addAssertion(mockAssertion(aqn1, 5, true));
    Policy p2 = new Policy();
    QName aqn2 = new QName("http://x.y.z", "b");
    p2.addAssertion(mockAssertion(aqn2, 5, true));
    control.replay();
    epi.setPolicy(p1.normalize(null, true));
    Policy ep = epi.updatePolicy(p2, createMessage()).getPolicy();
    List<ExactlyOne> pops = CastUtils.cast(ep.getPolicyComponents(), ExactlyOne.class);
    assertEquals("New policy must have 1 top level policy operator", 1, pops.size());
    List<All> alts = CastUtils.cast(pops.get(0).getPolicyComponents(), All.class);
    assertEquals("2 alternatives should be available", 2, alts.size());
    List<PolicyAssertion> assertions1 = CastUtils.cast(alts.get(0).getAssertions(), PolicyAssertion.class);
    assertEquals("1 assertion should be available", 1, assertions1.size());
    List<PolicyAssertion> assertions2 = CastUtils.cast(alts.get(1).getAssertions(), PolicyAssertion.class);
    assertEquals("1 assertion should be available", 1, assertions2.size());
    QName n1 = assertions1.get(0).getName();
    QName n2 = assertions2.get(0).getName();
    assertTrue("Policy was not merged", n1.equals(aqn1) && n2.equals(aqn2) || n1.equals(aqn2) && n2.equals(aqn1));
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) QName(javax.xml.namespace.QName) ExactlyOne(org.apache.neethi.ExactlyOne) Test(org.junit.Test)

Example 85 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class EndpointPolicyImplTest method testAccessors.

@Test
public void testAccessors() {
    EndpointPolicyImpl epi = new EndpointPolicyImpl();
    Message m = new MessageImpl();
    assertNull(epi.getPolicy());
    assertNull(epi.getChosenAlternative());
    assertNull(epi.getInterceptors(m));
    assertNull(epi.getFaultInterceptors(m));
    Policy p = control.createMock(Policy.class);
    Assertion a = control.createMock(Assertion.class);
    List<Assertion> la = Collections.singletonList(a);
    List<Interceptor<? extends Message>> li = createMockInterceptorList();
    control.replay();
    epi.setPolicy(p);
    assertSame(p, epi.getPolicy());
    epi.setChosenAlternative(la);
    assertSame(la, epi.getChosenAlternative());
    epi.setInterceptors(li);
    assertSame(li, epi.getInterceptors(m));
    epi.setFaultInterceptors(li);
    assertSame(li, epi.getFaultInterceptors(m));
    epi.setVocabulary(la);
    assertSame(la, epi.getVocabulary(m));
    epi.setFaultVocabulary(la);
    assertSame(la, epi.getFaultVocabulary(m));
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) MessageImpl(org.apache.cxf.message.MessageImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Aggregations

Policy (org.apache.neethi.Policy)122 Test (org.junit.Test)47 Assertion (org.apache.neethi.Assertion)27 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)21 All (org.apache.neethi.All)18 ExactlyOne (org.apache.neethi.ExactlyOne)18 Message (org.apache.cxf.message.Message)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 Element (org.w3c.dom.Element)13 Bus (org.apache.cxf.Bus)12 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)12 List (java.util.List)9 Interceptor (org.apache.cxf.interceptor.Interceptor)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 HashMap (java.util.HashMap)7 OMElement (org.apache.axiom.om.OMElement)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 InputStream (java.io.InputStream)5