Search in sources :

Example 1 with FooType

use of org.apache.cxf.test.assertions.foo.FooType 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 2 with FooType

use of org.apache.cxf.test.assertions.foo.FooType in project cxf by apache.

the class JaxbAssertionBuilderTest method testConstructors.

@Test
public void testConstructors() throws Exception {
    QName qn = new QName("http://cxf.apache.org/test/assertions/foo", "FooType");
    try {
        new JaxbAssertionBuilder<Object>("org.apache.cxf.test.assertions.foo.UnknownType", qn);
        fail("Expected ClassNotFoundException not thrown.");
    } catch (ClassNotFoundException ex) {
    // expected
    }
    assertNotNull(new JaxbAssertionBuilder<Object>(qn));
    assertNotNull(new JaxbAssertionBuilder<Object>(FooType.class.getName(), qn));
    assertNotNull(new JaxbAssertionBuilder<FooType>(FooType.class, qn));
}
Also used : FooType(org.apache.cxf.test.assertions.foo.FooType) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 3 with FooType

use of org.apache.cxf.test.assertions.foo.FooType in project cxf by apache.

the class JaxbAssertionTest method testBasic.

@Test
public void testBasic() {
    JaxbAssertion<FooType> assertion = new JaxbAssertion<>();
    assertNull(assertion.getName());
    assertNull(assertion.getData());
    assertFalse(assertion.isOptional());
    assertEquals(Constants.TYPE_ASSERTION, assertion.getType());
    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);
    assertion.setOptional(true);
    assertSame(qn, assertion.getName());
    assertSame(data, assertion.getData());
    assertTrue(assertion.isOptional());
    assertEquals(Constants.TYPE_ASSERTION, assertion.getType());
}
Also used : FooType(org.apache.cxf.test.assertions.foo.FooType) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 4 with FooType

use of org.apache.cxf.test.assertions.foo.FooType 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 5 with FooType

use of org.apache.cxf.test.assertions.foo.FooType in project cxf by apache.

the class JaxbAssertionTest method testEqual.

@Test
public void testEqual() {
    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);
    PolicyComponent pc = new Policy();
    assertFalse(assertion.equal(pc));
    pc = new All();
    assertFalse(assertion.equal(pc));
    pc = new ExactlyOne();
    assertFalse(assertion.equal(pc));
    IMocksControl ctrl = EasyMock.createNiceControl();
    PrimitiveAssertion xpa = ctrl.createMock(PrimitiveAssertion.class);
    QName oqn = new QName("http://cxf.apache.org/test/assertions/blah", "OtherType");
    EasyMock.expect(xpa.getName()).andReturn(oqn);
    EasyMock.expect(xpa.getType()).andReturn(Constants.TYPE_ASSERTION);
    ctrl.replay();
    assertFalse(assertion.equal(xpa));
    ctrl.verify();
    FooType odata = new FooType();
    odata.setName(data.getName());
    odata.setNumber(data.getNumber());
    JaxbAssertion<FooType> oassertion = new JaxbAssertion<>();
    oassertion.setData(odata);
    oassertion.setName(qn);
    assertFalse(assertion.equal(oassertion));
    oassertion.setData(data);
    assertTrue(assertion.equal(oassertion));
    assertTrue(assertion.equal(assertion));
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) IMocksControl(org.easymock.IMocksControl) 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) ExactlyOne(org.apache.neethi.ExactlyOne) Test(org.junit.Test)

Aggregations

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