use of org.apache.neethi.Assertion in project cxf by apache.
the class PolicyInterceptorProviderRegistryImpl method getInterceptorsForAlternative.
public List<Interceptor<? extends Message>> getInterceptorsForAlternative(Collection<? extends Assertion> alternative, boolean out, boolean fault) {
List<Interceptor<? extends Message>> interceptors = new ArrayList<>();
for (Assertion a : alternative) {
if (a.isOptional()) {
continue;
}
QName qn = a.getName();
interceptors.addAll(getInterceptorsForAssertion(qn, out, fault));
}
return interceptors;
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class EndpointPolicyImplTest method testAccessors.
@Test
public void testAccessors() {
EndpointPolicyImpl epi = new EndpointPolicyImpl();
Message m = new MessageImpl();
assertNull(epi.getPolicy());
assertNull(epi.getChosenAlternative());
assertNull(epi.getInterceptors(m));
assertNull(epi.getFaultInterceptors(m));
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();
epi.setPolicy(p);
assertSame(p, epi.getPolicy());
epi.setChosenAlternative(la);
assertSame(la, epi.getChosenAlternative());
epi.setInterceptors(li);
assertSame(li, epi.getInterceptors(m));
epi.setFaultInterceptors(li);
assertSame(li, epi.getFaultInterceptors(m));
epi.setVocabulary(la);
assertSame(la, epi.getVocabulary(m));
epi.setFaultVocabulary(la);
assertSame(la, epi.getFaultVocabulary(m));
control.verify();
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class EndpointPolicyImplTest method doTestInitializeInterceptors.
private void doTestInitializeInterceptors(boolean requestor) {
EndpointInfo ei = control.createMock(EndpointInfo.class);
PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class);
EndpointPolicyImpl epi = new EndpointPolicyImpl(ei, engine, requestor, null);
Collection<Assertion> v = new ArrayList<>();
Collection<Assertion> fv = new ArrayList<>();
QName aqn = new QName("http://x.y.z", "a");
v.add(mockAssertion(aqn, requestor ? 2 : 1, false));
v.add(mockAssertion(aqn, requestor ? 2 : 1, false));
fv.addAll(v);
epi.setVocabulary(v);
epi.setChosenAlternative(v);
epi.setFaultVocabulary(fv);
PolicyInterceptorProviderRegistry reg = control.createMock(PolicyInterceptorProviderRegistry.class);
setupPolicyInterceptorProviderRegistry(engine, reg);
List<Interceptor<? extends Message>> li = createMockInterceptorList();
Interceptor<? extends Message> api = li.get(0);
EasyMock.expect(reg.getInInterceptorsForAssertion(aqn)).andReturn(li).anyTimes();
if (requestor) {
EasyMock.expect(reg.getInFaultInterceptorsForAssertion(aqn)).andReturn(li).anyTimes();
}
control.replay();
Message m = new MessageImpl();
epi.initializeInterceptors(m);
assertEquals(1, epi.getInterceptors(m).size());
assertSame(api, epi.getInterceptors(m).get(0));
if (requestor) {
assertEquals(1, epi.getFaultInterceptors(m).size());
assertSame(api, epi.getFaultInterceptors(m).get(0));
} else {
assertNull(epi.getFaultInterceptors(m));
}
control.verify();
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class JaxbAssertionTest method testNormalise.
@Test
public void testNormalise() {
JaxbAssertion<FooType> assertion = new JaxbAssertion<>();
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);
JaxbAssertion<?> normalised = (JaxbAssertion<?>) assertion.normalize();
assertTrue(normalised.equal(assertion));
assertSame(assertion.getData(), normalised.getData());
assertion.setOptional(true);
PolicyComponent pc = assertion.normalize();
assertEquals(Constants.TYPE_POLICY, pc.getType());
Policy p = (Policy) pc;
Iterator<List<Assertion>> alternatives = p.getAlternatives();
int total = 0;
for (int i = 0; i < 2; i++) {
List<Assertion> pcs = alternatives.next();
if (!pcs.isEmpty()) {
assertTrue(assertion.equal(pcs.get(0)));
total += pcs.size();
}
}
assertFalse(alternatives.hasNext());
assertEquals(1, total);
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class AssertionBuilderRegistryImplTest method testBuildUnknownAssertion.
@Test
public void testBuildUnknownAssertion() {
Bus bus = control.createMock(Bus.class);
PolicyBuilder builder = control.createMock(PolicyBuilder.class);
EasyMock.expect(bus.getExtension(PolicyBuilder.class)).andReturn(builder).anyTimes();
AssertionBuilderRegistryImpl reg = new AssertionBuilderRegistryImpl() {
protected void loadDynamic() {
// nothing
}
};
reg.setIgnoreUnknownAssertions(false);
Element[] elems = new Element[11];
QName[] qnames = new QName[11];
for (int i = 0; i < 11; i++) {
qnames[i] = new QName("http://my.company.com", "type" + Integer.toString(i));
elems[i] = control.createMock(Element.class);
EasyMock.expect(elems[i].getNamespaceURI()).andReturn(qnames[i].getNamespaceURI()).anyTimes();
EasyMock.expect(elems[i].getLocalName()).andReturn(qnames[i].getLocalPart()).anyTimes();
}
control.replay();
reg.setBus(bus);
assertFalse(reg.isIgnoreUnknownAssertions());
try {
reg.build(elems[0]);
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
assertEquals("NO_ASSERTIONBUILDER_EXC", ex.getCode());
}
reg.setIgnoreUnknownAssertions(true);
assertTrue(reg.isIgnoreUnknownAssertions());
for (int i = 0; i < 10; i++) {
Assertion assertion = reg.build(elems[i]);
assertTrue("Not a PrimitiveAsertion: " + assertion.getClass().getName(), assertion instanceof PrimitiveAssertion);
}
for (int i = 9; i >= 0; i--) {
assertTrue(reg.build(elems[i]) instanceof PrimitiveAssertion);
}
assertTrue(reg.build(elems[10]) instanceof PrimitiveAssertion);
}
Aggregations