TestDerivatedBeanSerializerpublic class TestDerivatedBeanSerializer extends TestCase A little testcase for validating the serialization of inherited type. |
Fields Summary |
---|
QName | superTypeQName | QName | inheritedTypeQName | StringWriter | stringWriter | org.apache.axis.encoding.SerializationContext | context |
Constructors Summary |
---|
public TestDerivatedBeanSerializer(String arg0)Constructor for DerivatedBeanSerializerTest.
super(arg0);
|
Methods Summary |
---|
protected void | setUp()
super.setUp();
// Initialisation of attribute used in the testMethods.
stringWriter = new StringWriter();
MessageContext msgContext = new MessageContext(new AxisServer());
context = new SerializationContext(stringWriter, msgContext);
// Create a TypeMapping and register the specialized Type Mapping
TypeMappingRegistry reg = context.getTypeMappingRegistry();
TypeMapping tm = (TypeMapping) reg.createTypeMapping();
tm.setSupportedEncodings(new String[] {Constants.URI_DEFAULT_SOAP_ENC});
reg.register(Constants.URI_DEFAULT_SOAP_ENC, tm);
tm.register(SuperBean.class, superTypeQName, new BeanSerializerFactory(SuperBean.class,superTypeQName), new BeanDeserializerFactory(SuperBean.class,superTypeQName));
tm.register(DerivatedBean.class, inheritedTypeQName, new BeanSerializerFactory(DerivatedBean.class,inheritedTypeQName), new BeanDeserializerFactory(DerivatedBean.class,inheritedTypeQName));
| public void | testDerivatedBeanSerialize()Test the serialization of an derivated sequence. The derivated bean contains two elements
(three, four) and the super class has three elements (zero, one, two). The excepted
result is something like:
<DerivatedBean>
<zero/>
<one/>
<two/>
<three/>
<four/>
</DerivatedBean>
BeanSerializer ser = new BeanSerializer(DerivatedBean.class, inheritedTypeQName);
Object object = new DerivatedBean();
ser.serialize(inheritedTypeQName,null,object,context);
// Check the result
String msgString = stringWriter.toString();
StringReader reader = new StringReader(msgString);
Document doc = XMLUtils.newDocument(new InputSource(reader));
NodeList nodes = doc.getFirstChild().getChildNodes();
assertEquals("1st Attribute", "zero", nodes.item(0).getLocalName());
assertEquals("2nd Attribute", "one", nodes.item(1).getLocalName());
assertEquals("3rd Attribute", "two", nodes.item(2).getLocalName());
assertEquals("4th Attribute", "three", nodes.item(3).getLocalName());
assertEquals("First Attribute", "four", nodes.item(4).getLocalName());
|
|