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();
}
}
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);
}
}
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());
}
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);
}
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);
}
Aggregations