Search in sources :

Example 21 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class BeanTest method testByteBean.

@Test
public void testByteBean() throws Exception {
    defaultContext();
    BeanTypeInfo info = new BeanTypeInfo(ByteBean.class, "urn:Bean");
    info.setTypeMapping(mapping);
    BeanType type = new BeanType(info);
    type.setTypeClass(ByteBean.class);
    type.setTypeMapping(mapping);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    QName name = new QName("urn:Bean", "data");
    AegisType dataType = type.getTypeInfo().getType(name);
    assertNotNull(dataType);
    assertTrue(type.getTypeInfo().isNillable(name));
    ByteBean bean = new ByteBean();
    // Test writing
    Element element = writeObjectToElement(type, bean, getContext());
    // Make sure the date doesn't have an element. Its non nillable so it
    // just
    // shouldn't be there.
    addNamespace("xsi", Constants.URI_2001_SCHEMA_XSI);
    assertValid("/b:root/b:data[@xsi:nil='true']", element);
    XMLStreamReader sreader = StaxUtils.createXMLStreamReader(element);
    bean = (ByteBean) type.readObject(new ElementReader(sreader), getContext());
    assertNotNull(bean);
    assertNull(bean.getData());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Element(org.w3c.dom.Element) XmlElement(javax.xml.bind.annotation.XmlElement) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest) Test(org.junit.Test)

Example 22 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class DynamicProxyTest method testDynamicProxyNonStandardSetter.

@Test
public void testDynamicProxyNonStandardSetter() throws Exception {
    BeanType type = new BeanType();
    type.setTypeClass(IMyInterface.class);
    type.setTypeMapping(mapping);
    type.setSchemaType(new QName("urn:MyInterface", "data"));
    ElementReader reader = new ElementReader(getResourceAsStream("MyInterface.xml"));
    IMyInterface data = (IMyInterface) type.readObject(reader, getContext());
    try {
        data.setNameNoParams();
        fail(IllegalAccessError.class + " should be thrown.");
    } catch (IllegalAccessError e) {
    // do nothing
    }
    try {
        data.set();
        fail(IllegalAccessError.class + " should be thrown.");
    } catch (IllegalAccessError e) {
    // do nothing
    }
}
Also used : QName(javax.xml.namespace.QName) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 23 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class DynamicProxyTest method testDynamicProxy.

@Test
public void testDynamicProxy() throws Exception {
    BeanType type = new BeanType();
    type.setTypeClass(IMyInterface.class);
    type.setTypeMapping(mapping);
    type.setSchemaType(new QName("urn:MyInterface", "data"));
    ElementReader reader = new ElementReader(getResourceAsStream("MyInterface.xml"));
    IMyInterface data = (IMyInterface) type.readObject(reader, getContext());
    assertEquals("junk", data.getName());
    assertEquals(true, data.isUseless());
    data.setName("bigjunk");
    data.setUseless(false);
    assertEquals("bigjunk", data.getName());
    assertEquals(false, data.isUseless());
    assertTrue(data.hashCode() != 0);
    assertTrue(data.equals(data));
    // checkstyle isn't smart enough to know we're testing equals....
    // assertFalse(data.equals(null));
    // assertFalse("bigjunk".equals(data));
    assertNotNull(data.toString());
    assertEquals("foo", data.getFOO());
    assertEquals(0, data.getNonSpecifiedInt());
}
Also used : QName(javax.xml.namespace.QName) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 24 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class DynamicProxyTest method testDynamicProxyNonGetterSetter.

@Test
public void testDynamicProxyNonGetterSetter() throws Exception {
    BeanType type = new BeanType();
    type.setTypeClass(IMyInterface.class);
    type.setTypeMapping(mapping);
    type.setSchemaType(new QName("urn:MyInterface", "data"));
    ElementReader reader = new ElementReader(getResourceAsStream("MyInterface.xml"));
    IMyInterface data = (IMyInterface) type.readObject(reader, getContext());
    try {
        data.doSomething();
        fail(IllegalAccessError.class + " should be thrown.");
    } catch (IllegalAccessError e) {
    // do nothing
    }
}
Also used : QName(javax.xml.namespace.QName) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 25 with ElementReader

use of org.apache.cxf.aegis.xml.stax.ElementReader in project cxf by apache.

the class DynamicProxyTest method testDynamicProxyNested.

@Test
public void testDynamicProxyNested() throws Exception {
    BeanType type = new BeanType();
    type.setTypeClass(IMyInterface.class);
    type.setSchemaType(new QName("urn:MyInterface", "myInterface"));
    type.setTypeMapping(mapping);
    BeanType type2 = new BeanType();
    type2.setTypeClass(IMyInterface2.class);
    type2.setSchemaType(new QName("urn:MyInterface2", "myInterface2"));
    type2.setTypeMapping(mapping);
    type2.getTypeInfo().mapType(new QName("urn:MyInterface", "myInterface"), type);
    ElementReader reader = new ElementReader(getResourceAsStream("MyInterface2.xml"));
    IMyInterface2 data = (IMyInterface2) type2.readObject(reader, getContext());
    assertNotNull(data.getMyInterface());
    assertEquals("junk", data.getMyInterface().getName());
    assertEquals(true, data.getMyInterface().isUseless());
}
Also used : QName(javax.xml.namespace.QName) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Aggregations

ElementReader (org.apache.cxf.aegis.xml.stax.ElementReader)34 Test (org.junit.Test)26 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)16 QName (javax.xml.namespace.QName)13 Element (org.w3c.dom.Element)13 Context (org.apache.cxf.aegis.Context)11 XmlElement (javax.xml.bind.annotation.XmlElement)7 AegisType (org.apache.cxf.aegis.type.AegisType)7 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)7 SimpleBean (org.apache.cxf.aegis.services.SimpleBean)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 AegisContext (org.apache.cxf.aegis.AegisContext)3 DatabindingException (org.apache.cxf.aegis.DatabindingException)3 BigDecimal (java.math.BigDecimal)2 MapNamespaceContext (org.apache.cxf.helpers.MapNamespaceContext)2 XmlSchema (org.apache.ws.commons.schema.XmlSchema)2 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1