Search in sources :

Example 1 with TypeCreationOptions

use of org.apache.cxf.aegis.type.TypeCreationOptions 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 2 with TypeCreationOptions

use of org.apache.cxf.aegis.type.TypeCreationOptions 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)

Example 3 with TypeCreationOptions

use of org.apache.cxf.aegis.type.TypeCreationOptions 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)

Example 4 with TypeCreationOptions

use of org.apache.cxf.aegis.type.TypeCreationOptions in project cxf by apache.

the class JaxbTypeTest method testGetSetRequired.

@Test
public void testGetSetRequired() throws Exception {
    BeanType type = new BeanType(new AnnotatedTypeInfo(tm, BadBean.class, "urn:foo", new TypeCreationOptions()));
    type.setSchemaType(new QName("urn:foo", "BadBean"));
    assertEquals(0, type.getTypeInfo().getElements().size());
}
Also used : BeanType(org.apache.cxf.aegis.type.basic.BeanType) QName(javax.xml.namespace.QName) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 5 with TypeCreationOptions

use of org.apache.cxf.aegis.type.TypeCreationOptions in project cxf by apache.

the class JaxbTypeTest method testType.

@Test
public void testType() {
    AnnotatedTypeInfo info = new AnnotatedTypeInfo(tm, JaxbBean1.class, "urn:foo", new TypeCreationOptions());
    Iterator<QName> elements = info.getElements().iterator();
    assertTrue(elements.hasNext());
    // 1st element of 3 expected
    QName element = elements.next();
    assertTrue(elements.hasNext());
    AegisType custom = info.getType(element);
    if ("bogusProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof StringType);
    } else if ("elementProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof CustomStringType);
    } else if ("Annotated".equals(element.getLocalPart())) {
        assertTrue(custom instanceof StringType);
    } else {
        fail("Unexpected element name: " + element.getLocalPart());
    }
    assertTrue(elements.hasNext());
    // 2nd element of 3 expected
    element = elements.next();
    assertTrue(elements.hasNext());
    custom = info.getType(element);
    if ("bogusProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof StringType);
    } else if ("elementProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof CustomStringType);
    } else if ("Annotated".equals(element.getLocalPart())) {
        assertTrue(custom instanceof StringType);
    } else {
        fail("Unexpected element name: " + element.getLocalPart());
    }
    // 3rd element of 3 expected
    element = elements.next();
    assertFalse(elements.hasNext());
    custom = info.getType(element);
    if ("bogusProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof StringType);
    } else if ("elementProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof CustomStringType);
    } else if ("Annotated".equals(element.getLocalPart())) {
        assertTrue(custom instanceof StringType);
    } else {
        fail("Unexpected element name: " + element.getLocalPart());
    }
    Iterator<QName> atts = info.getAttributes().iterator();
    assertTrue(atts.hasNext());
    atts.next();
    assertFalse(atts.hasNext());
    assertTrue(info.isExtensibleElements());
    assertTrue(info.isExtensibleAttributes());
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) StringType(org.apache.cxf.aegis.type.basic.StringType) QName(javax.xml.namespace.QName) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Aggregations

TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)22 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)14 Test (org.junit.Test)14 DefaultTypeMapping (org.apache.cxf.aegis.type.DefaultTypeMapping)10 QName (javax.xml.namespace.QName)8 AegisType (org.apache.cxf.aegis.type.AegisType)8 AegisContext (org.apache.cxf.aegis.AegisContext)6 Before (org.junit.Before)6 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)4 BeanType (org.apache.cxf.aegis.type.basic.BeanType)3 StringType (org.apache.cxf.aegis.type.basic.StringType)3 Context (org.apache.cxf.aegis.Context)2 XmlMappedAttributeBean (org.apache.cxf.aegis.services.XmlMappedAttributeBean)2 DefaultTypeCreator (org.apache.cxf.aegis.type.DefaultTypeCreator)2 XMLTypeCreator (org.apache.cxf.aegis.type.XMLTypeCreator)2 CollectionType (org.apache.cxf.aegis.type.collection.CollectionType)2 XmlSchema (org.apache.ws.commons.schema.XmlSchema)2 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)2 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)2 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)2