Search in sources :

Example 31 with AegisType

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

the class EnumTypeTest method testTypeWithJaxbAnnotations.

/**
 * {@link https://issues.apache.org/jira/browse/CXF-7188}
 */
@Test
public void testTypeWithJaxbAnnotations() throws Exception {
    AegisType type = tm.getTypeCreator().createType(JaxbTestEnum.class);
    Element element = writeObjectToElement(type, JaxbTestEnum.VALUE1, getContext());
    assertEquals("Value1", element.getTextContent());
    XMLStreamReader xreader = StaxUtils.createXMLStreamReader(element);
    ElementReader reader = new ElementReader(xreader);
    Object value = type.readObject(reader, getContext());
    assertEquals(JaxbTestEnum.VALUE1, value);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) AegisType(org.apache.cxf.aegis.type.AegisType) Element(org.w3c.dom.Element) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 32 with AegisType

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

the class EnumTypeTest method testJaxbTypeAttributeOnEnum.

@Test
public void testJaxbTypeAttributeOnEnum() throws Exception {
    AegisType type = tm.getTypeCreator().createType(JaxbTestEnum.class);
    assertEquals("urn:xfire:foo", type.getSchemaType().getNamespaceURI());
    assertTrue(type instanceof EnumType);
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 33 with AegisType

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

the class EnumTypeTest method testWsdlFromJaxbAnnotations.

/**
 * {@link https://issues.apache.org/jira/browse/CXF-7188}
 */
@Test
public void testWsdlFromJaxbAnnotations() throws Exception {
    AegisType type = tm.getTypeCreator().createType(JaxbTestEnum.class);
    XmlSchema schema = newXmlSchema("urn:test");
    type.writeSchema(schema);
    XmlSchemaSerializer ser = new XmlSchemaSerializer();
    Document doc = ser.serializeSchema(schema, false)[0];
    addNamespace("xsd", Constants.URI_2001_SCHEMA_XSD);
    assertValid("//xsd:simpleType[@name='bar']/xsd:restriction[@base='xsd:string']", doc);
    assertValid("//xsd:restriction[@base='xsd:string']/xsd:enumeration[@value='Value1']", doc);
    assertValid("//xsd:restriction[@base='xsd:string']/xsd:enumeration[@value='VALUE2']", doc);
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSerializer(org.apache.ws.commons.schema.XmlSchemaSerializer) Document(org.w3c.dom.Document) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 34 with AegisType

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

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

AegisType (org.apache.cxf.aegis.type.AegisType)97 QName (javax.xml.namespace.QName)43 Test (org.junit.Test)40 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)35 DatabindingException (org.apache.cxf.aegis.DatabindingException)18 AegisContext (org.apache.cxf.aegis.AegisContext)16 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)11 Element (org.w3c.dom.Element)11 Context (org.apache.cxf.aegis.Context)10 BeanType (org.apache.cxf.aegis.type.basic.BeanType)10 Method (java.lang.reflect.Method)9 MessageReader (org.apache.cxf.aegis.xml.MessageReader)9 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)8 BeanTypeInfo (org.apache.cxf.aegis.type.basic.BeanTypeInfo)8 CollectionType (org.apache.cxf.aegis.type.collection.CollectionType)8 HashSet (java.util.HashSet)7 MapType (org.apache.cxf.aegis.type.collection.MapType)7 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)7 ElementReader (org.apache.cxf.aegis.xml.stax.ElementReader)7 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)5