use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.
the class AbstractEncodedTest method readWriteReadRef.
public <T> T readWriteReadRef(String file, Class<T> typeClass) throws XMLStreamException {
Context context = getContext();
AegisType type = mapping.getType(typeClass);
assertNotNull("no type found for " + typeClass.getName());
// read file
ElementReader reader = new ElementReader(getClass().getResourceAsStream(file));
T value = typeClass.cast(type.readObject(reader, context));
reader.getXMLStreamReader().close();
// write value to element
Element element = writeRef(value);
// reread value from element
value = typeClass.cast(readRef(element));
return value;
}
use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.
the class SoapArrayTypeTest method testStructArray.
@Test
public void testStructArray() throws Exception {
Context context = getContext();
// b:address[2]
ElementReader reader = new ElementReader(getClass().getResourceAsStream("arrayStructs.xml"));
Address[] addresses = (Address[]) createArrayType(Address[].class).readObject(reader, context);
reader.getXMLStreamReader().close();
AbstractEncodedTest.validateShippingAddress(addresses[0]);
AbstractEncodedTest.validateBillingAddress(addresses[1]);
// round trip tests
addresses = readWriteReadRef("arrayStructs.xml", Address[].class);
AbstractEncodedTest.validateShippingAddress(addresses[0]);
AbstractEncodedTest.validateBillingAddress(addresses[1]);
}
use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.
the class SoapArrayTypeTest method testPartiallyTransmitted.
@Test
public void testPartiallyTransmitted() throws Exception {
Context context = getContext();
// xsd:int[5] offset="[2]"
ElementReader reader = new ElementReader(getClass().getResourceAsStream("arrayPartiallyTransmitted.xml"));
int[] numbers = (int[]) createArrayType(int[].class).readObject(reader, context);
reader.getXMLStreamReader().close();
assertArrayEquals(new int[] { 0, 0, 3, 4, 0 }, numbers);
// round trip tests
numbers = readWriteReadRef("arrayPartiallyTransmitted.xml", int[].class);
assertArrayEquals(new int[] { 0, 0, 3, 4, 0 }, numbers);
}
use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.
the class SoapArrayTypeTest method testUrTypeArray.
@Test
public void testUrTypeArray() throws Exception {
Context context = getContext();
// ur-type[4] nested elements have xsi:type
ElementReader reader = new ElementReader(getClass().getResourceAsStream("arrayUrType1.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("arrayUrType2.xml"));
objects = (Object[]) createArrayType(Object[].class).readObject(reader, context);
reader.getXMLStreamReader().close();
assertArrayEquals(Arrays.asList(objects).toString(), new Object[] { 42, new BigDecimal("42.42"), "Forty Two" }, objects);
}
use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.
the class StructTypeTest method testComplexStruct.
@Test
public void testComplexStruct() throws Exception {
// Test reading
ElementReader reader = new ElementReader(getClass().getResourceAsStream("struct3.xml"));
PurchaseOrder po = (PurchaseOrder) purchaseOrderType.readObject(reader, getLocalContext());
validatePurchaseOrder(po);
reader.getXMLStreamReader().close();
// Test reading - no namespace on nested elements
reader = new ElementReader(getClass().getResourceAsStream("struct4.xml"));
po = (PurchaseOrder) purchaseOrderType.readObject(reader, getLocalContext());
validatePurchaseOrder(po);
reader.getXMLStreamReader().close();
// Test writing
Element element = writeRef(po);
validatePurchaseOrder(element);
// Test reading - no namespace on nested elements, xsi:nil (CXF-2695)
reader = new ElementReader(getClass().getResourceAsStream("struct5.xml"));
po = (PurchaseOrder) purchaseOrderType.readObject(reader, getLocalContext());
validatePurchaseOrder(po, true);
reader.getXMLStreamReader().close();
}
Aggregations