Search in sources :

Example 1 with PrimitiveAssertion

use of org.apache.neethi.builders.PrimitiveAssertion in project cxf by apache.

the class RMPolicyUtilities method getRMConfiguration.

/**
 * Returns an RMAssertion that is compatible with the default value and all RMAssertions pertaining to the
 * message (can never be null).
 *
 * @param defaultValue the default value (non-<code>null</code>)
 * @param message the message
 * @return the compatible RMAssertion
 */
public static RMConfiguration getRMConfiguration(RMConfiguration defaultValue, Message message) {
    RMConfiguration compatible = defaultValue;
    Collection<AssertionInfo> ais = collectRMAssertions(message.get(AssertionInfoMap.class));
    for (AssertionInfo ai : ais) {
        if (ai.getAssertion() instanceof JaxbAssertion<?>) {
            RMAssertion rma = (RMAssertion) ((JaxbAssertion<?>) ai.getAssertion()).getData();
            compatible = intersect(rma, compatible);
        } else if (ai.getAssertion() instanceof PrimitiveAssertion) {
            PrimitiveAssertion assertion = (PrimitiveAssertion) ai.getAssertion();
            if (RM11Constants.WSRMP_NAMESPACE_URI.equals(assertion.getName().getNamespaceURI())) {
                compatible = intersect(assertion, compatible);
            }
        }
    }
    return compatible;
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) RMAssertion(org.apache.cxf.ws.rmp.v200502.RMAssertion) PrimitiveAssertion(org.apache.neethi.builders.PrimitiveAssertion) RMConfiguration(org.apache.cxf.ws.rm.RMConfiguration) JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 2 with PrimitiveAssertion

use of org.apache.neethi.builders.PrimitiveAssertion 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

PrimitiveAssertion (org.apache.neethi.builders.PrimitiveAssertion)2 QName (javax.xml.namespace.QName)1 Bus (org.apache.cxf.Bus)1 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)1 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)1 JaxbAssertion (org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion)1 RMConfiguration (org.apache.cxf.ws.rm.RMConfiguration)1 RMAssertion (org.apache.cxf.ws.rmp.v200502.RMAssertion)1 Assertion (org.apache.neethi.Assertion)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1