Search in sources :

Example 16 with All

use of org.apache.neethi.All 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 17 with All

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

the class EndpointPolicyImplTest method doTestUpdateWithEmptyPolicy.

private void doTestUpdateWithEmptyPolicy(Policy emptyPolicy) {
    Policy p1 = new Policy();
    QName aqn1 = new QName("http://x.y.z", "a");
    p1.addAssertion(mockAssertion(aqn1, 5, true));
    EndpointPolicyImpl epi = new TestEndpointPolicy();
    control.replay();
    epi.setPolicy(p1.normalize(true));
    Policy ep = epi.updatePolicy(emptyPolicy, 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("1 alternatives should be available", 1, alts.size());
    List<PolicyAssertion> assertions1 = CastUtils.cast(alts.get(0).getAssertions(), PolicyAssertion.class);
    assertEquals("1 assertion should be available", 1, assertions1.size());
    QName n1 = assertions1.get(0).getName();
    assertTrue("Policy was not merged", n1.equals(aqn1));
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) QName(javax.xml.namespace.QName) ExactlyOne(org.apache.neethi.ExactlyOne)

Example 18 with All

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

the class EndpointPolicyImplTest method testUpdatePolicyWithEmptyAll.

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

Aggregations

All (org.apache.neethi.All)18 Policy (org.apache.neethi.Policy)18 ExactlyOne (org.apache.neethi.ExactlyOne)17 Test (org.junit.Test)10 Assertion (org.apache.neethi.Assertion)7 QName (javax.xml.namespace.QName)6 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)6 Message (org.apache.cxf.message.Message)3 MessageImpl (org.apache.cxf.message.MessageImpl)3 AlternativeSelector (org.apache.cxf.ws.policy.AlternativeSelector)3 Assertor (org.apache.cxf.ws.policy.Assertor)3 PolicyAssertion (org.apache.cxf.ws.policy.PolicyAssertion)3 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)3 TestAssertion (org.apache.cxf.ws.policy.TestAssertion)3 AlgorithmSuite (org.apache.wss4j.policy.model.AlgorithmSuite)3 ProtectionToken (org.apache.wss4j.policy.model.ProtectionToken)3 SignedParts (org.apache.wss4j.policy.model.SignedParts)3 ArrayList (java.util.ArrayList)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 DOMSource (javax.xml.transform.dom.DOMSource)2