Search in sources :

Example 26 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class AbstractEncodedTest method verifyInvalid.

public void verifyInvalid(String resourceName, Class<?> expectedType) throws XMLStreamException {
    AegisType type = mapping.getType(expectedType);
    assertNotNull("type is null", type);
    Context context = getContext();
    ElementReader reader = new ElementReader(getClass().getResourceAsStream(resourceName));
    try {
        type.readObject(reader, context);
        fail("expected DatabindingException");
    } catch (DatabindingException expected) {
    // expected
    } finally {
        reader.getXMLStreamReader().close();
    }
}
Also used : MapNamespaceContext(org.apache.cxf.helpers.MapNamespaceContext) Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) DatabindingException(org.apache.cxf.aegis.DatabindingException) AegisType(org.apache.cxf.aegis.type.AegisType) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader)

Example 27 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class AbstractEncodedTest method readRef.

public Object readRef(Element element) throws XMLStreamException {
    String xml = StaxUtils.toString(element);
    ElementReader root;
    try {
        root = new ElementReader(new ByteArrayInputStream(xml.getBytes("utf-8")));
        return readRef(root);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader)

Example 28 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class ArrayTypeInfoTest method assertEquals.

public void assertEquals(ArrayTypeInfo expected, String actualString) throws Exception {
    ArrayTypeInfo actual = new ArrayTypeInfo(getNamespaceContext(), actualString);
    // only compare local part because prefix is only resolved when using the MessageReader constructor
    assertEquals(expected.getRanks(), actual.getRanks());
    assertEquals(expected.getDimensions(), actual.getDimensions());
    if (expected.getType() != null) {
        assertEquals(expected.getTypeName().getLocalPart(), actual.getTypeName().getLocalPart());
        if (expected.getRanks() == 0) {
            assertSame(addressType, actual.getType());
        } else {
            assertTrue("actual.getType() should be an instance of SoapArrayType, but is " + actual.getType().getClass().getName(), actual.getType() instanceof SoapArrayType);
        }
    }
    assertEquals(expected.toString(), actual.toString());
    String xml = "<b:array xmlns:b=\"urn:Bean\"\n" + "    xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "    xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"\n" + "    soapenc:arrayType=\"" + actualString + "\"/>";
    ElementReader reader = new ElementReader(new ByteArrayInputStream(xml.getBytes()));
    actual = new ArrayTypeInfo(reader, mapping);
    assertEquals(expected.getRanks(), actual.getRanks());
    assertEquals(expected.getDimensions(), actual.getDimensions());
    if (expected.getType() != null) {
        assertEquals(expected.getTypeName(), actual.getTypeName());
        if (expected.getRanks() == 0) {
            assertSame(addressType, actual.getType());
        } else {
            assertTrue("actual.getType() should be an instance of SoapArrayType, but is " + actual.getType().getClass().getName(), actual.getType() instanceof SoapArrayType);
        }
    }
    assertEquals(expected.toString(), actual.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader)

Example 29 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class SoapArrayTypeTest method testSparseArray.

@Test
public void testSparseArray() throws Exception {
    Context context = getContext();
    // xsd:string[2,3,4]
    ElementReader reader = new ElementReader(getClass().getResourceAsStream("arraySparse1.xml"));
    String[][][] strings = (String[][][]) createArrayType(String[][][].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    verifySparseArray(strings);
    // xsd:string[,][4] -> xsd:string[3,4]
    reader = new ElementReader(getClass().getResourceAsStream("arraySparse2.xml"));
    strings = (String[][][]) createArrayType(String[][][].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    verifySparseArray(strings);
    // xsd:string[,][4] -> xsd:string[][3] -> xsd:string[4]
    reader = new ElementReader(getClass().getResourceAsStream("arraySparse3.xml"));
    strings = (String[][][]) createArrayType(String[][][].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    verifySparseArray(strings);
    // round trip tests
    strings = readWriteReadRef("arraySparse1.xml", String[][][].class);
    verifySparseArray(strings);
    strings = readWriteReadRef("arraySparse2.xml", String[][][].class);
    verifySparseArray(strings);
    strings = readWriteReadRef("arraySparse3.xml", String[][][].class);
    verifySparseArray(strings);
}
Also used : Context(org.apache.cxf.aegis.Context) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test)

Example 30 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class SoapArrayTypeTest method testSquareArray.

@Test
public void testSquareArray() throws Exception {
    Context context = getContext();
    // xsd:string[2,3,4]
    ElementReader reader = new ElementReader(getClass().getResourceAsStream("arraySquare.xml"));
    String[][][] strings = (String[][][]) createArrayType(String[][][].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    assertArrayEquals(ARRAY_2_3_4, strings);
    // round trip tests
    strings = readWriteReadRef("arraySquare.xml", String[][][].class);
    assertArrayEquals(ARRAY_2_3_4, strings);
}
Also used : Context(org.apache.cxf.aegis.Context) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test)

Aggregations

ElementReader (org.apache.cxf.aegis.xml.stax.ElementReader)34 Test (org.junit.Test)26 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)16 QName (javax.xml.namespace.QName)13 Element (org.w3c.dom.Element)13 Context (org.apache.cxf.aegis.Context)11 XmlElement (javax.xml.bind.annotation.XmlElement)7 AegisType (org.apache.cxf.aegis.type.AegisType)7 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)7 SimpleBean (org.apache.cxf.aegis.services.SimpleBean)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 AegisContext (org.apache.cxf.aegis.AegisContext)3 DatabindingException (org.apache.cxf.aegis.DatabindingException)3 BigDecimal (java.math.BigDecimal)2 MapNamespaceContext (org.apache.cxf.helpers.MapNamespaceContext)2 XmlSchema (org.apache.ws.commons.schema.XmlSchema)2 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1