Package nexj.core.rpc

Examples of nexj.core.rpc.TransferObject$Iterator


      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());
      argArray = action.getArguments();
      assertEquals(5, argArray.length); // untyped + anytyped + inttyped + 2*listtyped
      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));
      assertTrue(argArray[3] instanceof List);
      assertEquals("ghi", ((List)argArray[4]).get(0));
      assertEquals("jkl", ((List)argArray[4]).get(1));
      assertEquals(metaclass.getName(), tobj.getClassName());
      assertNull(tobj.getEventName());
      assertNull(tobj.getOID());
      assertEquals(0, tobj.getValueCount());
   }
View Full Code Here


   }

   public void testTransformMessageCollection()
   {
      // build source message
      TransferObject msg = new TransferObject("TransformTestMsg", 1);
      TransferObject msg1 = null;
      TransferObject msg2 = null;
      ArrayList col = null;
      ArrayList col1 = null;
     
      msg1 = new TransferObject(1);
      col = new ArrayList(2);
      msg2 = new TransferObject(1);
      msg2.setValue("primitive", new Integer(10));
      col.add(msg2);
      msg2 = new TransferObject(1);
      msg2.setValue("primitive", new Integer(20));
      col.add(msg2);
      msg1.setValue("messageCollection", col);
      msg.setValue("message", msg1);
     
      col = new ArrayList(2);
      msg1 = new TransferObject(2);
      msg2 = new TransferObject(1);
      msg2.setValue("primitive", new Integer(30));
      msg1.setValue("message", msg2);
      col1 = new ArrayList(2);
      msg2 = new TransferObject(1);
      msg2.setValue("primitive", new Integer(40));
      col1.add(msg2);
      msg2 = new TransferObject(1);
      msg2.setValue("primitive", new Integer(50));
      col1.add(msg2);
      msg1.setValue("messageCollection", col1);
      col.add(msg1);
     
      msg1 = new TransferObject(2);
      msg2 = new TransferObject(1);
      msg2.setValue("primitive", new Integer(60));
      msg1.setValue("message", msg2);
      col1 = new ArrayList(2);
      msg2 = new TransferObject(1);
      msg2.setValue("primitive", new Integer(70));
      col1.add(msg2);
      msg2 = new TransferObject(1);
      msg2.setValue("primitive", new Integer(80));
      col1.add(msg2);
      msg1.setValue("messageCollection", col1);
      col.add(msg1);
     
      msg.setValue("messageCollection", col);
     
      Logger logger = Logger.getLogger("TransformerTest");
     
      logger.info("source: " + msg.toString());
     
      // transform message
      TransferObject res = m_tf.transform(msg, m_metadata.getTransformation("MapMessageCollection"));

      logger.info("result: " + res.toString());
     
      // validate result message
      assertEquals("TransformTestMsg", res.getClassName());
      assertEquals(2, res.getValueCount());
     
      msg = (TransferObject)res.getValue("message");
      assertEquals(2, msg.getValueCount());
     
      msg1 = (TransferObject)msg.getValue("message");
      assertEquals(1, msg1.getValueCount());
      assertEquals(new Integer(20), msg1.getValue("primitive"));
     
      col = (ArrayList)msg.getValue("messageCollection");
      assertEquals(3, col.size());
      msg1 = (TransferObject)col.get(0);
      assertEquals(1, msg1.getValueCount());
      assertEquals(new Integer(10), msg1.getValue("primitive"));
      msg1 = (TransferObject)col.get(1);
      assertEquals(1, msg1.getValueCount());
      assertEquals(new Integer(10), msg1.getValue("primitive"));
      msg1 = (TransferObject)col.get(2);
      assertEquals(1, msg1.getValueCount());
      assertEquals(new Integer(20), msg1.getValue("primitive"));
     
      col = (ArrayList)res.getValue("messageCollection");
      assertEquals(2, col.size());
      msg1 = (TransferObject)col.get(0);
      assertEquals(2, msg1.getValueCount());
      msg2 = (TransferObject)msg1.getValue("message");
      assertEquals(1, msg2.getValueCount());
View Full Code Here

      assertEquals(new Integer(60), msg2.getValue("primitive"));
   }
  
   public void testTransformMessagesToStrings()
   {
      TransferObject msg = new TransferObject("MsgCol", 2);
      TransferObject tobj = new TransferObject(2);

      tobj.setValue("s", "q");
      tobj.setValue("n", new Integer(1));

      msg.setValue("a", tobj);

      tobj = new TransferObject(2);

      tobj.setValue("s", "r");
      tobj.setValue("n", new Integer(2));
     
      msg.setValue("b", tobj);

      TransferObject res = m_tf.transform(msg, m_metadata.getTransformation("2MsgToPrimitiveCol"));

      assertEquals("MsgPrimitiveCol", res.getClassName());
      assertEquals(1, res.getValueCount());
     
      List list = (List)res.getValue("c");

      assertEquals(2, list.size());

      tobj = (TransferObject)list.get(0);
View Full Code Here

      assertEquals("r", tobj.getValue("s"));
   }

   public void testHealthCareUseCase()
   {
      TransferObject msg = new TransferObject("HL7_25_ADT_A04");
      TransferObject pid = new TransferObject(3);

      msg.setValue("patientIdentification", pid);

      List idList = new ArrayList(2);

      pid.setValue("patientIdentifierList", idList);

      TransferObject id = new TransferObject(2);

      id.setValue("idNumber", "1234567890");
     
      TransferObject auth = new TransferObject(1);

      auth.setValue("universalId", "OHIP");

      id.setValue("assigningAuthority", auth);

      idList.add(id);

      id = new TransferObject(2);
     
      id.setValue("idNumber", "234567890");
     
      auth = new TransferObject(1);

      auth.setValue("universalId", "SIN");

      id.setValue("assigningAuthority", auth);

      idList.add(id);

      List nameList = new ArrayList(1);
     
      pid.setValue("patientName", nameList);
     
      TransferObject name = new TransferObject(4);

      name.setValue("givenName", "Joe");
      name.setValue("initials", "F.");
      name.setValue("degree", "Ph.D.");

      TransferObject family = new TransferObject(1);

      family.setValue("surname", "Test");
      name.setValue("familyName", family);
     
      nameList.add(name);

      TransferObject dob = new TransferObject(1);

      dob.setValue("time", new Timestamp(100000));
      pid.setValue("dateTimeOfBirth", dob);
      pid.setValue("administrativeSex", "N");
     
      List addressList = new ArrayList(2);
     
      pid.setValue("patientAddress", addressList);

      TransferObject address = new TransferObject();
      TransferObject street = new TransferObject(1);

      street.setValue("streetAddress", "123 45th St.");
      address.setValue("streetAddress", street);

      address.setValue("otherDesignation", "#456");
      address.setValue("city", "Toronto");
      address.setValue("state", "ON");
      address.setValue("zip", "A1B 2C3");
      address.setValue("country", "Canada");
      address.setValue("addressType", "B");

      addressList.add(address);

      address = new TransferObject();
      street = new TransferObject(1);

      street.setValue("streetAddress", "789 Geek Blvd.");
      address.setValue("streetAddress", street);

      address.setValue("otherDesignation", "basement");
      address.setValue("city", "Richmond Hill");
      address.setValue("state", "ON");
      address.setValue("zip", "M4N 4H5");
      address.setValue("country", "Canada");
      address.setValue("addressType", "H");

      addressList.add(address);

      List phoneList = new ArrayList(2);
      TransferObject phone = new TransferObject(2);

      phone.setValue("telephoneNumber", "(905) 123-4567");
      phone.setValue("emailAddress", "jtest@yahoo.ca");
      phoneList.add(phone);

      phone = new TransferObject(2);

      phone.setValue("telephoneNumber", "(905) 765-4321");
      phone.setValue("emailAddress", "haxx0r16@yahoo.ca");
      phoneList.add(phone);

      pid.setValue("phoneNumberHome", phoneList);

      phoneList = new ArrayList(2);
      phone = new TransferObject(2);

      phone.setValue("telephoneNumber", "(416) 123-4567");
      phone.setValue("emailAddress", "jtest@dot.com");
      phoneList.add(phone);

      phone = new TransferObject(2);

      phone.setValue("telephoneNumber", "(416) 765-4321");
      phone.setValue("emailAddress", "joe.test@dot.com");
      phoneList.add(phone);

      pid.setValue("phoneNumberBusiness", phoneList);
     
      Logger.getLogger(TransformerTest.class).info("src" + msg.toString());

      TransferObject res = m_tf.transform(msg, m_metadata.getTransformation("HL7_25_ADT_A04_Object_PatientDemographics"));

      Logger.getLogger(TransformerTest.class).info("dst" + res.toString());

     
      assertEquals("Object_PatientDemographics", res.getClassName());
      assertEquals(1, res.getValueCount());

      TransferObject player = (TransferObject)res.getValue("player");

      assertEquals(11, player.getValueCount());

      assertEquals("Joe", player.getValue("firstName"));
      assertEquals("F.", player.getValue("initials"));
      assertEquals("Test", player.getValue("lastName"));
      assertEquals("Test, Joe", player.getValue("fullName"));
      assertEquals("Ph.D.", player.getValue("title"));
      assertEquals("Ph.D.", player.getValue("affix"));
      assertEquals(new Timestamp(100000), player.getValue("birthTime"));

      // Validate ids
     
      List list = (List)player.getValue("ids");

      assertEquals(2, list.size());

      TransferObject tobj = (TransferObject)list.get(0);

      assertEquals(2, tobj.getValueCount());
      assertEquals("OHIP", tobj.getValue("type"));
      assertEquals("1234567890", tobj.getValue("id"));

      tobj = (TransferObject)list.get(1);

      assertEquals(2, tobj.getValueCount());
      assertEquals("SIN", tobj.getValue("type"));
      assertEquals("234567890", tobj.getValue("id"));

      // Validate addrs
     
      list = (List)player.getValue("addrs");

      assertEquals(2, list.size());

      tobj = (TransferObject)list.get(0);

      assertEquals(7, tobj.getValueCount());
      assertEquals("Toronto", tobj.getValue("city"));
      assertEquals("123 45th St.", tobj.getValue("address1"));
      assertEquals("#456", tobj.getValue("address2"));
      assertEquals("ON", tobj.getValue("state"));
      assertEquals("Canada", tobj.getValue("country"));
      assertEquals("A1B 2C3", tobj.getValue("zip"));

      tobj = (TransferObject)tobj.getValue("type");

      assertEquals(1, tobj.getValueCount());
     
      tobj = (TransferObject)tobj.getValue("useCodes");
     
      assertEquals(1, tobj.getValueCount());
      assertEquals("WP", tobj.getValue("code"));

      tobj = (TransferObject)list.get(1);

      assertEquals(7, tobj.getValueCount());
      assertEquals("Richmond Hill", tobj.getValue("city"));
      assertEquals("789 Geek Blvd.", tobj.getValue("address1"));
      assertEquals("basement", tobj.getValue("address2"));
      assertEquals("ON", tobj.getValue("state"));
      assertEquals("Canada", tobj.getValue("country"));
      assertEquals("M4N 4H5", tobj.getValue("zip"));

      tobj = (TransferObject)tobj.getValue("type");

      assertEquals(1, tobj.getValueCount());
     
      tobj = (TransferObject)tobj.getValue("useCodes");
     
      assertEquals(1, tobj.getValueCount());
      assertEquals("HP", tobj.getValue("code"));
     
      // Validate telcoms
     
      list = (List)player.getValue("telcoms");

      assertEquals(6, list.size());

      tobj = (TransferObject)list.get(0);
      assertEquals(2, tobj.getValueCount());
      assertEquals("(905) 123-4567", tobj.getValue("address"));

      tobj = (TransferObject)tobj.getValue("type");
      assertEquals(1, tobj.getValueCount());

      List list2 = (List)tobj.getValue("useCodes");

      assertEquals(1, list2.size());

      tobj = (TransferObject)list2.get(0);
      assertEquals(1, tobj.getValueCount());
      assertEquals("HP", tobj.getValue("code"));


      tobj = (TransferObject)list.get(1);
      assertEquals(2, tobj.getValueCount());
      assertEquals("jtest@yahoo.ca", tobj.getValue("address"));

      tobj = (TransferObject)tobj.getValue("type");
      assertEquals(1, tobj.getValueCount());

      list2 = (List)tobj.getValue("useCodes");
      assertEquals(1, list2.size());

      tobj = (TransferObject)list2.get(0);
      assertEquals(1, tobj.getValueCount());
      assertEquals("EMAIL", tobj.getValue("code"));

     
      tobj = (TransferObject)list.get(2);
      assertEquals(2, tobj.getValueCount());
      assertEquals("(905) 765-4321", tobj.getValue("address"));

      tobj = (TransferObject)tobj.getValue("type");
      assertEquals(1, tobj.getValueCount());

      list2 = (List)tobj.getValue("useCodes");
      assertEquals(1, list2.size());

      tobj = (TransferObject)list2.get(0);
      assertEquals(1, tobj.getValueCount());
      assertEquals("HP", tobj.getValue("code"));
     
     
      tobj = (TransferObject)list.get(3);
      assertEquals(2, tobj.getValueCount());
      assertEquals("haxx0r16@yahoo.ca", tobj.getValue("address"));

      tobj = (TransferObject)tobj.getValue("type");
      assertEquals(1, tobj.getValueCount());

      list2 = (List)tobj.getValue("useCodes");
      assertEquals(1, list2.size());

      tobj = (TransferObject)list2.get(0);
      assertEquals(1, tobj.getValueCount());
      assertEquals("EMAIL", tobj.getValue("code"));
     
     
      tobj = (TransferObject)list.get(4);
      assertEquals(2, tobj.getValueCount());
      assertEquals("(416) 123-4567", tobj.getValue("address"));

      tobj = (TransferObject)tobj.getValue("type");
      assertEquals(1, tobj.getValueCount());

      list2 = (List)tobj.getValue("useCodes");
      assertEquals(1, list2.size());

      tobj = (TransferObject)list2.get(0);
      assertEquals(1, tobj.getValueCount());
      assertEquals("WP", tobj.getValue("code"));
     
     
      tobj = (TransferObject)list.get(5);
      assertEquals(2, tobj.getValueCount());
      assertEquals("(416) 765-4321", tobj.getValue("address"));

      tobj = (TransferObject)tobj.getValue("type");
      assertEquals(1, tobj.getValueCount());

      list2 = (List)tobj.getValue("useCodes");
      assertEquals(1, list2.size());

      tobj = (TransferObject)list2.get(0);
      assertEquals(1, tobj.getValueCount());
      assertEquals("WP", tobj.getValue("code"));

      // Validate genderCode
     
      tobj = (TransferObject)player.getValue("genderCode");

      assertEquals(1, tobj.getValueCount());
      assertEquals("N", tobj.getValue("value"));
   }
View Full Code Here

      m_xsdMapBasic.put(XML.NS_URI_XML, XML_NAMESPACE_URL);
      m_xsdMapBasic.put(XML.ENV_URI, m_tmpSOAPXSD.toURL());

      m_request = new Request();

      TransferObject contact = new TransferObject();

      contact.setOID(new OID(new Object[]{"123"}));

      // make sure not to be same as an existing metaclass,
      // otherwise only metaclass fields are valid
      contact.setClassName("Contact-test");

      contact.setEventName("update");
      contact.setVersion((short)12345);
      contact.setValue("firstName", "Java");
      contact.setValue("lastName", "Kava");
      contact.setValue("null", null);
      contact.setValue("self", contact);
      contact.setValue("integer", new Integer(1));
      contact.setValue("long", new Long(2));
      contact.setValue("float", new Float(0.625f));
      contact.setValue("double", new Double(1.625));
      contact.setValue("decimal", new BigDecimal("1.2345"));
      contact.setValue("timestamp", new Timestamp(12345));
      contact.setValue("boolean", Boolean.TRUE);
      contact.setValue("binary", new Binary(new byte[]{1, 2, 3, 4, 5}));
      contact.setValue("binary2", new Binary(new byte[]{1, 2, 3, 4, 5, 6, 7}));
      contact.setValue("binary3", new Binary(new byte[]{1, 2}));
      contact.setValue("symbol", Symbol.define("sym"));
      contact.setValue("pair", new Pair("A", new Pair("B")));
      contact.setValue("cvector", new char[]{'a', 'b', 'c'});
      contact.setValue("bvector", new byte[]{0, (byte)0xAB, 0x12});
      contact.setValue("svector", new String[]{"a", "b", "c"});
      contact.setValue("vector", new Object[]{"a", "b", "c"});
      contact.setValue("function", new PCodeFunction(new char[]{0, 1, 2}, new Object[]{"abc"}));
      contact.setValue("macro", new PCodeMacro(new char[]{3, 4, 5}, new Object[]{"cde"}, null));

      PrivilegeSet privilegeSet = Repository.getMetadata().createPrivilegeSet();

      privilegeSet.add(Repository.getMetadata().getPrimitivePrivilege("updateContact"));
      privilegeSet.add(Repository.getMetadata().getPrimitivePrivilege("WorkflowManage"));
      contact.setValue("privilegeSet", privilegeSet);

      ArrayList addressList = new ArrayList();
     
      TransferObject address = new TransferObject();
      address.setOID(new OID(new Object[]{"456"}));

      // make sure not to be same as an existing metaclass,
      // otherwise only metaclass fields are valid
      address.setClassName("Address-test");

      address.setEventName("update");
      address.setValue("country", "Canada");
      address.setValue("self", address);
      address.setValue("contact", contact);
      address.setValue("symbol", Symbol.define("sym"));
      addressList.add(address);
     
      address = new TransferObject();
      address.setOID(new OID(new Object[]{"789"}));

      // make sure not to be same as an existing metaclass,
      // otherwise only metaclass fields are valid
      address.setClassName("Address-test");

      address.setEventName("new");
      address.setValue("country", "USA");
      address.setValue("contact", contact);
      addressList.add(address);
     
      contact.setValue("addresses", addressList);

      m_request.setNamespace("http://www.nexjsystems.com/ns/test");
View Full Code Here

    * Tests formatting of a message with vCard v2.1 settings.
    */
   public void testFormatV21Message() throws Exception
   {
      Message message = Repository.getMetadata().getMessage("VCard_v21");
      TransferObject root = new TransferObject("VCard_v21");
      TransferObject tobj;

      root.setValue("fullName", "Sherlock Holmes");
      root.setValue("END", "vCard");

      ArrayList companyInfo = new ArrayList(2);

      companyInfo.add("NexJ Systems Inc.");
      companyInfo.add("R&D");
      root.setValue("company", companyInfo);

      tobj = new TransferObject();
      root.setValue("telephone", tobj);
      tobj.setValue("number", "555-1234");

      ArrayList valList = new ArrayList();
      ArrayList p1List = new ArrayList();
      ArrayList p2List = new ArrayList();

      tobj = new TransferObject();
      root.setValue("collection", tobj);
      tobj.setValue("value", valList);
      tobj.setValue("p1", p1List);
      tobj.setValue("p2", p2List);
      valList.add("abc");
      valList.add("def");
      valList.add("g,hi");
      p1List.add(Primitive.createInteger(1));
      p1List.add(Primitive.createInteger(1));
      p1List.add(Primitive.createInteger(2));
      p1List.add(Primitive.createInteger(3));
      p1List.add(Primitive.createInteger(5));
      p1List.add(Primitive.createInteger(8));
      p2List.add(Primitive.createInteger(0));
      tobj.setValue("p4", "123;456:789");

      tobj = new TransferObject();
      root.setValue("logicalGrouping", tobj);
      tobj.setValue("TEL", "555-0000");
      tobj.setValue("NOTE", "Evenings and weekends only.");

      ArrayList containedSimpleNameList = new ArrayList();

      tobj = new TransferObject();
      root.setValue("containedVCardSimple", tobj);
      tobj.setValue("N", containedSimpleNameList);
      containedSimpleNameList.add("Watson");
      containedSimpleNameList.add("");
      containedSimpleNameList.add("");
      containedSimpleNameList.add("Dr.");

      tobj = new TransferObject();
      root.setValue("containedVCardRef", tobj);
      tobj.setValue("fullName", "Moriarty");

      ArrayList telephonesList = new ArrayList();

      root.setValue("telephones", telephonesList);
      tobj = new TransferObject();
      telephonesList.add(tobj);
      tobj.setValue("number", "This is a really long line....12345678941234567895123456789612345678971234567 89");
      tobj = new TransferObject();
      telephonesList.add(tobj);
      tobj.setValue("number", "(416) 967-1111");
      tobj.setValue("kind", "PIZZA");

      ArrayList addressList = new ArrayList(1);
      ArrayList addressInfoList = new ArrayList(7);

      root.setValue("addresses", addressList);
      tobj = new TransferObject(2);
      addressList.add(tobj);
      tobj.setValue("address", addressInfoList);
      addressInfoList.add(0, null);
      addressInfoList.add(1, null);
      addressInfoList.add(2, "4101 Yonge Street\r\nUnit 501");
      addressInfoList.add(3, "North York");
      addressInfoList.add(4, "ON");
      addressInfoList.add(5, "111111");
      addressInfoList.add(6, "Canada");
      tobj.setValue("type", "WORK");

      tobj = new TransferObject(1);
      root.setValue("logo", tobj);
      tobj.setValue("data", Binary.parse("313233414243"));

      tobj = new TransferObject(1);
      root.setValue("trueName", tobj);
      tobj.setValue("name", "Pr\u00E6tor");

      tobj = new TransferObject(1);
      root.setValue("assistant1", tobj);
      tobj.setValue("card", tobj = new TransferObject(1));
      tobj.setValue("FN", "Dr. John H. Watson");

      tobj = new TransferObject(1);
      root.setValue("assistant2", tobj);
      tobj.setValue("card", tobj = new TransferObject(1));
      tobj.setValue("fullName", "Sir Arthur Conan Doyle");

      m_formatter.format(root, message, new WriterOutput(m_writer));
      assertEquals("BEGIN:VCARD\r\n" +
            "VERSION:2.1\r\n" +
            "FN:Sherlock Holmes\r\n" +
            "ORG:NexJ Systems Inc.;R&D\r\n" +
            "TEL;TYPE=VOICE:555-1234\r\n" +
            "X-NexJ-Collection;p1=1,1,2,3,5,8;p2=0;p3=4,9,16;p4=123\\;456\\:789:abc,def,g\\,hi\r\n" +
            "Home.TEL:555-0000\r\n" +
            "Home.NOTE:Evenings and weekends only.\r\n" +
            "BEGIN:VCARD_CONTAINED\r\n" +
            "VERSION:2.1\r\n" +
            "N:Watson,,,Dr.\r\n" +
            "END:VCARD_CONTAINED\r\n" +
            "BEGIN:VCARD\r\n" +
            "VERSION:2.1\r\n" +
            "FN:Moriarty\r\n" +
            "END:VCARD\r\n" +
            "TEL;TYPE=VOICE:This is a really long\r\n" +
            " line....12345678941234567895123456789612345678971234567 89\r\n" +
            "TEL;TYPE=PIZZA:(416) 967-1111\r\n" +
            "ADR;TYPE=WORK;ENCODING=QUOTED-PRINTABLE:;;4101 Yonge Street=0D=0AUnit 501;N=\r\n" +
            "orth York;ON;111111;Canada\r\n" +
            "LOGO;TYPE=PNG;ENCODING=BASE64:MTIzQUJD\r\n" +
            "\r\n" +
            "X-NexJ-IntlName;CHARSET=ISO-8859-1;ENCODING=QUOTED-PRINTABLE:Pr=E6tor\r\n" +
            "AGENT;NUM=1:BEGIN:VCARD\r\n" +
            "VERSION:2.1\r\n" +
            "FN:Dr. John H. Watson\r\n" +
            "END:VCARD\r\n" +
            "AGENT;NUM=2:BEGIN:VCARD\r\n" +
            "VERSION:2.1\r\n" +
            "FN:Sir Arthur Conan Doyle\r\n" +
            "END:VCARD\r\n" +
            "END:vCard\r\n",
            m_writer.toString());

      try
      {
         companyInfo.add("extra");
         m_writer = new StringWriter();
         m_formatter.format(root, message, new WriterOutput(m_writer));
         fail();
      }
      catch (IntegrationException ex)
      {
         assertEquals("err.integration.maxPartCount", ex.getErrorCode());
         assertEquals("VCard_v21 company", ex.getErrorArgs()[0]);
      }
      finally
      {
         companyInfo.remove(2);
      }

      try
      {
         p2List.add(Primitive.createInteger(42));
         p2List.add(Primitive.createInteger(21));
         m_writer = new StringWriter();
         m_formatter.format(root, message, new WriterOutput(m_writer));
         fail();
      }
      catch (IntegrationException ex)
      {
         assertEquals("err.integration.maxPartCount", ex.getErrorCode());
         assertEquals("VCard_v21 collection p2", ex.getErrorArgs()[0]);
      }
      finally
      {
         p2List.remove(2);
         p2List.remove(1);
      }

      try
      {
         root.removeValue("fullName");
         m_writer = new StringWriter();
         m_formatter.format(root, message, new WriterOutput(m_writer));
         fail();
      }
      catch (IntegrationException ex)
      {
         assertEquals("err.integration.minPartCount", ex.getErrorCode());
         assertEquals("VCard_v21 fullName", ex.getErrorArgs()[0]);
      }
      finally
      {
         root.setValue("fullName", "Sherlock Holmes");
      }

      try
      {
         valList.remove(2);
         m_writer = new StringWriter();
         m_formatter.format(root, message, new WriterOutput(m_writer));
         fail();
      }
      catch (IntegrationException ex)
      {
         assertEquals("err.integration.minPartCount", ex.getErrorCode());
         assertEquals("VCard_v21 collection value", ex.getErrorArgs()[0]);
      }
      finally
      {
         valList.add("ghi");
      }

      try
      {
         tobj = (TransferObject)root.getValue("collection");
         tobj.removeValue("value");
         m_writer = new StringWriter();
         m_formatter.format(root, message, new WriterOutput(m_writer));
         fail();
      }
      catch (IntegrationException ex)
      {
         assertEquals("err.integration.minPartCount", ex.getErrorCode());
         assertEquals("VCard_v21 collection value", ex.getErrorArgs()[0]);
      }
      finally
      {
         tobj.setValue("value", valList);
      }

      try
      {
         tobj = (TransferObject)root.getValue("collection");
         tobj.removeValue("p1");
         m_writer = new StringWriter();
         m_formatter.format(root, message, new WriterOutput(m_writer));
         fail();
      }
      catch (IntegrationException ex)
      {
         assertEquals("err.integration.minPartCount", ex.getErrorCode());
         assertEquals("VCard_v21 collection p1", ex.getErrorArgs()[0]);
      }
      finally
      {
         tobj.setValue("p1", p1List);
      }
   }
View Full Code Here

    * Tests formatting of a message with vCard v3.0 settings.
    */
   public void testFormatV30Message() throws Exception
   {
      Message message = Repository.getMetadata().getMessage("VCard_v30");
      TransferObject root = new TransferObject("VCard_v30");
      TransferObject tobj;

      root.setValue("fullName", "Sherlock Holmes");
      root.setValue("END", "vCard");

      ArrayList companyInfo = new ArrayList(2);

      companyInfo.add("NexJ Systems Inc.");
      companyInfo.add("R&D");
      root.setValue("company", companyInfo);

      ArrayList telephonesList = new ArrayList();

      root.setValue("telephones", telephonesList);
      tobj = new TransferObject();
      telephonesList.add(tobj);
      tobj.setValue("number", "This is a really long line....12345678941234567895123456789612345678971234567 89");
      tobj = new TransferObject();
      telephonesList.add(tobj);
      tobj.setValue("number", "(416) 967-1111");
      tobj.setValue("kind", "PIZZA");

      tobj = new TransferObject(1);
      root.setValue("logo", tobj);
      tobj.setValue("data", Binary.parse("313233414243000000000000000000000000000000000000000000000000000000000000"));

      tobj = new TransferObject(1);
      root.setValue("trueName", tobj);
      tobj.setValue("name", "Pr\u00E6tor");

      root.setValue("assistant1", "BEGIN:VCARD\r\nFN:Joe Friday\r\n" +
            "TEL:+1-919-555-7878\r\nTITLE:Area Administrator, Assistant\r\nEND:VCARD\r\n");

      m_formatter.format(root, message, new WriterOutput(m_writer));
View Full Code Here

      m_message = Repository.getMetadata().getMessage("Zip_AllMapped");
   }

   public void testFormat() throws Exception
   {
      TransferObject root = new TransferObject("Zip_AllMapped", 1);
      List entryList = new ArrayList(4);
      TransferObject entry;

      root.setValue("files", entryList);

      entry = new TransferObject(2);
      entry.setValue("fileName", "cat.txt");
      entry.setValue("data", new Binary("This is what should go in CAT.".getBytes("UTF-8")));
      entryList.add(entry);

      entry = new TransferObject(1);
      entry.setValue("fileName", "toy/");
      entryList.add(entry);

      entry = new TransferObject(2);
      entry.setValue("data", new Binary("This file has no name.".getBytes("UTF-8")));
      entry.setValue("comments", "This entry will not be written.");
      entryList.add(entry);

      entry = new TransferObject(3);
      entry.setValue("fileName", "toy/ball.txt");
      entry.setValue("data", new Binary("This is the cat's ball-toy.".getBytes("UTF-8")));
      entry.setValue("comments", "A toy");
      entryList.add(entry);

      // Format and check result
      ByteArrayOutputStream ostream = new ByteArrayOutputStream();
View Full Code Here

      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);
View Full Code Here

   }

   public void testSerializeTransferObject() throws IOException
   {
      Request request = new Request();
      TransferObject tobj = new TransferObject();
      List/*<String>*/ list = new ArrayList/*<String>*/(3);

      list.add("name1");
      list.add("name2");
      list.add("name3");
      tobj.setClassName("User");
      tobj.setValue("firstName", "fName");
      tobj.setValue("names", list);
      request.setVersion("0");
      request.addInvocation(tobj);
      m_marshaller.serialize(request, m_writer);
      XMLUtil.parse(new StringReader(m_writer.toString()), m_xsdMap); // validate to XSD

      request = (Request)m_unmarshaller.deserialize(new StringReader(m_writer.toString()));

      TransferObject processed = request.getObject(0);

      assertEquals(tobj.getClassName(), processed.getClassName());
      assertEquals(tobj.getValueCount(), processed.getValueCount());
      assertEquals(tobj.getValue("firstName"), processed.getValue("firstName"));

      Object names = processed.getValue("names");

      assertTrue(names instanceof List);
      assertEquals(list.size(), ((List)names).size());
      assertEquals(list.get(0), ((List)names).get(0));
      assertEquals(list.get(1), ((List)names).get(1));
View Full Code Here

TOP

Related Classes of nexj.core.rpc.TransferObject$Iterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.