Search in sources :

Example 16 with ExactlyOne

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

the class JaxbAssertionTest method testEqual.

@Test
public void testEqual() {
    JaxbAssertion<FooType> assertion = new JaxbAssertion<FooType>();
    FooType data = new FooType();
    data.setName("CXF");
    data.setNumber(2);
    QName qn = new QName("http://cxf.apache.org/test/assertions/foo", "FooType");
    assertion.setName(qn);
    assertion.setData(data);
    PolicyComponent pc = new Policy();
    assertTrue(!assertion.equal(pc));
    pc = new All();
    assertTrue(!assertion.equal(pc));
    pc = new ExactlyOne();
    assertTrue(!assertion.equal(pc));
    IMocksControl ctrl = EasyMock.createNiceControl();
    PrimitiveAssertion xpa = ctrl.createMock(PrimitiveAssertion.class);
    QName oqn = new QName("http://cxf.apache.org/test/assertions/blah", "OtherType");
    EasyMock.expect(xpa.getName()).andReturn(oqn);
    EasyMock.expect(xpa.getType()).andReturn(Constants.TYPE_ASSERTION);
    ctrl.replay();
    assertTrue(!assertion.equal(xpa));
    ctrl.verify();
    FooType odata = new FooType();
    odata.setName(data.getName());
    odata.setNumber(data.getNumber());
    JaxbAssertion<FooType> oassertion = new JaxbAssertion<FooType>();
    oassertion.setData(odata);
    oassertion.setName(qn);
    assertTrue(!assertion.equal(oassertion));
    oassertion.setData(data);
    assertTrue(assertion.equal(oassertion));
    assertTrue(assertion.equal(assertion));
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) IMocksControl(org.easymock.IMocksControl) FooType(org.apache.cxf.test.assertions.foo.FooType) PolicyComponent(org.apache.neethi.PolicyComponent) QName(javax.xml.namespace.QName) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) ExactlyOne(org.apache.neethi.ExactlyOne) Test(org.junit.Test)

Example 17 with ExactlyOne

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

the class FirstAlternativeSelectorTest method testChooseAlternative.

@Test
public void testChooseAlternative() {
    AlternativeSelector selector = new FirstAlternativeSelector();
    PolicyEngine engine = control.createMock(PolicyEngine.class);
    Assertor assertor = control.createMock(Assertor.class);
    Policy policy = new Policy();
    ExactlyOne ea = new ExactlyOne();
    All all = new All();
    PolicyAssertion a1 = new TestAssertion();
    all.addAssertion(a1);
    ea.addPolicyComponent(all);
    Collection<PolicyAssertion> firstAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
    policy.addPolicyComponent(ea);
    Message m = new MessageImpl();
    EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false);
    control.replay();
    assertNull(selector.selectAlternative(policy, engine, assertor, null, m));
    control.verify();
    control.reset();
    EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(true);
    control.replay();
    Collection<Assertion> chosen = selector.selectAlternative(policy, engine, assertor, null, m);
    assertSame(1, chosen.size());
    assertSame(chosen.size(), firstAlternative.size());
    assertSame(chosen.iterator().next(), firstAlternative.iterator().next());
    control.verify();
    control.reset();
    All other = new All();
    other.addAssertion(a1);
    ea.addPolicyComponent(other);
    Collection<PolicyAssertion> secondAlternative = CastUtils.cast(other.getPolicyComponents(), PolicyAssertion.class);
    EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false);
    EasyMock.expect(engine.supportsAlternative(secondAlternative, assertor, m)).andReturn(true);
    control.replay();
    chosen = selector.selectAlternative(policy, engine, assertor, null, m);
    assertSame(1, chosen.size());
    assertSame(chosen.size(), secondAlternative.size());
    assertSame(chosen.iterator().next(), secondAlternative.iterator().next());
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) TestAssertion(org.apache.cxf.ws.policy.TestAssertion) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) ExactlyOne(org.apache.neethi.ExactlyOne) AlternativeSelector(org.apache.cxf.ws.policy.AlternativeSelector) Assertor(org.apache.cxf.ws.policy.Assertor) TestAssertion(org.apache.cxf.ws.policy.TestAssertion) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 18 with ExactlyOne

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

the class MinimalMaximalAlternativeSelectorTest method testChooseMinAlternative.

@Test
public void testChooseMinAlternative() {
    Message m = new MessageImpl();
    AlternativeSelector selector = new MinimalAlternativeSelector();
    PolicyEngine engine = control.createMock(PolicyEngine.class);
    Assertor assertor = control.createMock(Assertor.class);
    Policy policy = new Policy();
    ExactlyOne ea = new ExactlyOne();
    All all = new All();
    PolicyAssertion a1 = new TestAssertion();
    all.addAssertion(a1);
    ea.addPolicyComponent(all);
    Collection<PolicyAssertion> maxAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
    all = new All();
    ea.addPolicyComponent(all);
    Collection<PolicyAssertion> minAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
    policy.addPolicyComponent(ea);
    EasyMock.expect(engine.supportsAlternative(maxAlternative, assertor, m)).andReturn(true);
    EasyMock.expect(engine.supportsAlternative(minAlternative, assertor, m)).andReturn(true);
    control.replay();
    Collection<Assertion> choice = selector.selectAlternative(policy, engine, assertor, null, m);
    assertEquals(0, choice.size());
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) TestAssertion(org.apache.cxf.ws.policy.TestAssertion) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) ExactlyOne(org.apache.neethi.ExactlyOne) AlternativeSelector(org.apache.cxf.ws.policy.AlternativeSelector) Assertor(org.apache.cxf.ws.policy.Assertor) TestAssertion(org.apache.cxf.ws.policy.TestAssertion) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 19 with ExactlyOne

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

the class EndpointPolicyImpl method checkExactlyOnes.

void checkExactlyOnes() {
    // Policy has been normalized and merged by now but unfortunately
    // ExactlyOnce have not been normalized properly by Neethi, for ex
    // <Policy>
    // <ExactlyOne><All><A></All></ExactlyOne>
    // <ExactlyOne><All><B></All></ExactlyOne>
    // </Policy>
    // this is what we can see after the normalization happens but in fact this
    // is still unnormalized expression, should be
    // <Policy>
    // <ExactlyOne><All><A></All><All><B></All></ExactlyOne>
    // </Policy>
    List<?> assertions = policy.getPolicyComponents();
    if (assertions.size() <= 1) {
        return;
    }
    Policy p = new Policy();
    ExactlyOne alternatives = new ExactlyOne();
    p.addPolicyComponent(alternatives);
    for (Object a : assertions) {
        alternatives.addPolicyComponents(((ExactlyOne) a).getPolicyComponents());
    }
    setPolicy(p);
}
Also used : Policy(org.apache.neethi.Policy) ExactlyOne(org.apache.neethi.ExactlyOne)

Aggregations

ExactlyOne (org.apache.neethi.ExactlyOne)19 All (org.apache.neethi.All)18 Policy (org.apache.neethi.Policy)18 Test (org.junit.Test)9 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