Search in sources :

Example 51 with Assertion

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

the class EffectivePolicyImplTest method testChooseAlternative.

@Test
public void testChooseAlternative() {
    Message m = new MessageImpl();
    EffectivePolicyImpl epi = new EffectivePolicyImpl();
    Policy policy = new Policy();
    epi.setPolicy(policy);
    PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class);
    Assertor assertor = control.createMock(Assertor.class);
    AlternativeSelector selector = control.createMock(AlternativeSelector.class);
    EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
    EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null, m)).andReturn(null);
    control.replay();
    try {
        epi.chooseAlternative(engine, assertor, m);
        fail("Expected PolicyException not thrown.");
    } catch (PolicyException ex) {
    // expected
    }
    control.verify();
    control.reset();
    EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
    Collection<Assertion> alternative = new ArrayList<>();
    EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null, m)).andReturn(alternative);
    control.replay();
    epi.chooseAlternative(engine, assertor, m);
    Collection<Assertion> choice = epi.getChosenAlternative();
    assertSame(choice, alternative);
    control.verify();
}
Also used : Policy(org.apache.neethi.Policy) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 52 with Assertion

use of org.apache.neethi.Assertion 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 53 with Assertion

use of org.apache.neethi.Assertion 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 54 with Assertion

use of org.apache.neethi.Assertion 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 55 with Assertion

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

the class PolicyInterceptorsTest method testServerPolicyOutInterceptor.

@Test
public void testServerPolicyOutInterceptor() {
    PolicyOutInterceptor interceptor = new PolicyOutInterceptor();
    doTestBasics(interceptor, false, true);
    control.reset();
    setupMessage(false, false, true, true, true, true);
    EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
    EasyMock.expect(pe.getEffectiveServerResponsePolicy(ei, boi, destination, null, message)).andReturn(effectivePolicy);
    List<Interceptor<? extends Message>> li = createMockInterceptorList();
    EasyMock.expect(effectivePolicy.getInterceptors()).andReturn(li);
    InterceptorChain ic = control.createMock(InterceptorChain.class);
    EasyMock.expect(message.getInterceptorChain()).andReturn(ic);
    ic.add(li.get(0));
    EasyMock.expectLastCall();
    Collection<Assertion> assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class);
    EasyMock.expect(effectivePolicy.getChosenAlternative()).andReturn(assertions);
    control.replay();
    interceptor.handleMessage(message);
    control.verify();
}
Also used : InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Aggregations

Assertion (org.apache.neethi.Assertion)64 Policy (org.apache.neethi.Policy)27 Message (org.apache.cxf.message.Message)25 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)21 Interceptor (org.apache.cxf.interceptor.Interceptor)19 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)19 PolicyContainingAssertion (org.apache.neethi.PolicyContainingAssertion)9 Element (org.w3c.dom.Element)9 MessageImpl (org.apache.cxf.message.MessageImpl)7 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 All (org.apache.neethi.All)7 ExactlyOne (org.apache.neethi.ExactlyOne)7 Bus (org.apache.cxf.Bus)6 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)6 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)6 PolicyContainingPrimitiveAssertion (org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)6 XMLPrimitiveAssertionBuilder (org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)6 List (java.util.List)5