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