{
m_marshaller.serialize(m_request, m_writer);
XMLUtil.parse(new StringReader(m_writer.toString()), m_xsdMap); // validate to XSD
StringReader reader = new StringReader(m_writer.toString());
Request req = (Request)m_unmarshaller.deserialize(reader);
assertEquals("http://www.nexjsystems.com/ns/test", req.getNamespace());
assertEquals("10", req.getVersion());
assertEquals(true, req.isAsync());
assertEquals(true, req.isCommit());
assertEquals("bg_BG_SF", req.getLocale().toString());
assertEquals("AST", req.getTimeZone().getID());
assertEquals(4, req.getInvocationCount());
assertEquals(1, req.getFilterCount());
TransferObject contact = req.getObject(0);
// remove all pointer references,
// objects are going to be different due to being unmarshalled from different branches of the
// XML tree (i.e. first argument and first filter blocks)
assertEqualsPointerless(contact, req.getFilter(0));
// remove all pointer references,
// objects are going to be different due to being unmarshalled from different branches of the
// XML tree (i.e. first argument and first filter blocks)
assertEqualsPointerless(contact, req.getObject(1));
Request.Invocation action = req.getInvocation(0);
assertTrue(contact == action.getObject());
assertNull(action.getEventName());
assertNull(action.getAttributes());
Pair pair = req.getInvocation(1).getAttributes();
assertEquals("a", pair.getHead());
assertEquals("b", pair.getNext().getHead());
assertNull(pair.getNext().getNext());
Object[] params = req.getInvocation(2).getArguments();
assertEquals(3, params.length);
assertTrue(params[0] instanceof Integer);
assertEquals(42, ((Integer)params[0]).intValue());
assertTrue(params[1] instanceof Double);
assertEquals(Math.PI, ((Double)params[1]).doubleValue(), 0);
assertTrue(params[2] instanceof String);
assertEquals("Hello World!", params[2]);
action = req.getInvocation(3);
assertEquals("invokeEv", action.getEventName());
assertEquals("update", action.getObject().getEventName());
params = action.getArguments();
assertEquals(2, params.length);
assertTrue(params[0] instanceof Long);
assertEquals(-1, ((Long)params[0]).intValue());
assertTrue(params[1] instanceof Double);
assertEquals(Math.E, ((Double)params[1]).doubleValue(), 0);
pair = action.getAttributes();
assertEquals("e", pair.getHead());
assertEquals("f", pair.getNext().getHead());
assertNull(pair.getNext().getNext());
OID oid = contact.getOID();
assertEquals(1, oid.getCount());
assertEquals("123", oid.getValue(0));
assertEquals("Contact-test", contact.getClassName());
assertEquals("update", contact.getEventName());
assertEquals(12345, contact.getVersion());
assertEquals(24, contact.getValueCount());
assertEquals("Java", contact.getValue("firstName"));
assertEquals("Kava", contact.getValue("lastName"));
assertNull(contact.getValue("null"));
assertSame(contact, contact.getValue("self"));
assertEquals(new Integer(1), contact.getValue("integer"));
assertEquals(new Long(2), contact.getValue("long"));
assertEquals(new Float(0.625f), contact.getValue("float"));
assertEquals(new Double(1.625), contact.getValue("double"));
assertEquals(new BigDecimal("1.2345"), contact.getValue("decimal"));
assertEquals(new Timestamp(12345), contact.getValue("timestamp"));
assertEquals(Boolean.TRUE, contact.getValue("boolean"));
assertEquals(new Binary(new byte[]{1, 2, 3, 4, 5}), contact.getValue("binary"));
assertEquals(new Binary(new byte[]{1, 2, 3, 4, 5, 6, 7}), contact.getValue("binary2"));
assertEquals(new Binary(new byte[]{1, 2}), contact.getValue("binary3"));
assertEquals("sym", ((Symbol)contact.getValue("symbol")).getName());
assertSame(Symbol.define("sym"), contact.getValue("symbol"));
Pair pairA = (Pair)contact.getValue("pair");
assertEquals("A", pairA.getHead());
Pair pairB = pairA.getNext();
assertEquals("B", pairB.getHead());
assertNull(pairB.getTail());
char[] cvec = (char[])contact.getValue("cvector");
assertEquals(3, cvec.length);
assertEquals('a', cvec[0]);
assertEquals('b', cvec[1]);
assertEquals('c', cvec[2]);
byte[] bvec = (byte[])contact.getValue("bvector");
assertEquals(3, bvec.length);
assertEquals(0, bvec[0]);
assertEquals((byte)0xAB, bvec[1]);
assertEquals(0x12, bvec[2]);
String[] svec = (String[])contact.getValue("svector");
assertEquals(3, svec.length);
assertEquals("a", svec[0]);
assertEquals("b", svec[1]);
assertEquals("c", svec[2]);
// XMLMarshaller is hardcoded to marshal Object[] as List for compatibility with MS.NET
List vec = (List)contact.getValue("vector");
assertEquals(3, vec.size());
assertEquals("a", vec.get(0));
assertEquals("b", vec.get(1));
assertEquals("c", vec.get(2));
PCodeFunction fun = (PCodeFunction)contact.getValue("function");
assertEquals(3, fun.code.length);
assertEquals(0, fun.code[0]);
assertEquals(1, fun.code[1]);
assertEquals(2, fun.code[2]);
assertEquals(1, fun.constants.length);
assertEquals("abc", fun.constants[0]);
PCodeMacro mac = (PCodeMacro)contact.getValue("macro");
assertEquals(3, mac.code.length);
assertEquals(3, mac.code[0]);
assertEquals(4, mac.code[1]);
assertEquals(5, mac.code[2]);
assertEquals(1, mac.constants.length);
assertEquals("cde", mac.constants[0]);
PrivilegeSet privilegeSet = (PrivilegeSet)contact.getValue("privilegeSet");
assertTrue(privilegeSet.contains(Repository
.getMetadata()
.getPrimitivePrivilege("updateContact")));
assertTrue(privilegeSet.contains(Repository
.getMetadata()
.getPrimitivePrivilege("WorkflowManage")));
assertFalse(privilegeSet.contains(Repository
.getMetadata()
.getPrimitivePrivilege("createContact")));
List addressList = (List)contact.getValue("addresses");
assertEquals(2, addressList.size());
TransferObject addr1 = (TransferObject)addressList.get(0);
oid = addr1.getOID();
assertEquals(1, oid.getCount());
assertEquals("456", oid.getValue(0));
assertEquals("Address-test", addr1.getClassName());
assertEquals("update", addr1.getEventName());
assertEquals(0, addr1.getVersion());
assertEquals("Canada", addr1.getValue("country"));
assertSame(addr1, addr1.getValue("self"));
assertSame(contact, addr1.getValue("contact"));
assertSame(contact.getValue("symbol"), addr1.getValue("symbol"));
TransferObject addr2 = (TransferObject)addressList.get(1);
assertEquals(2, addr2.getValueCount());
assertEquals("USA", addr2.getValue("country"));
assertSame(contact, addr2.getValue("contact"));
// remove all pointer references,
// objects are going to be different due to being unmarshalled from different branches of the
// XML tree (i.e. correlator and first argument blocks)
assertEqualsPointerless(req.getCorrelator(), addr2);
}