Search in sources :

Example 6 with AegisContext

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

the class StandaloneReadTest method testCollectionReadNoXsiType.

@Test
public void testCollectionReadNoXsiType() 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("topLevelList.xml");
    AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
    // until I fix type mapping to use java.lang.reflect.Type instead of
    // Class, I need to do the following
    QName magicTypeQName = new QName("urn:org.apache.cxf.aegis.types", "ArrayOfString");
    AegisType aegisRegisteredType = context.getTypeMapping().getType(magicTypeQName);
    Object something = reader.read(streamReader, aegisRegisteredType);
    List<String> correctAnswer = new ArrayList<>();
    correctAnswer.add("cat");
    correctAnswer.add("dog");
    correctAnswer.add("hailstorm");
    assertEquals(correctAnswer, something);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) 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 7 with AegisContext

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

the class BadXMLTest method testBadDescriptorNS.

@Test
public void testBadDescriptorNS() throws Exception {
    AegisContext context = new AegisContext();
    context.initialize();
    mapping = context.getTypeMapping();
    try {
        mapping.getTypeCreator().createType(BadBeanDescriptor.class);
        Assert.fail("No exception was thrown");
    } catch (DatabindingException e) {
    // this is supposed to happen
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) AegisContext(org.apache.cxf.aegis.AegisContext) Test(org.junit.Test)

Example 8 with AegisContext

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

the class BeanTest method defaultContext.

private void defaultContext() {
    context = new AegisContext();
    context.initialize();
    mapping = context.getTypeMapping();
}
Also used : AegisContext(org.apache.cxf.aegis.AegisContext)

Example 9 with AegisContext

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

the class BeanTest method testNillableIntMinOccurs1.

@Test
public void testNillableIntMinOccurs1() throws Exception {
    context = new AegisContext();
    TypeCreationOptions config = new TypeCreationOptions();
    config.setDefaultMinOccurs(1);
    config.setDefaultNillable(false);
    context.setTypeCreationOptions(config);
    context.initialize();
    mapping = context.getTypeMapping();
    BeanType type = (BeanType) mapping.getTypeCreator().createType(IntBean.class);
    type.setTypeClass(IntBean.class);
    type.setTypeMapping(mapping);
    XmlSchema schema = newXmlSchema("urn:Bean");
    type.writeSchema(schema);
    XmlSchemaComplexType btype = (XmlSchemaComplexType) schema.getTypeByName("IntBean");
    XmlSchemaSequence seq = (XmlSchemaSequence) btype.getParticle();
    boolean int1ok = 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 ("int1".equals(oe.getName())) {
                int1ok = true;
                assertFalse(oe.isNillable());
                assertEquals(1, oe.getMinOccurs());
            }
        }
    }
    assertTrue(int1ok);
}
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 10 with AegisContext

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

the class QualificationTest method testXmlDefaultQualifiedAttribute.

@Test
public void testXmlDefaultQualifiedAttribute() throws Exception {
    AegisContext context = new AegisContext();
    TypeCreationOptions typeCreationOptions = new TypeCreationOptions();
    typeCreationOptions.setQualifyAttributes(true);
    context.setTypeCreationOptions(typeCreationOptions);
    context.initialize();
    TypeMapping mapping = context.getTypeMapping();
    AegisType type = mapping.getTypeCreator().createType(XmlMappedAttributeBean.class);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    Context messageContext = new Context(context);
    XmlMappedAttributeBean bean = new XmlMappedAttributeBean();
    Element element = writeObjectToElement(type, bean, messageContext);
    assertValid("/b:root[@pkg:attrXmlString]", element);
    assertXPathEquals("/b:root/@pkg:attrXmlString", "attrXml", element);
}
Also used : Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) XmlMappedAttributeBean(org.apache.cxf.aegis.services.XmlMappedAttributeBean) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) AegisContext(org.apache.cxf.aegis.AegisContext) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

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