Search in sources :

Example 31 with ElementReader

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

the class SoapArrayTypeTest method testAnyTypeArray.

@Test
public void testAnyTypeArray() throws Exception {
    Context context = getContext();
    // ur-type[4] nested elements have xsi:type
    ElementReader reader = new ElementReader(getClass().getResourceAsStream("arrayAnyType1.xml"));
    Object[] objects = (Object[]) createArrayType(Object[].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    assertArrayEquals(new Object[] { 42, (float) 42.42, "Forty Two" }, objects);
    // ur-type[4] nested element name have a global schema type
    reader = new ElementReader(getClass().getResourceAsStream("arrayAnyType2.xml"));
    objects = (Object[]) createArrayType(Object[].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    assertArrayEquals(new Object[] { 42, new BigDecimal("42.42"), "Forty Two" }, objects);
    // round trip tests
    objects = readWriteReadRef("arrayAnyType1.xml", Object[].class);
    assertArrayEquals(new Object[] { 42, (float) 42.42, "Forty Two" }, objects);
    objects = readWriteReadRef("arrayAnyType2.xml", Object[].class);
    assertArrayEquals(new Object[] { 42, new BigDecimal("42.42"), "Forty Two" }, objects);
}
Also used : Context(org.apache.cxf.aegis.Context) BigDecimal(java.math.BigDecimal) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test)

Example 32 with ElementReader

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

the class SoapArrayTypeTest method testArrayOfArrays.

@Test
public void testArrayOfArrays() throws Exception {
    Context context = getContext();
    // xsd:string[,][2]
    ElementReader reader = new ElementReader(getClass().getResourceAsStream("arrayArrayOfArrays1.xml"));
    String[][][] strings = (String[][][]) createArrayType(String[][][].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    assertArrayEquals(ARRAY_2_3_4, strings);
    // round trip tests
    strings = readWriteReadRef("arrayArrayOfArrays1.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)

Example 33 with ElementReader

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

the class SoapArrayTypeTest method testSimpleArray.

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

Example 34 with ElementReader

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

the class EnumTypeTest method testNillable.

@Test
public void testNillable() throws Exception {
    AegisType type = tm.getTypeCreator().createType(EnumBean.class);
    tm.register(type);
    Element root = writeObjectToElement(type, new EnumBean(), getContext());
    ElementReader reader = new ElementReader(StaxUtils.createXMLStreamReader(root));
    Object value = type.readObject(reader, getContext());
    assertTrue(value instanceof EnumBean);
    EnumBean bean = (EnumBean) value;
    assertNull(bean.getCurrency());
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) Element(org.w3c.dom.Element) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

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