Search in sources :

Example 36 with AegisType

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

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

Example 38 with AegisType

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

the class MapTest method testType.

@Test
public void testType() throws Exception {
    Method m = MapService.class.getMethod("getMap", new Class[0]);
    AegisType type = creator.createType(m, -1);
    tm.register(type);
    assertTrue(type instanceof MapType);
    MapType mapType = (MapType) type;
    QName keyName = mapType.getKeyName();
    assertNotNull(keyName);
    type = mapType.getKeyType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(String.class));
    type = mapType.getValueType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(Integer.class));
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) Method(java.lang.reflect.Method) MapType(org.apache.cxf.aegis.type.collection.MapType) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 39 with AegisType

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

the class MapTest method testPDType.

@Test
public void testPDType() throws Exception {
    PropertyDescriptor pd = Introspector.getBeanInfo(MapDTO.class, Object.class).getPropertyDescriptors()[0];
    AegisType type = creator.createType(pd);
    tm.register(type);
    assertTrue(type instanceof MapType);
    MapType mapType = (MapType) type;
    QName keyName = mapType.getKeyName();
    assertNotNull(keyName);
    type = mapType.getKeyType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(String.class));
    type = mapType.getValueType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(Integer.class));
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) MapType(org.apache.cxf.aegis.type.collection.MapType) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 40 with AegisType

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

the class MapTest method testMapDTO.

@Test
public void testMapDTO() {
    tm = new DefaultTypeMapping();
    creator = new Java5TypeCreator();
    creator.setConfiguration(new TypeCreationOptions());
    tm.setTypeCreator(creator);
    AegisType dto = creator.createType(MapDTO.class);
    Set<AegisType> deps = dto.getDependencies();
    AegisType type = deps.iterator().next();
    assertTrue(type instanceof MapType);
    MapType mapType = (MapType) type;
    deps = dto.getDependencies();
    assertEquals(1, deps.size());
    type = mapType.getKeyType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(String.class));
    type = mapType.getValueType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(Integer.class));
}
Also used : DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) AegisType(org.apache.cxf.aegis.type.AegisType) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) MapType(org.apache.cxf.aegis.type.collection.MapType) 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