Search in sources :

Example 1 with AlternativeSelector

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

the class MinimalMaximalAlternativeSelectorTest method testChooseMaxAlternative.

@Test
public void testChooseMaxAlternative() {
    Message m = new MessageImpl();
    AlternativeSelector selector = new MaximalAlternativeSelector();
    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(1, choice.size());
    assertSame(a1, choice.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 2 with AlternativeSelector

use of org.apache.cxf.ws.policy.AlternativeSelector 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 3 with AlternativeSelector

use of org.apache.cxf.ws.policy.AlternativeSelector 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 4 with AlternativeSelector

use of org.apache.cxf.ws.policy.AlternativeSelector in project jbossws-cxf by jbossws.

the class BusHolder method getAlternativeSelector.

private static AlternativeSelector getAlternativeSelector(Map<String, String> props) {
    // default to MaximalAlternativeSelector on server side [JBWS-3149]
    AlternativeSelector selector = new MaximalAlternativeSelector();
    if (props != null && !props.isEmpty()) {
        String className = props.get(Constants.CXF_POLICY_ALTERNATIVE_SELECTOR_PROP);
        if (className != null) {
            try {
                Class<?> clazz = Class.forName(className);
                selector = (AlternativeSelector) clazz.newInstance();
            } catch (Exception e) {
            }
        }
    }
    return selector;
}
Also used : MaximalAlternativeSelector(org.apache.cxf.ws.policy.selector.MaximalAlternativeSelector) AlternativeSelector(org.apache.cxf.ws.policy.AlternativeSelector) MaximalAlternativeSelector(org.apache.cxf.ws.policy.selector.MaximalAlternativeSelector) WSFException(org.jboss.wsf.spi.WSFException)

Aggregations

AlternativeSelector (org.apache.cxf.ws.policy.AlternativeSelector)4 Message (org.apache.cxf.message.Message)3 MessageImpl (org.apache.cxf.message.MessageImpl)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 All (org.apache.neethi.All)3 Assertion (org.apache.neethi.Assertion)3 ExactlyOne (org.apache.neethi.ExactlyOne)3 Policy (org.apache.neethi.Policy)3 Test (org.junit.Test)3 MaximalAlternativeSelector (org.apache.cxf.ws.policy.selector.MaximalAlternativeSelector)1 WSFException (org.jboss.wsf.spi.WSFException)1