Search in sources :

Example 6 with PolicyComponent

use of org.apache.neethi.PolicyComponent in project cxf by apache.

the class JaxbAssertionTest method testNormalise.

@Test
public void testNormalise() {
    JaxbAssertion<FooType> assertion = new JaxbAssertion<FooType>();
    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();
        }
    }
    assertTrue(!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)

Aggregations

PolicyComponent (org.apache.neethi.PolicyComponent)6 Assertion (org.apache.neethi.Assertion)4 Policy (org.apache.neethi.Policy)3 Test (org.junit.Test)3 QName (javax.xml.namespace.QName)2 FooType (org.apache.cxf.test.assertions.foo.FooType)2 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)2 InputStream (java.io.InputStream)1 List (java.util.List)1 All (org.apache.neethi.All)1 ExactlyOne (org.apache.neethi.ExactlyOne)1 PolicyContainingAssertion (org.apache.neethi.PolicyContainingAssertion)1 PolicyOperator (org.apache.neethi.PolicyOperator)1 PolicyReference (org.apache.neethi.PolicyReference)1 IMocksControl (org.easymock.IMocksControl)1