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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations