Package nexj.core.rpc

Examples of nexj.core.rpc.MockServer


         + "\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><objects x" + "si:type=\"User\"><"
         + XML.BASE_PREFIX + "oid>10e8359492f25f4be49109b9979e684ff3</" + XML.BASE_PREFIX
         + "oid><" + XML.BASE_PREFIX + "event>welcome</" + XML.BASE_PREFIX
         + "event><fullName>fullname</fullName></objects><attributes>(password)</" + "attributes></Change-Request>");
      XMLChangeRequest changeRequest = (XMLChangeRequest)unmarshaller.deserialize(reader);
      MockServer server = new MockServer();

      changeRequest.invoke(server);

      Request request = server.getRequest();
      Request.Invocation action = request.getInvocation(0);

      assertEquals(1, request.getInvocationCount());
      assertNull(action.getEventName());
      assertEquals("User", request.getObject(0).getClassName());
View Full Code Here


         .getMachine().getGlobalEnvironment());
      StringReader reader = new StringReader("<Read-Request xmlns=\"" + XML.NS_URI_TNS + "\">"
         + "<class>User-test</class><attributes>(fullName)</attributes>"
         + "<where></where><orderBy></orderBy><count>8</count><offset>0</offset></Read-Request>");
      XMLReadRequest readRequest = (XMLReadRequest)unmarshaller.deserialize(reader);
      MockServer server = new MockServer(new Object[1]);

      readRequest.invoke(server);

      Request request = server.getRequest();
      Request.Invocation action = request.getInvocation(0);

      assertEquals(1, request.getInvocationCount());
      assertEquals("User-test", request.getObject(0).getClassName());
      assertNull(request.getObject(0).getEventName());
View Full Code Here

         + "\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><objects x" + "si:type=\"User\"><"
         + XML.BASE_PREFIX + "oid>10e8359492f25f4be49109b9979e684ff3</" + XML.BASE_PREFIX
         + "oid><" + XML.BASE_PREFIX + "event>welcome</" + XML.BASE_PREFIX
         + "event><fullName>fullname</fullName></objects><attributes>(password)</" + "attributes></User-Change-Request>");
      XMLChangeRequest changeRequest = (XMLChangeRequest)unmarshaller.deserialize(reader);
      MockServer server = new MockServer();

      changeRequest.invoke(server);

      Request request = server.getRequest();
      Request.Invocation action = request.getInvocation(0);

      assertEquals(1, request.getInvocationCount());
      assertEquals("User", request.getObject(0).getClassName());
      assertEquals("welcome", request.getObject(0).getEventName());
View Full Code Here

         .getMachine().getGlobalEnvironment());
      StringReader reader = new StringReader("<User-Read-Request xmlns=\"" + XML.NS_URI_TNS + "\"><class>User-test</class>"
         + "<attributes>(fullName)</attributes><where></where><orderBy></orderBy><count>8</count>"
         + "<offset>0</offset></User-Read-Request>");
      XMLReadRequest readRequest = (XMLReadRequest)unmarshaller.deserialize(reader);
      MockServer server = new MockServer(new Object[1]);

      readRequest.invoke(server);

      Request request = server.getRequest();
      Request.Invocation action = request.getInvocation(0);

      assertEquals(1, request.getInvocationCount());
      assertEquals("User-test", request.getObject(0).getClassName());
      assertNull(request.getObject(0).getEventName());
View Full Code Here

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

         + "\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><objects xsi:type=\"User\"><"
         + XML.BASE_PREFIX + "oid>10e8359492f25f4be49109b9979e684ff3</" + XML.BASE_PREFIX
         + "oid><" + XML.BASE_PREFIX + "event>welcome</" + XML.BASE_PREFIX
         + "event><name>fullname</name></objects><attributes>(e privilegeSet name)</attributes></Change-Request>"));

      m_marshaller.serialize(request.invoke(new MockServer(response)), writer);
      XMLUtil.parse(new StringReader(writer.toString()), m_xsdMap); // validate to XSD

      Node root = XMLUtil.parse(new StringReader(writer.toString())).getFirstChild();

      assertEquals(XML.BASE_PREFIX + "Change-Response", root.getNodeName());
      assertEquals(1, root.getChildNodes().getLength());
      assertEquals("item", root.getChildNodes().item(0).getNodeName());
      assertEquals(1, root.getChildNodes().item(0).getAttributes().getLength());
      assertEquals("User",
                   root
                      .getChildNodes()
                         .item(0)
                            .getAttributes()
                               .getNamedItem(XML.XSI_NS + ":type")
                                  .getNodeValue());
      assertEquals(6, root.getChildNodes().item(0).getChildNodes().getLength());

      assertNotNull(XMLUtil.findChildElement(root.getChildNodes().item(0),
                                             XML.BASE_PREFIX + "oid"));
      assertNotNull(XMLUtil.findChildElement(root.getChildNodes().item(0),
                                             XML.BASE_PREFIX + "version"));
      assertEquals("e",
                   XMLUtil
                      .findChildElement(root.getChildNodes().item(0),
                                        XML.BASE_PREFIX + "keys")
                         .getTextContent());
      assertEquals(XML.XSD_NS + ":double",
                   XMLUtil
                      .findChildElement(root.getChildNodes().item(0),
                                        XML.BASE_PREFIX + "values")
                         .getAttributes()
                            .getNamedItem(XML.XSI_NS + ":type")
                               .getNodeValue());
      assertEquals("2.71828183",
                   XMLUtil
                      .findChildElement(root.getChildNodes().item(0),
                                        XML.BASE_PREFIX + "values")
                         .getTextContent());
      assertEquals(XML.XSD_NS + ":int",
                   XMLUtil
                      .findChildElement(root.getChildNodes().item(0), "privilegeSet")
                         .getAttributes()
                            .getNamedItem(XML.XSI_NS + ":type")
                               .getNodeValue());
      assertEquals("42",
                   XMLUtil
                      .findChildElement(root.getChildNodes().item(0), "privilegeSet")
                         .getTextContent());
      assertEquals("Name",
                   XMLUtil.findChildElement(root.getChildNodes().item(0), "name").getTextContent());

      writer.getBuffer().setLength(0);
      request = (XMLChangeRequest)unmarshaller.deserialize(new StringReader("<User-Change-Request xmlns=\"" + XML.NS_URI_TNS
         + "\"><objects><" + XML.BASE_PREFIX + "oid>10e8359492f25f4be49109b9979e684ff3</"
         + XML.BASE_PREFIX + "oid><" + XML.BASE_PREFIX + "event>welcome</"
         + XML.BASE_PREFIX + "event><name>fullname</name></objects><attributes>(e privilegeSet name)</attributes></User-Change-Request>"));
      m_marshaller.serialize(request.invoke(new MockServer(response)), writer);
      XMLUtil.parse(new StringReader(writer.toString()), m_xsdMapBasic); // validate to XSD
      root = XMLUtil.parse(new StringReader(writer.toString())).getFirstChild();

      assertEquals(XML.BASE_PREFIX + "User-Change-Response", root.getNodeName());
      assertEquals(1, root.getChildNodes().getLength());
View Full Code Here

      tobj.setValue("firstName", "FName");
      tobj.setValue("name", "fullName");
      response.addResult(tobj);
      XMLChangeRequest request = (XMLChangeRequest)unmarshaller.deserialize(reader);

      m_marshaller.serialize(request.invoke(new MockServer(response)), writer);
      XMLUtil.parse(new StringReader(writer.toString()), m_xsdMap); // validate to XSD

      Node root = XMLUtil.parse(new StringReader(writer.toString())).getFirstChild();

      assertEquals(XML.BASE_PREFIX + "Change-Response", root.getNodeName());
View Full Code Here

      tobj.setValue("fullName", "FName");
      tobj.setValue("name", null);
      response.addResult(Arrays.asList(new Object[]{tobj}));
      XMLReadRequest request = (XMLReadRequest)unmarshaller.deserialize(reader);

      m_marshaller.serialize(request.invoke(new MockServer(response)), writer);
      XMLUtil.parse(new StringReader(writer.toString()), m_xsdMap); // validate to XSD

      Node root = XMLUtil.parse(new StringReader(writer.toString())).getFirstChild();

      assertEquals(XML.BASE_PREFIX + "Read-Response", root.getNodeName());
View Full Code Here

      tobj.setValue("fullName", "FName");
      tobj.setValue("name", "Name");
      response.addResult(tobj);
      XMLChangeRequest request = (XMLChangeRequest)unmarshaller.deserialize(reader);

      m_marshaller.serialize(request.invoke(new MockServer(response)), writer);
      XMLUtil.parse(new StringReader(writer.toString()), m_xsdMapBasic); // validate to XSD

      Node root = XMLUtil.parse(new StringReader(writer.toString())).getFirstChild();

      assertEquals(XML.BASE_PREFIX + "Principal-Change-Response", root.getNodeName());
View Full Code Here

      tobj.setValue("fullName", "FName");
      tobj.setValue("name", "Name");
      response.addResult(Arrays.asList(new Object[]{tobj}));
      XMLReadRequest request = (XMLReadRequest)unmarshaller.deserialize(reader);

      m_marshaller.serialize(request.invoke(new MockServer(response)), writer);
      XMLUtil.parse(new StringReader(writer.toString()), m_xsdMapBasic); // validate to XSD

      Node root = XMLUtil.parse(new StringReader(writer.toString())).getFirstChild();

      assertEquals(XML.BASE_PREFIX + "Principal-Read-Response", root.getNodeName());
View Full Code Here

TOP

Related Classes of nexj.core.rpc.MockServer

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.