use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.
the class AssertionInfoMapTest method testCheck.
@Test
public void testCheck() throws PolicyException {
QName aqn = new QName("http://x.y.z", "a");
Assertion a = new PrimitiveAssertion(aqn);
Collection<Assertion> assertions = new ArrayList<>();
assertions.add(a);
AssertionInfoMap aim = new AssertionInfoMap(assertions);
try {
aim.check();
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
assertEquals("NOT_ASSERTED_EXC", ex.getCode());
}
aim.get(aqn).iterator().next().setAsserted(true);
aim.check();
}
use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.
the class AssertionInfoMapTest method testAllAssertionsIn.
@Test
public void testAllAssertionsIn() {
Policy nested = new Policy();
Assertion nb = new PrimitiveAssertion(new QName("http://x.y.z", "b"));
nested.addAssertion(nb);
Policy p = new Policy();
Assertion a1 = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
Assertion a2 = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
Assertion b = new PrimitiveAssertion(new QName("http://x.y.z", "b"));
Assertion c = new PolicyContainingPrimitiveAssertion(new QName("http://x.y.z", "c"), false, false, nested);
All alt1 = new All();
alt1.addAssertion(a1);
alt1.addAssertion(b);
All alt2 = new All();
alt1.addAssertion(a2);
alt2.addAssertion(c);
ExactlyOne ea = new ExactlyOne();
ea.addPolicyComponent(alt1);
ea.addPolicyComponent(alt2);
p.addPolicyComponent(ea);
AssertionInfoMap aim = new AssertionInfoMap(p);
Collection<AssertionInfo> listA = aim.getAssertionInfo(new QName("http://x.y.z", "a"));
assertEquals("2 A assertions should've been added", 2, listA.size());
AssertionInfo[] ais = listA.toArray(new AssertionInfo[] {});
assertTrue("Two different A instances should be added", ais[0].getAssertion() == a1 && ais[1].getAssertion() == a2 || ais[0].getAssertion() == a2 && ais[1].getAssertion() == a1);
Collection<AssertionInfo> listB = aim.getAssertionInfo(new QName("http://x.y.z", "b"));
assertEquals("2 B assertions should've been added", 2, listB.size());
ais = listB.toArray(new AssertionInfo[] {});
assertTrue("Two different B instances should be added", ais[0].getAssertion() == nb && ais[1].getAssertion() == b || ais[0].getAssertion() == b && ais[1].getAssertion() == nb);
Collection<AssertionInfo> listC = aim.getAssertionInfo(new QName("http://x.y.z", "c"));
assertEquals("1 C assertion should've been added", 1, listC.size());
ais = listC.toArray(new AssertionInfo[] {});
assertSame("One C instances should be added", ais[0].getAssertion(), c);
}
use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.
the class IgnorablePolicyInterceptorProviderTest method createTestAssertions.
private AssertionInfoMap createTestAssertions() {
AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
Assertion a = new PrimitiveAssertion(ONEWAY_QNAME);
Assertion b = new PrimitiveAssertion(DUPLEX_QNAME);
AssertionInfo ai = new AssertionInfo(a);
AssertionInfo bi = new AssertionInfo(b);
aim.put(ONEWAY_QNAME, Collections.singleton(ai));
aim.put(DUPLEX_QNAME, Collections.singleton(bi));
return aim;
}
use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.
the class PolicyEngineTest method testAddAssertions.
@Test
public void testAddAssertions() {
engine = new PolicyEngineImpl();
Collection<Assertion> assertions = new ArrayList<>();
Assertion a = control.createMock(Assertion.class);
EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
EasyMock.expect(a.isOptional()).andReturn(true);
control.replay();
engine.addAssertions(a, false, assertions);
assertTrue(assertions.isEmpty());
control.verify();
control.reset();
EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
control.replay();
engine.addAssertions(a, true, assertions);
assertEquals(1, assertions.size());
assertSame(a, assertions.iterator().next());
control.verify();
assertions.clear();
Policy p = new Policy();
a = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
p.addAssertion(a);
// id has no #
engine.getRegistry().register("ab", p);
// local reference is an id + #
PolicyReference pr = new PolicyReference();
pr.setURI("#ab");
engine.addAssertions(pr, false, assertions);
assertEquals(1, assertions.size());
assertSame(a, assertions.iterator().next());
}
use of org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion in project cxf by apache.
the class MC11AssertionBuilder method build.
/**
* @see org.apache.neethi.builders.AssertionBuilder#build(org.w3c.dom.Element,
* org.apache.neethi.AssertionBuilderFactory)
*/
public Assertion build(Element elem, AssertionBuilderFactory factory) throws IllegalArgumentException {
Assertion assertion = null;
if (WSMC_NAMESPACE.equals(elem.getNamespaceURI()) && MCSUPPORTED_NAME.equals(elem.getLocalName())) {
boolean optional = XMLPrimitiveAssertionBuilder.isOptional(elem);
assertion = new PrimitiveAssertion(MCSUPPORTED_QNAME, optional);
}
return assertion;
}
Aggregations