Search in sources :

Example 1 with AegisContext

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

the class BaeldungIntegrationTest method initializeContext.

private void initializeContext() {
    context = new AegisContext();
    Set<Type> rootClasses = new HashSet<Type>();
    rootClasses.add(CourseRepo.class);
    context.setRootClasses(rootClasses);
    Map<Class<?>, String> beanImplementationMap = new HashMap<>();
    beanImplementationMap.put(CourseRepoImpl.class, "CourseRepo");
    context.setBeanImplementationMap(beanImplementationMap);
    context.setWriteXsiTypes(true);
    context.initialize();
}
Also used : Type(java.lang.reflect.Type) AegisType(org.apache.cxf.aegis.type.AegisType) HashMap(java.util.HashMap) AegisContext(org.apache.cxf.aegis.AegisContext) HashSet(java.util.HashSet)

Example 2 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 3 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 4 with AegisContext

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

the class QualificationTest method testAnnotatedDefaultUnqualifiedAttribute.

@Test
public void testAnnotatedDefaultUnqualifiedAttribute() throws Exception {
    AegisContext context = new AegisContext();
    context.initialize();
    TypeMapping mapping = context.getTypeMapping();
    AegisType type = mapping.getTypeCreator().createType(AttributeBean.class);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    Context messageContext = new Context(context);
    AttributeBean bean = new AttributeBean();
    Element element = writeObjectToElement(type, bean, messageContext);
    assertValid("/b:root[@xyzzy:attrExplicitString]", element);
    assertXPathEquals("/b:root/@xyzzy:attrExplicitString", "attrExplicit", element);
    assertValid("/b:root[@attrPlainString]", element);
    assertXPathEquals("/b:root/@attrPlainString", "attrPlain", element);
}
Also used : Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) 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) AttributeBean(org.apache.cxf.aegis.services.AttributeBean) XmlMappedAttributeBean(org.apache.cxf.aegis.services.XmlMappedAttributeBean) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 5 with AegisContext

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

the class QualificationTest method testAnnotatedDefaultQualifiedAttribute.

@Test
public void testAnnotatedDefaultQualifiedAttribute() 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(AttributeBean.class);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    Context messageContext = new Context(context);
    AttributeBean bean = new AttributeBean();
    Element element = writeObjectToElement(type, bean, messageContext);
    assertValid("/b:root[@xyzzy:attrExplicitString]", element);
    assertXPathEquals("/b:root/@xyzzy:attrExplicitString", "attrExplicit", element);
    assertValid("/b:root[@pkg:attrPlainString]", element);
    assertXPathEquals("/b:root/@pkg:attrPlainString", "attrPlain", element);
}
Also used : Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) 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) AttributeBean(org.apache.cxf.aegis.services.AttributeBean) XmlMappedAttributeBean(org.apache.cxf.aegis.services.XmlMappedAttributeBean) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Aggregations

AegisContext (org.apache.cxf.aegis.AegisContext)37 Test (org.junit.Test)16 QName (javax.xml.namespace.QName)14 AegisType (org.apache.cxf.aegis.type.AegisType)13 HashSet (java.util.HashSet)11 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)8 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)8 Before (org.junit.Before)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 StringWriter (java.io.StringWriter)4 Type (java.lang.reflect.Type)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 AegisDatabinding (org.apache.cxf.aegis.databinding.AegisDatabinding)4 XmlMappedAttributeBean (org.apache.cxf.aegis.services.XmlMappedAttributeBean)4 DefaultTypeMapping (org.apache.cxf.aegis.type.DefaultTypeMapping)3 Element (org.w3c.dom.Element)3 IOException (java.io.IOException)2