use of org.apache.neethi.Assertion in project cxf by apache.
the class JaxbAssertionBuilderTest method testBuild.
@Test
public void testBuild() throws Exception {
QName qn = new QName("http://cxf.apache.org/test/assertions/foo", "FooType");
JaxbAssertionBuilder<FooType> ab = new JaxbAssertionBuilder<>(FooType.class, qn);
assertNotNull(ab);
InputStream is = JaxbAssertionBuilderTest.class.getResourceAsStream("foo.xml");
Document doc = StaxUtils.read(is);
Element elem = DOMUtils.findAllElementsByTagNameNS(doc.getDocumentElement(), "http://cxf.apache.org/test/assertions/foo", "foo").get(0);
Assertion a = ab.build(elem, null);
JaxbAssertion<FooType> jba = JaxbAssertion.cast(a, FooType.class);
FooType foo = jba.getData();
assertEquals("CXF", foo.getName());
assertEquals(2, foo.getNumber().intValue());
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class PolicyInterceptorsTest method testServerPolicyOutFaultInterceptor.
@Test
public void testServerPolicyOutFaultInterceptor() throws NoSuchMethodException {
Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getBindingFaultInfo", new Class[] { Message.class, Exception.class, BindingOperationInfo.class });
ServerPolicyOutFaultInterceptor interceptor = EasyMock.createMockBuilder(ServerPolicyOutFaultInterceptor.class).addMockedMethod(m).createMock(control);
doTestBasics(interceptor, false, true);
control.reset();
setupMessage(false, false, true, true, true, true);
Exception ex = control.createMock(Exception.class);
EasyMock.expect(exchange.get(Exception.class)).andReturn(ex);
EasyMock.expect(interceptor.getBindingFaultInfo(message, ex, boi)).andReturn(null);
control.replay();
interceptor.handleMessage(message);
control.verify();
control.reset();
setupMessage(false, false, true, true, true, true);
// Exception ex = control.createMock(Exception.class);
EasyMock.expect(exchange.get(Exception.class)).andReturn(ex);
BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
EasyMock.expect(interceptor.getBindingFaultInfo(message, ex, boi)).andReturn(bfi);
EffectivePolicy effectivePolicy = control.createMock(EffectivePolicyImpl.class);
EasyMock.expect(pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination, 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();
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class PolicyInterceptorsTest method coachPolicyOverride.
private void coachPolicyOverride(boolean in, boolean fault) {
Assertion assertion = control.createMock(Assertion.class);
EasyMock.expect(assertion.getName()).andReturn(ASSERTION_QNAME);
Collection<Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
Policy policyOverride = control.createMock(Policy.class);
EasyMock.expect(message.getContextualProperty(PolicyConstants.POLICY_OVERRIDE)).andReturn(policyOverride);
AlternativeSelector selector = control.createMock(AlternativeSelector.class);
EasyMock.expect(selector.selectAlternative(policyOverride, pe, null, null, message)).andReturn(assertions);
EasyMock.expect(pe.getAlternativeSelector()).andReturn(selector);
EasyMock.expect(pe.getBus()).andReturn(bus).anyTimes();
PolicyInterceptorProviderRegistry reg = control.createMock(PolicyInterceptorProviderRegistry.class);
EasyMock.expect(bus.getExtension(PolicyInterceptorProviderRegistry.class)).andReturn(reg);
List<Interceptor<? extends Message>> li = createMockInterceptorList();
if (in && fault) {
EasyMock.expect(reg.getInFaultInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li);
} else if (!in && fault) {
EasyMock.expect(reg.getOutFaultInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li);
} else if (in && !fault) {
EasyMock.expect(reg.getInInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li);
} else if (!in && !fault) {
EasyMock.expect(reg.getOutInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li);
}
InterceptorChain ic = control.createMock(InterceptorChain.class);
EasyMock.expect(message.getInterceptorChain()).andReturn(ic).anyTimes();
ic.add(li.get(0));
EasyMock.expectLastCall();
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class PolicyInterceptorsTest method testServerPolicyInInterceptor.
@Test
public void testServerPolicyInInterceptor() {
PolicyInInterceptor interceptor = new PolicyInInterceptor();
doTestBasics(interceptor, false, false);
control.reset();
setupMessage(false, false, false, false, true, true);
EndpointPolicy endpointPolicy = control.createMock(EndpointPolicyImpl.class);
EasyMock.expect(pe.getServerEndpointPolicy(ei, destination, message)).andReturn(endpointPolicy);
List<Interceptor<? extends Message>> li = createMockInterceptorList();
EasyMock.expect(endpointPolicy.getInterceptors(message)).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(endpointPolicy.getVocabulary(message)).andReturn(assertions);
control.replay();
interceptor.handleMessage(message);
control.verify();
}
use of org.apache.neethi.Assertion in project cxf by apache.
the class AssertionInfoMapTest method testCheckEffectivePolicy.
@Test
public void testCheckEffectivePolicy() {
Policy p = new Policy();
QName aqn = new QName("http://x.y.z", "a");
Assertion a = new PrimitiveAssertion(aqn);
QName bqn = new QName("http://x.y.z", "b");
Assertion b = new PrimitiveAssertion(bqn);
QName cqn = new QName("http://x.y.z", "c");
Assertion c = new PrimitiveAssertion(cqn);
All alt1 = new All();
alt1.addAssertion(a);
alt1.addAssertion(b);
All alt2 = new All();
alt2.addAssertion(c);
ExactlyOne ea = new ExactlyOne();
ea.addPolicyComponent(alt1);
ea.addPolicyComponent(alt2);
p.addPolicyComponent(ea);
AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
AssertionInfo ai = new AssertionInfo(a);
AssertionInfo bi = new AssertionInfo(b);
AssertionInfo ci = new AssertionInfo(c);
aim.put(aqn, Collections.singleton(ai));
aim.put(bqn, Collections.singleton(bi));
aim.put(cqn, Collections.singleton(ci));
try {
aim.checkEffectivePolicy(p);
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
// expected
}
ai.setAsserted(true);
ci.setAsserted(true);
aim.checkEffectivePolicy(p);
}
Aggregations