Search in sources :

Example 26 with AegisContext

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]);
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) AegisContext(org.apache.cxf.aegis.AegisContext) XmlSchemaSerializer(org.apache.ws.commons.schema.XmlSchemaSerializer) Document(org.w3c.dom.Document) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) Test(org.junit.Test)

Example 27 with AegisContext

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);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) AegisContext(org.apache.cxf.aegis.AegisContext) ArrayList(java.util.ArrayList) AegisType(org.apache.cxf.aegis.type.AegisType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with AegisContext

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));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) AegisContext(org.apache.cxf.aegis.AegisContext) Test(org.junit.Test)

Example 29 with AegisContext

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);
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) Test(org.junit.Test)

Example 30 with AegisContext

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);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) ArrayList(java.util.ArrayList) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

AegisContext (org.apache.cxf.aegis.AegisContext)40 Test (org.junit.Test)20 QName (javax.xml.namespace.QName)15 AegisType (org.apache.cxf.aegis.type.AegisType)15 HashSet (java.util.HashSet)13 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)8 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)8 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 Context (org.apache.cxf.aegis.Context)6 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)6 XmlSchema (org.apache.ws.commons.schema.XmlSchema)5 Before (org.junit.Before)5 StringWriter (java.io.StringWriter)4 AegisDatabinding (org.apache.cxf.aegis.databinding.AegisDatabinding)4 XmlMappedAttributeBean (org.apache.cxf.aegis.services.XmlMappedAttributeBean)4 Type (java.lang.reflect.Type)3 ArrayList (java.util.ArrayList)3 SimpleBean (org.apache.cxf.aegis.services.SimpleBean)3 DefaultTypeMapping (org.apache.cxf.aegis.type.DefaultTypeMapping)3