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