use of org.apache.cxf.ws.policy.PolicyAssertion 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();
}
use of org.apache.cxf.ws.policy.PolicyAssertion in project cxf by apache.
the class PolicyUtilsTest method testAssertPolicyNoop.
void testAssertPolicyNoop(boolean isRequestor) {
PolicyDataEngine pde = new PolicyDataEngineImpl(null);
Message message = control.createMock(Message.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
control.replay();
pde.assertMessage(message, null, new ClientPolicyCalculator());
control.verify();
control.reset();
Collection<PolicyAssertion> as = new ArrayList<>();
AssertionInfoMap aim = new AssertionInfoMap(as);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
control.replay();
if (isRequestor) {
pde.assertMessage(message, null, new ClientPolicyCalculator());
} else {
pde.assertMessage(message, null, new ServerPolicyCalculator());
}
control.verify();
}
use of org.apache.cxf.ws.policy.PolicyAssertion 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();
}
use of org.apache.cxf.ws.policy.PolicyAssertion 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();
}
use of org.apache.cxf.ws.policy.PolicyAssertion in project cxf by apache.
the class AbstractRMInterceptorTest method testAssertReliability.
@Test
public void testAssertReliability() {
RMInterceptor interceptor = new RMInterceptor();
Message message = control.createMock(Message.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
AssertionInfoMap aim = control.createMock(AssertionInfoMap.class);
Collection<AssertionInfo> ais = new ArrayList<>();
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).times(2);
PolicyAssertion a = control.createMock(PolicyAssertion.class);
AssertionInfo ai = new AssertionInfo(a);
EasyMock.expectLastCall();
control.replay();
interceptor.assertReliability(message);
assertTrue(!ai.isAsserted());
aim.put(RM10Constants.RMASSERTION_QNAME, ais);
interceptor.assertReliability(message);
assertTrue(!ai.isAsserted());
ais.add(ai);
interceptor.assertReliability(message);
}
Aggregations