Search in sources :

Example 16 with Context

use of org.apache.cxf.aegis.Context 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 17 with Context

use of org.apache.cxf.aegis.Context 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 18 with Context

use of org.apache.cxf.aegis.Context 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)

Example 19 with Context

use of org.apache.cxf.aegis.Context 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 20 with Context

use of org.apache.cxf.aegis.Context 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)

Aggregations

Context (org.apache.cxf.aegis.Context)21 Test (org.junit.Test)13 AegisContext (org.apache.cxf.aegis.AegisContext)11 ElementReader (org.apache.cxf.aegis.xml.stax.ElementReader)11 AegisType (org.apache.cxf.aegis.type.AegisType)10 Element (org.w3c.dom.Element)7 QName (javax.xml.namespace.QName)5 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)5 MapNamespaceContext (org.apache.cxf.helpers.MapNamespaceContext)5 XmlMappedAttributeBean (org.apache.cxf.aegis.services.XmlMappedAttributeBean)4 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)4 DatabindingException (org.apache.cxf.aegis.DatabindingException)3 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)3 ElementWriter (org.apache.cxf.aegis.xml.stax.ElementWriter)3 BigDecimal (java.math.BigDecimal)2 AttributeBean (org.apache.cxf.aegis.services.AttributeBean)2 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)2 Message (org.apache.cxf.common.i18n.Message)2 Fault (org.apache.cxf.interceptor.Fault)2 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)2