Package org.jboss.seam.remoting

Examples of org.jboss.seam.remoting.CallContext


   @Test
   public void testBagWrapper() throws Exception
   {
      BagWrapper wrapper = new BagWrapper();
      wrapper.setCallContext(new CallContext());

      String[] values = new String[2];
      values[0] = "foo";
      values[1] = "bar";
View Full Code Here


   @Test
   public void testMapWrapper() throws Exception
   {
      MapWrapper wrapper = new MapWrapper();
      wrapper.setCallContext(new CallContext());

      // Construct a map with two elements, foo:aaaaa and bar:zzzzz
      Element e = DocumentFactory.getInstance().createElement("map");
      Element child = e.addElement("element");
      child.addElement("k").addElement("str").addText("foo");
      child.addElement("v").addElement("str").addText("aaaaa");
      child = e.addElement("element");
      child.addElement("k").addElement("str").addText("bar");
      child.addElement("v").addElement("str").addText("zzzzz");

      wrapper.setElement(e);

      // Conversion tests
      Map m = (Map) wrapper.convert(Map.class);
      assert m.containsKey("foo");
      assert m.containsKey("bar");
      assert "aaaaa".equals(m.get("foo"));
      assert "zzzzz".equals(m.get("bar"));

      m = (Map) wrapper.convert(HashMap.class);
      assert m.containsKey("foo");
      assert m.containsKey("bar");
      assert "aaaaa".equals(m.get("foo"));
      assert "zzzzz".equals(m.get("bar"));

      Type t = RemotingTest.class.getMethod("dummyMap").getGenericReturnType();
      m = (Map) wrapper.convert(t);
      assert m.containsKey("foo");
      assert m.containsKey("bar");
      assert "aaaaa".equals(m.get("foo"));
      assert "zzzzz".equals(m.get("bar"));

      try
      {
         // This should throw a ConversionException
         wrapper.convert(InvalidClass.class);
         assert false;
      }
      catch (ConversionException ex)
      {
      }

      try
      {
         // This should throw a ConversionException also
         wrapper.convert(InvalidMap.class);
         assert false;
      }
      catch (ConversionException ex)
      {
      }

      // ensure when we marshal/unmarshal the values in the map remain the same     
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      wrapper.marshal(out);
     
      SAXReader xmlReader = new SAXReader();
      Document doc = xmlReader.read( new ByteArrayInputStream(out.toByteArray()) );    
     
      Element root = doc.getRootElement();     
     
      MapWrapper other = new MapWrapper();
      other.setCallContext(new CallContext());
      other.setElement(root);
     
      Map otherMap = (Map) other.convert(Map.class);
      for (Object key : otherMap.keySet())
      {
View Full Code Here

  
   public Model(BeanManager beanManager)
   {
      this.beanManager = beanManager;
      id = UUID.randomUUID().toString();
      callContext = new CallContext(beanManager);
      beanProperties = new HashMap<String, BeanProperty>();
   }
View Full Code Here

   @Test
   public void testBagWrapper() throws Exception
   {
      BagWrapper wrapper = new BagWrapper();
      wrapper.setCallContext(new CallContext());

      String[] values = new String[2];
      values[0] = "foo";
      values[1] = "bar";
View Full Code Here

   @Test
   public void testMapWrapper() throws Exception
   {
      MapWrapper wrapper = new MapWrapper();
      wrapper.setCallContext(new CallContext());

      // Construct a map with two elements, foo:aaaaa and bar:zzzzz
      Element e = DocumentFactory.getInstance().createElement("map");
      Element child = e.addElement("element");
      child.addElement("k").addElement("str").addText("foo");
View Full Code Here

         ByteArrayOutputStream out = new ByteArrayOutputStream();

         // Constrain a single field of the result
         List<String> constraints = Arrays.asList(new String[] { "secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         SAXReader xmlReader = new SAXReader();
         Document doc = xmlReader.read(new StringReader(new String(out
               .toByteArray())));

         Widget widget = (Widget) ParserUtils.unmarshalResult(doc
               .getRootElement());

         // value field should equal "foo"
         assert "foo".equals(widget.getValue());

         // secret field should be null
         assert widget.getSecret() == null;

         // Now extend our object graph a little further
         result.setChild(new Widget());
         result.getChild().setValue("foo");
         result.getChild().setSecret("bar");

         // Reset our output stream so we can re-use it
         out.reset();

         // Now we're going to constrain result.child's secret field
         constraints = Arrays.asList(new String[] { "child.secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         assert "foo".equals(widget.getValue());
         assert "bar".equals(widget.getSecret());
         assert "foo".equals(widget.getChild().getValue());
         assert widget.getChild().getSecret() == null;

         // Add a map to our result
         result.setWidgetMap(new HashMap<String, Widget>());
         Widget val = new Widget();
         val.setValue("foo");
         val.setSecret("bar");
         result.getWidgetMap().put("foo", val);

         // Reset our output stream again
         out.reset();

         // Constrain the "secret" field of the widgetMap map's values (sounds
         // confusing, I know...)
         constraints = Arrays
               .asList(new String[] { "widgetMap[value].secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         val = widget.getWidgetMap().get("foo");
         assert val != null;
         assert "foo".equals(val.getValue());
         assert val.getSecret() == null;

         // Reset our output stream
         out.reset();

         // Add a list to our result
         result.setWidgetList(new ArrayList<Widget>());
         Widget item = new Widget();
         item.setValue("foo");
         item.setSecret("bar");
         result.getWidgetList().add(item);

         // Constraint the "secret" field of widgetList
         constraints = Arrays.asList(new String[] { "widgetList.secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         item = widget.getWidgetList().get(0);
         assert item != null;
         assert "foo".equals(item.getValue());
         assert item.getSecret() == null;

         // Reset our output stream
         out.reset();

         // Now constrain all secrets
         constraints = Arrays
               .asList(new String[] { "[" + Widget.class.getName() + "].secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
View Full Code Here

  public static Object unmarshalResult(Element resultElement)
  {
    Element valueElement = resultElement.element("value");
    Element refsElement = resultElement.element("refs");

    CallContext ctx = new CallContext();

    Iterator iter = refsElement.elementIterator("ref");
    while (iter.hasNext())
    {
      ctx.createWrapperFromElement((Element) iter.next());
    }

    Wrapper resultWrapper = ctx.createWrapperFromElement((Element) valueElement.elementIterator().next());

    // Now unmarshal the ref values
    for (Wrapper w : ctx.getInRefs().values())
      w.unmarshal();

    return resultWrapper.getValue();
  }
View Full Code Here

   @Test
   public void testBagWrapper() throws Exception
   {
      BagWrapper wrapper = new BagWrapper();
      wrapper.setCallContext(new CallContext());

      String[] values = new String[2];
      values[0] = "foo";
      values[1] = "bar";
View Full Code Here

   @Test
   public void testMapWrapper() throws Exception
   {
      MapWrapper wrapper = new MapWrapper();
      wrapper.setCallContext(new CallContext());

      // Construct a map with two elements, foo:aaaaa and bar:zzzzz
      Element e = DocumentFactory.getInstance().createElement("map");
      Element child = e.addElement("element");
      child.addElement("k").addElement("str").addText("foo");
View Full Code Here

         ByteArrayOutputStream out = new ByteArrayOutputStream();

         // Constrain a single field of the result
         List<String> constraints = Arrays.asList(new String[] { "secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         SAXReader xmlReader = new SAXReader();
         Document doc = xmlReader.read(new StringReader(new String(out
               .toByteArray())));

         Widget widget = (Widget) ParserUtils.unmarshalResult(doc
               .getRootElement());

         // value field should equal "foo"
         assert "foo".equals(widget.getValue());

         // secret field should be null
         assert widget.getSecret() == null;

         // Now extend our object graph a little further
         result.setChild(new Widget());
         result.getChild().setValue("foo");
         result.getChild().setSecret("bar");

         // Reset our output stream so we can re-use it
         out.reset();

         // Now we're going to constrain result.child's secret field
         constraints = Arrays.asList(new String[] { "child.secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         assert "foo".equals(widget.getValue());
         assert "bar".equals(widget.getSecret());
         assert "foo".equals(widget.getChild().getValue());
         assert widget.getChild().getSecret() == null;

         // Add a map to our result
         result.setWidgetMap(new HashMap<String, Widget>());
         Widget val = new Widget();
         val.setValue("foo");
         val.setSecret("bar");
         result.getWidgetMap().put("foo", val);

         // Reset our output stream again
         out.reset();

         // Constrain the "secret" field of the widgetMap map's values (sounds
         // confusing, I know...)
         constraints = Arrays
               .asList(new String[] { "widgetMap[value].secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         val = widget.getWidgetMap().get("foo");
         assert val != null;
         assert "foo".equals(val.getValue());
         assert val.getSecret() == null;

         // Reset our output stream
         out.reset();

         // Add a list to our result
         result.setWidgetList(new ArrayList<Widget>());
         Widget item = new Widget();
         item.setValue("foo");
         item.setSecret("bar");
         result.getWidgetList().add(item);

         // Constraint the "secret" field of widgetList
         constraints = Arrays.asList(new String[] { "widgetList.secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
         item = widget.getWidgetList().get(0);
         assert item != null;
         assert "foo".equals(item.getValue());
         assert item.getSecret() == null;

         // Reset our output stream
         out.reset();

         // Now constrain all secrets
         constraints = Arrays
               .asList(new String[] { "[org.jboss.seam.test.Widget].secret" });
         MarshalUtils.marshalResult(null, new CallContext(), out, result,
               constraints);

         doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
         widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
View Full Code Here

TOP

Related Classes of org.jboss.seam.remoting.CallContext

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.