Search in sources :

Example 31 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class StandaloneWriteTest method testBean.

@Test
public void testBean() throws Exception {
    context = new AegisContext();
    Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
    rootClasses.add(SimpleBean.class);
    context.setRootClasses(rootClasses);
    context.initialize();
    SimpleBean sb = new SimpleBean();
    sb.setCharacter('\u4000');
    sb.setHowdy("doody");
    AegisType sbType = context.getTypeMapping().getType(sb.getClass());
    AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
    writer.write(sb, new QName("urn:meow", "catnip"), false, xmlWriter, sbType);
    xmlWriter.close();
    String xml = stringWriter.toString();
    assertTrue(xml.contains("doody"));
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) StringType(org.apache.cxf.aegis.type.basic.StringType) AegisType(org.apache.cxf.aegis.type.AegisType) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) SimpleBean(org.apache.cxf.aegis.services.SimpleBean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class StandaloneWriteTest method testBasicTypeWrite.

@Test
public void testBasicTypeWrite() throws Exception {
    context = new AegisContext();
    context.initialize();
    AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
    writer.write("ball-of-yarn", new QName("urn:meow", "cat-toy"), false, xmlWriter, new StringType());
    xmlWriter.close();
    String xml = stringWriter.toString();
    XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(new StringReader(xml));
    reader.nextTag();
    assertEquals("urn:meow", reader.getNamespaceURI());
    assertEquals("cat-toy", reader.getLocalName());
    reader.next();
    String text = reader.getText();
    assertEquals("ball-of-yarn", text);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringWriter(java.io.StringWriter) StringType(org.apache.cxf.aegis.type.basic.StringType) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 33 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class BeanTest method testNillableAnnotation.

@Test
public void testNillableAnnotation() throws Exception {
    context = new AegisContext();
    TypeCreationOptions config = new TypeCreationOptions();
    config.setDefaultNillable(false);
    config.setDefaultMinOccurs(1);
    context.setTypeCreationOptions(config);
    context.initialize();
    mapping = context.getTypeMapping();
    BeanType type = (BeanType) mapping.getTypeCreator().createType(BeanWithNillableItem.class);
    type.setTypeClass(BeanWithNillableItem.class);
    type.setTypeMapping(mapping);
    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);
    XmlSchemaComplexType btype = (XmlSchemaComplexType) schema.getTypeByName("BeanWithNillableItem");
    XmlSchemaSequence seq = (XmlSchemaSequence) btype.getParticle();
    boolean itemFound = false;
    boolean itemNotNillableFound = false;
    for (int x = 0; x < seq.getItems().size(); x++) {
        XmlSchemaSequenceMember o = seq.getItems().get(x);
        if (o instanceof XmlSchemaElement) {
            XmlSchemaElement oe = (XmlSchemaElement) o;
            if ("item".equals(oe.getName())) {
                itemFound = true;
                assertTrue(oe.isNillable());
                assertEquals(0, oe.getMinOccurs());
            } else if ("itemNotNillable".equals(oe.getName())) {
                itemNotNillableFound = true;
                assertFalse(oe.isNillable());
            }
        }
    }
    assertTrue(itemFound);
    assertTrue(itemNotNillableFound);
}
Also used : XmlSchemaSequence(org.apache.ws.commons.schema.XmlSchemaSequence) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSequenceMember(org.apache.ws.commons.schema.XmlSchemaSequenceMember) AegisContext(org.apache.cxf.aegis.AegisContext) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest) Test(org.junit.Test)

Example 34 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class DateTimezoneTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    context = new AegisContext();
    context.initialize();
    mapping = context.getTypeMapping();
}
Also used : AegisContext(org.apache.cxf.aegis.AegisContext)

Example 35 with AegisContext

use of org.apache.cxf.aegis.AegisContext in project cxf by apache.

the class DynamicProxyTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    AegisContext context = new AegisContext();
    context.initialize();
    mapping = context.getTypeMapping();
}
Also used : AegisContext(org.apache.cxf.aegis.AegisContext)

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