use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class SchemaAddinsTest method testAegisTypeSchema.
@Test
public void testAegisTypeSchema() throws Exception {
AegisContext context = new AegisContext();
context.initialize();
XmlSchemaCollection collection = new XmlSchemaCollection();
context.addTypesSchemaDocument(collection);
XmlSchema[] schemas = collection.getXmlSchemas();
XmlSchema typeSchema = null;
for (XmlSchema schema : schemas) {
if (AegisContext.UTILITY_TYPES_SCHEMA_NS.equals(schema.getTargetNamespace())) {
typeSchema = schema;
break;
}
}
assertNotNull(typeSchema);
assertNotSame(0, typeSchema.getItems().size());
XmlSchemaSerializer serializer = new XmlSchemaSerializer();
Document[] docs = serializer.serializeSchema(typeSchema, false);
testUtilities.assertValid("/xsd:schema/xsd:simpleType[@name='char']", docs[0]);
}
use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class StandaloneReadTest method testCollectionReadXsiType.
@Test
public void testCollectionReadXsiType() throws Exception {
context = new AegisContext();
Set<java.lang.reflect.Type> roots = new HashSet<java.lang.reflect.Type>();
java.lang.reflect.Type listStringType = ListStringInterface.class.getMethods()[0].getGenericReturnType();
roots.add(listStringType);
context.setRootClasses(roots);
context.initialize();
XMLStreamReader streamReader = testUtilities.getResourceAsXMLStreamReader("topLevelListWithXsiType.xml");
AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
Object something = reader.read(streamReader);
List<String> correctAnswer = new ArrayList<>();
correctAnswer.add("cat");
correctAnswer.add("dog");
correctAnswer.add("hailstorm");
assertEquals(correctAnswer, something);
}
use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class StandaloneReadTest method testBasicTypeRead.
@Test
public void testBasicTypeRead() throws Exception {
context = new AegisContext();
context.initialize();
XMLStreamReader streamReader = testUtilities.getResourceAsXMLStreamReader("stringElement.xml");
AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
Object something = reader.read(streamReader);
assertTrue("ball-of-yarn".equals(something));
}
use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class StandaloneWriteTest method testTypeLookup.
@Test
public void testTypeLookup() throws Exception {
context = new AegisContext();
context.initialize();
AegisType st = context.getTypeMapping().getType(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string"));
assertNotNull(st);
assertEquals(st.getClass(), StringType.class);
}
use of org.apache.cxf.aegis.AegisContext in project cxf by apache.
the class StandaloneWriteTest method testWriteCollection.
@Test
public void testWriteCollection() throws Exception {
context = new AegisContext();
context.setWriteXsiTypes(true);
context.initialize();
List<String> strings = new ArrayList<>();
strings.add("cat");
strings.add("dog");
strings.add("hailstorm");
AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
StringWriter stringWriter = new StringWriter();
XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
java.lang.reflect.Type listStringType = ListStringInterface.class.getMethods()[0].getGenericReturnType();
writer.write(strings, new QName("urn:borghes", "items"), false, xmlWriter, listStringType);
xmlWriter.close();
String xml = stringWriter.toString();
XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(new StringReader(xml));
reader.nextTag();
assertEquals("urn:borghes", reader.getNamespaceURI());
assertEquals("items", reader.getLocalName());
reader.nextTag();
assertEquals(reader.getNamespaceURI(), "urn:org.apache.cxf.aegis.types");
assertEquals("string", reader.getLocalName());
String text = reader.getElementText();
assertEquals("cat", text);
reader.nextTag();
assertEquals(reader.getNamespaceURI(), "urn:org.apache.cxf.aegis.types");
assertEquals("string", reader.getLocalName());
text = reader.getElementText();
assertEquals("dog", text);
reader.nextTag();
assertEquals(reader.getNamespaceURI(), "urn:org.apache.cxf.aegis.types");
assertEquals("string", reader.getLocalName());
text = reader.getElementText();
assertEquals("hailstorm", text);
}
Aggregations