Package nexj.core.integration.io

Examples of nexj.core.integration.io.StringInput


    * Test parsing messages and sub-messages with value parts.
    */
   public void testParseValueParts() throws Exception
   {
      // Parent - hex value part
      StringInput in = new StringInput(XML_HEADER +
         "<referrer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
         "<name>123</name>" +
         "<reference>" +
            "<a>Avalue</a>" +
            "<b>17</b>" +
            "313233" +
         "</reference>" +
         "</referrer>");
      TransferObject root = m_parser.parse(in, m_referrerMessage);
      TransferObject ref;

      assertEquals("XML_Inherit_Parent_Referrer", root.getClassName());
      assertEquals("123", root.getValue("name"));
      ref = (TransferObject)root.getValue("ref");
      assertEquals("XML_Inherit_Parent", ref.getClassName());
      assertEquals("Avalue", ref.getValue("a"));
      assertEquals(Primitive.createInteger(17), ref.getValue("b"));
      assertEquals(Binary.fromBase64("MTIz"), ref.getValue("value"));

      // Child2 - base64 value part
      in = new StringInput(XML_HEADER +
         "<referrer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
         "<name>123</name>" +
         "<reference xsi:type=\"Child2Type\">" +
            "<a>Avalue</a>" +
            "<b>Bvalue</b>" +
            "MTIz" +
         "</reference>" +
         "</referrer>");
      root = m_parser.parse(in, m_referrerMessage);

      assertEquals("XML_Inherit_Parent_Referrer", root.getClassName());
      assertEquals("123", root.getValue("name"));
      ref = (TransferObject)root.getValue("ref");
      assertEquals("XML_Inherit_Child2", ref.getClassName());
      assertEquals("Avalue", ref.getValue("a"));
      assertEquals("Bvalue", ref.getValue("b"));
      assertEquals(Binary.parse("313233"), ref.getValue("value"));

      // Child4 - xsd:anyType value part (with interface)
      in = new StringInput(XML_HEADER +
         "<referrer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
         "<name>123</name>" +
         "<reference xsi:type=\"Child4Type\">" +
            "<a>Avalue</a>" +
            "<b>Bvalue</b>" +
            "<internationalPrice currency=\"CNY\">8.00</internationalPrice>" +
         "</reference>" +
         "</referrer>");
      root = m_parser.parse(in, m_referrerMessage);

      assertEquals("XML_Inherit_Parent_Referrer", root.getClassName());
      assertEquals("123", root.getValue("name"));
      ref = (TransferObject)root.getValue("ref");
      assertEquals("XML_Inherit_Child4", ref.getClassName());
      assertEquals("Avalue", ref.getValue("a"));
      assertEquals("Bvalue", ref.getValue("b"));
      ref = (TransferObject)ref.getValue("value");
      assertEquals("XML_InternationalPrice", ref.getClassName());
      assertEquals("CNY", ref.getValue("currency"));
      assertEquals(800, ((BigDecimal)ref.getValue("price")).multiply(new BigDecimal(100)).intValueExact());

      // Child4Child - xsd:anyType value part (without interface)
      in = new StringInput(XML_HEADER +
         "<referrer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
         "<name>123</name>" +
         "<reference xsi:type=\"Child4ChildType\">" +
            "<a>Avalue</a>" +
            "<b>Bvalue</b>" +
View Full Code Here


      table.addMessage(msg3);
      table.addMessage(msgp);
      m_parser.initializeMessageTable(table);

      // Parse child1
      root = m_parser.parse(new StringInput(
         "<child1>" +
            "<b>23</b>" +
            "<c1>31</c1>" +
         "</child1>"), table);

      assertEquals("XML_Inherit_Child1", root.getClassName());
      assertEquals(Primitive.createInteger(23), root.getValue("b"));
      assertEquals(Primitive.createInteger(31), root.getValue("c1"));

      // Parse child2
      root = m_parser.parse(new StringInput(
         "<child2>" +
            "<a>Avalue</a>" +
            "<b>Bvalue</b>" +
         "</child2>"), table);

      assertEquals("XML_Inherit_Child2", root.getClassName());
      assertEquals("Avalue", root.getValue("a"));
      assertEquals("Bvalue", root.getValue("b"));

      // Cannot parse child3 on its own. (it has same root element name as its parent)

      // Parse parent
      root = m_parser.parse(new StringInput(
         "<parent>" +
            "<a>Avalue</a>" +
            "<b>11</b>" +
         "</parent>"), table);

      assertEquals("XML_Inherit_Parent", root.getClassName());
      assertEquals("Avalue", root.getValue("a"));
      assertEquals(Primitive.createInteger(11), root.getValue("b"));

      // Parse parent/child1
      root = m_parser.parse(new StringInput(
         "<parent xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"Child1Type\">" +
            "<b>23</b>" +
            "<c1>31</c1>" +
         "</parent>"), table);

      assertEquals("XML_Inherit_Child1", root.getClassName());
      assertEquals(Primitive.createInteger(23), root.getValue("b"));
      assertEquals(Primitive.createInteger(31), root.getValue("c1"));

      // Parse parent/child2
      root = m_parser.parse(new StringInput(
         "<parent xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"Child2Type\">" +
            "<a>Avalue</a>" +
            "<b>Bvalue</b>" +
         "</parent>"), table);

      assertEquals("XML_Inherit_Child2", root.getClassName());
      assertEquals("Avalue", root.getValue("a"));
      assertEquals("Bvalue", root.getValue("b"));

      // Parse parent/child3
      root = m_parser.parse(new StringInput(
         "<parent xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"Child3Type\">" +
            "<a>Avalue</a>" +
            "<b>Bvalue</b>" +
         "</parent>"), table);
View Full Code Here

   /**
    * Tests parsing of a message that is missing a reference whose min count is 1.
    */
   public void testParseMissingReference()
   {
      StringInput in = new StringInput(XML_HEADER +
         "<referrer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
         "<name>123</name>" +
         "</referrer>");

      try
View Full Code Here

    * Test that parser enforces sequential aggregation on a message, and
    * that it allows random aggregation on that message's sub-message.
    */
   public void testParseParentUsesSequentialAggregation()
   {
      StringInput in = new StringInput(XML_HEADER +
         "<referrer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
         "<name>123</name>" +
         "<reference xsi:type=\"ParentType\">" +
            "<b>17</b>" +
            "<a>Avalue</a>" +
         "</reference>" +
         "</referrer>");

      try
      {
         m_parser.parse(in, m_referrerMessage);
         fail("Expected IntegrationException");
      }
      catch (IntegrationException ex)
      {
         assertEquals("err.integration.xml.invalidElement", ex.getErrorCode());
         assertEquals("a", ex.getErrorArgs()[1]);
      }

      // Test random aggregation on a sub-message
      in = new StringInput(XML_HEADER +
         "<referrer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
         "<name>123</name>" +
         "<reference xsi:type=\"Child1Type\">" +
            "<c1>31</c1>" +
            "<b>23</b>" +
View Full Code Here

    */
   public void testParseDocRootNameDoesNotFunctionLikeXSIType()
   {
      Message msgChild1 = m_context.getMetadata().getMessage("XML_Inherit_Child1");
      Message msgParent = m_context.getMetadata().getMessage("XML_Inherit_Parent");
      StringInput in;

      // Child1 is not polymorphic.
      in = new StringInput(XML_HEADER +
         "<child1child>" +
            "<b>23</b>" +
            "<c1>31</c1>" +
            "<c1c>C1Cvalue</c1c>" +
         "</child1child>");

      try
      {
         m_parser.parse(in, msgChild1);
         fail("Expected IntegrationException");
      }
      catch (IntegrationException ex)
      {
         assertEquals("err.integration.xml.invalidDocRoot", ex.getErrorCode());
         assertEquals("child1child", ex.getErrorArgs()[1]);
      }

      // Parent is polymorphic--but still xsi:type is needed.
      in = new StringInput(XML_HEADER +
         "<child1>" +
            "<b>23</b>" +
            "<c1>31</c1>" +
         "</child1>");

View Full Code Here

   public void testParseSchemaInherited()
   {
      Message msg1 = m_context.getMetadata().getMessage("XML_Inherit_Schema1");
      Message msg2 = m_context.getMetadata().getMessage("XML_Inherit_Schema2");
      Message msg3 = m_context.getMetadata().getMessage("XML_Inherit_Schema3");
      StringInput in;
      TransferObject root;

      // Valid root message
      in = new StringInput(
         "<ns:schema1" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>Hi</a>" +
         "</ns:schema1>");

      root = m_parser.parse(in, msg1);
      assertEquals("XML_Inherit_Schema1", root.getClassName());
      assertEquals("Hi", root.getValue("a"));

      // Invalid root message
      in = new StringInput(
         "<ns:schema1" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>Hi</a>" +
            "<b>there!</b>" +
         "</ns:schema1>");

      try
      {
         m_parser.parse(in, msg1);
         fail("Expected IntegrationException");
      }
      catch (IntegrationException ex)
      {
      }

      // Valid sub-message (parsed directly)
      in = new StringInput(
         "<ns:schema2" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>Hi</a>" +
            "<b>there!</b>" +
         "</ns:schema2>");

      root = m_parser.parse(in, msg2);
      assertEquals("XML_Inherit_Schema2", root.getClassName());
      assertEquals("Hi", root.getValue("a"));
      assertEquals("there!", root.getValue("b"));

      // Invalid sub-message (parsed directly)
      in = new StringInput(
         "<ns:schema2" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>Hi</a>" +
            "<b>there!</b>" +
            "<c>bye</c>" +
         "</ns:schema2>");

      try
      {
         m_parser.parse(in, msg2);
         fail("Expected IntegrationException");
      }
      catch (IntegrationException ex)
      {
         XMLParserException cause = (XMLParserException)ex.getCause();

         assertEquals("err.xml.parser", cause.getErrorCode());
      }

      // Valid sub-message (parsed through inheritance)
      in = new StringInput(
         "<ns:schema1 xsi:type=\"ns:Schema2Type\"" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>2Hi</a>" +
            "<b>2there!</b>" +
         "</ns:schema1>");

      root = m_parser.parse(in, msg1);
      assertEquals("XML_Inherit_Schema2", root.getClassName());
      assertEquals("2Hi", root.getValue("a"));
      assertEquals("2there!", root.getValue("b"));

      // Invalid sub-message (parsed through inheritance)
      in = new StringInput(
         "<ns:schema1 xsi:type=\"ns:Schema2Type\"" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>Hi</a>" +
            "<b>there!</b>" +
            "<c>bye</c>" +
         "</ns:schema1>");

      try
      {
         m_parser.parse(in, msg1);
         fail("Expected IntegrationException");
      }
      catch (IntegrationException ex)
      {
         XMLParserException cause = (XMLParserException)ex.getCause();

         assertEquals("err.xml.parser", cause.getErrorCode());
      }

      // Valid sub-sub-message in different schema (direct)
      in = new StringInput(
         "<ns3:schema3" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:ns3=\"urn:com.nexjsystems:ns:test:inherit:schema3\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>3Hi</a>" +
            "<b>3there!</b>" +
            "<cReal>bye</cReal>" +
         "</ns3:schema3>");

      root = m_parser.parse(in, msg3);
      assertEquals("XML_Inherit_Schema3", root.getClassName());
      assertEquals("3Hi", root.getValue("a"));
      assertEquals("3there!", root.getValue("b"));
      assertEquals("bye", root.getValue("cReal"));

      // Invalid sub-sub-message in different schema (direct)
      in = new StringInput(
         "<ns3:schema3" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:ns3=\"urn:com.nexjsystems:ns:test:inherit:schema3\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>3Hi</a>" +
            "<b>3there!</b>" +
            "<cReal>bye</cReal>" +
            "<x>bad</x>" +
         "</ns3:schema3>");

      try
      {
         m_parser.parse(in, msg3);
         fail("Expected IntegrationException");
      }
      catch (IntegrationException ex)
      {
         XMLParserException cause = (XMLParserException)ex.getCause();

         assertEquals("err.xml.parser", cause.getErrorCode());
      }

      // Valid sub-sub-message in different schema (inheritance)
      in = new StringInput(
         "<ns:schema1 xsi:type=\"ns3:Schema3Type\"" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:ns3=\"urn:com.nexjsystems:ns:test:inherit:schema3\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>4Hi</a>" +
            "<b>4there!</b>" +
            "<cReal>2bye</cReal>" +
         "</ns:schema1>");

      root = m_parser.parse(in, msg1);
      assertEquals("XML_Inherit_Schema3", root.getClassName());
      assertEquals("4Hi", root.getValue("a"));
      assertEquals("4there!", root.getValue("b"));
      assertEquals("2bye", root.getValue("cReal"));

      // Invalid sub-sub-message in different schema (inheritance)
      in = new StringInput(
         "<ns:schema1 xsi:type=\"ns3:Schema3Type\"" +
            " xmlns:ns=\"urn:com.nexjsystems:ns:test:inherit:schema1\"" +
            " xmlns:ns3=\"urn:com.nexjsystems:ns:test:inherit:schema3\"" +
            " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
            "<a>4Hi</a>" +
View Full Code Here

         "</anyTypeElementCompCollection> " +
         "<anyTypeElementCompCollection attribute=\"" + sQuotedMarkup + "\">   " +
         sMarkup +
         "   </anyTypeElementCompCollection></XMLAnyTest>";

      TransferObject msg = m_parser.parse(new StringInput(sMessage), m_message);
      List list, subList;

      assertEquals(" abc " + sMarkup + " 123 ", msg.getValue("anyTypeElement"));
      list = (List)msg.getValue("anyTypeElementCollection");
      assertEquals(1, list.size());
View Full Code Here

         sMarkup +
         " <after>post</after> " +
         " <subInterface>   " + sMarkup + " </subInterface> " +
         "</anyInterfaceElementComp> </XMLAnyTest>";

      TransferObject msg = m_parser.parse(new StringInput(sMessage), m_message);
      TransferObject subMsg = (TransferObject)msg.getValue("anyInterfaceElement");
      List list;

      assertEquals("XML_InternationalPrice", subMsg.getClassName());
      assertEquals("CNY", subMsg.getValue("currency"));
View Full Code Here

         " <before>pre</before> " +
         sMarkup + " " + sMarkup2 +
         " <after>post</after> " +
         "</anyInterfaceElementCompCollection> </XMLAnyTest>";

      TransferObject msg = m_parser.parse(new StringInput(sMessage), m_message);
      TransferObject subMsg;
      List list, subList;

      list = (List)msg.getValue("anyInterfaceElementCompCollection");
      assertEquals(2, list.size());
View Full Code Here

         "<anyTypeElementCollectionTyped xsi:nil=\"1\"/>" +
         "<anyTypeElementCollectionTyped xsi:type=\"xsd:integer\"/>" +
         "<anyTypeElementCollectionTyped/>" +
         "</XMLAnyTest>";

      TransferObject msg = m_parser.parse(new StringInput(sMessage), m_message);
      List list = (List)msg.getValue("anyTypeElementCollectionTyped");

      assertEquals(7, list.size());

      assertEquals("5 < 4", list.get(0));
View Full Code Here

TOP

Related Classes of nexj.core.integration.io.StringInput

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.