Search in sources :

Example 46 with Assertion

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

Example 47 with Assertion

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();
}
Also used : Policy(org.apache.neethi.Policy) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) MessageImpl(org.apache.cxf.message.MessageImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 48 with Assertion

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();
}
Also used : Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Interceptor(org.apache.cxf.interceptor.Interceptor) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 49 with Assertion

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);
}
Also used : Policy(org.apache.neethi.Policy) FooType(org.apache.cxf.test.assertions.foo.FooType) PolicyComponent(org.apache.neethi.PolicyComponent) QName(javax.xml.namespace.QName) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) List(java.util.List) Test(org.junit.Test)

Example 50 with Assertion

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);
}
Also used : Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) PrimitiveAssertion(org.apache.neethi.builders.PrimitiveAssertion) Element(org.w3c.dom.Element) Assertion(org.apache.neethi.Assertion) PrimitiveAssertion(org.apache.neethi.builders.PrimitiveAssertion) 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