Search in sources :

Example 26 with Assertion

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());
}
Also used : FooType(org.apache.cxf.test.assertions.foo.FooType) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) Assertion(org.apache.neethi.Assertion) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 27 with Assertion

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();
}
Also used : InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) Method(java.lang.reflect.Method) Interceptor(org.apache.cxf.interceptor.Interceptor) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) Test(org.junit.Test)

Example 28 with Assertion

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();
}
Also used : Policy(org.apache.neethi.Policy) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 29 with Assertion

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();
}
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)

Example 30 with Assertion

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);
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) QName(javax.xml.namespace.QName) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) PolicyContainingPrimitiveAssertion(org.apache.neethi.builders.PolicyContainingPrimitiveAssertion) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) ExactlyOne(org.apache.neethi.ExactlyOne) 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