Argument inttyped = new Argument("inttyped");
Argument listtyped = new Argument("listtyped");
Event protectedEv = new Event("protected");
Event publicEv = new Event("public");
Event staticEv = new Event("static");
MockServer server = new MockServer(new Object[]{null});
Timestamp ts =
SOAPUtil.parseDateTime("1234-05-06T07:08:09", true, true, TimeZone.getDefault());
attr.setType(Primitive.ANY);
anytyped.setType(Primitive.ANY);
inttyped.setType(Primitive.INTEGER);
listtyped.setType(Primitive.STRING);
listtyped.setCollection(true);
protectedEv.setVisibility(Metaclass.PROTECTED);
publicEv.addArgument(untyped);
publicEv.addArgument(anytyped);
publicEv.addArgument(inttyped);
publicEv.addArgument(listtyped);
staticEv.addArgument(untyped);
staticEv.addArgument(anytyped);
staticEv.addArgument(inttyped);
staticEv.addArgument(listtyped);
staticEv.setStatic(true);
staticEv.setVarArg(true);
metaclass.addAttribute(attr);
metaclass.addEvent(protectedEv);
metaclass.addEvent(publicEv);
metaclass.addEvent(staticEv);
metadata.addMetaclass(metaclass);
// test protected event
XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(metadata));
String sElement = XSDGenerator.computeElementName(protectedEv);
StringReader reader = new StringReader(
"<" + sElement + " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'/>");
try
{
unmarshaller.deserialize(reader);
fail(); // SOAPUnmarshallerException expected
}
catch (SOAPUnmarshallerException e)
{
assertEquals("err.rpc.soap.missingType", e.getErrorCode());
}
// test public non-static unbound event
sElement = XSDGenerator.computeElementName(publicEv);
reader = new StringReader(
"<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
"<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
"<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
"<inttyped>42</inttyped>" +
"<listtyped>abc</listtyped><listtyped>def</listtyped>" +
"</" + sElement + ">");
try
{
unmarshaller.deserialize(reader);
fail(); // SOAPUnmarshallerException expected
}
catch (SOAPUnmarshallerException e)
{
assertEquals("err.rpc.soap.unmshComplex", e.getErrorCode());
}
// test public non-static event
sElement = XSDGenerator.computeElementName(publicEv);
reader = new StringReader(
"<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:tns='" + XML.NS_URI_TNS + "'" +
" xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
"<_instance><tns:" + attr.getName() + ">test</tns:" + attr.getName() + "></_instance>" +
"<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
"<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
"<inttyped>42</inttyped>" +
"<listtyped>abc</listtyped><listtyped>def</listtyped>" +
"</" + sElement + ">");
((XMLInvocationRequest)unmarshaller.deserialize(reader)).invoke(server);
Request request = server.getRequest();
assertNotNull(request);
assertEquals(1, request.getInvocationCount());
Request.Invocation action = request.getInvocation(0);
TransferObject tobj = action.getObject();
Object[] argArray = action.getArguments();
assertEquals(publicEv.getName(), action.getEventName());
assertEquals(publicEv.getArgumentCount(), argArray.length);
assertTrue(argArray[0] instanceof BigDecimal);
assertEquals(3.1415926535897932384626433832795, ((BigDecimal)argArray[0]).doubleValue(), 0);
assertTrue(argArray[1] instanceof Timestamp);
assertEquals(ts.getTime(), ((Timestamp)argArray[1]).getTime());
assertEquals(Primitive.createInteger(42), argArray[2]);
assertTrue(argArray[3] instanceof List);
assertEquals(2, ((List)argArray[3]).size());
assertEquals("abc", ((List)argArray[3]).get(0));
assertEquals("def", ((List)argArray[3]).get(1));
assertEquals(metaclass.getName(), tobj.getClassName());
assertNull(tobj.getEventName());
assertNull(tobj.getOID());
assertEquals(1, tobj.getValueCount());
assertEquals("test", tobj.findValue(attr.getName()));
// test static bound event
sElement = XSDGenerator.computeElementName(staticEv);
reader = new StringReader(
"<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:tns='" + XML.NS_URI_TNS + "'" +
" xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
"<_instance><tns:" + attr.getName() + ">test</tns:" + attr.getName() + "></_instance>" +
"<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
"<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
"<inttyped>42</inttyped>" +
"<listtyped>abc</listtyped><listtyped>def</listtyped>" +
"</" + sElement + ">");
try
{
unmarshaller.deserialize(reader);
fail(); // SOAPUnmarshallerException expected
}
catch (SOAPUnmarshallerException e)
{
assertEquals("err.rpc.soap.element", e.getErrorCode());
}
// test static event
sElement = XSDGenerator.computeElementName(staticEv);
reader = new StringReader(
"<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:tns='" + XML.NS_URI_TNS + "'" +
" xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
"<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
"<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
"<inttyped>42</inttyped>" +
"<listtyped><tns:item>abc</tns:item><tns:item>def</tns:item></listtyped>" +
"<listtyped><tns:item>ghi</tns:item><tns:item>jkl</tns:item></listtyped>" +
"</" + sElement + ">");
((XMLInvocationRequest)unmarshaller.deserialize(reader)).invoke(server);
request = server.getRequest();
assertNotNull(request);
assertEquals(1, request.getInvocationCount());
action = request.getInvocation(0);
tobj = action.getObject();
assertEquals(staticEv.getName(), action.getEventName());