[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/aop/jdom ...

Ben Wang bwang at jboss.com
Thu Aug 10 12:12:41 EDT 2006


  User: bwang   
  Date: 06/08/10 12:12:41

  Added:       tests/functional/org/jboss/cache/aop/jdom    Tag:
                        JBossCache_1_4_JDOM ReplicatedTest.java
                        TestDocument.java XPathTest.java
  Log:
  JBCACHE-733
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +302 -0    JBossCache/tests/functional/org/jboss/cache/aop/jdom/Attic/ReplicatedTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ReplicatedTest.java
  ===================================================================
  RCS file: ReplicatedTest.java
  diff -N ReplicatedTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ReplicatedTest.java	10 Aug 2006 16:12:41 -0000	1.1.2.1
  @@ -0,0 +1,302 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +
  +package org.jboss.cache.aop.jdom;
  +
  +import junit.framework.TestCase;
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.aop.NewReplicatedAopTest;
  +import org.jboss.cache.aop.PojoCache;
  +import org.jboss.cache.aop.test.Person;
  +import org.jboss.cache.PropertyConfigurator;
  +import org.jdom.Element;
  +import org.jdom.Document;
  +import org.jdom.output.XMLOutputter;
  +import org.jdom.output.Format;
  +
  +import javax.naming.Context;
  +import java.util.Properties;
  +import java.util.List;
  +
  +/**
  + *
  + * @author Ben Wang
  + */
  +
  +public class ReplicatedTest extends TestCase
  +{
  +   Log log_= LogFactory.getLog(ReplicatedTest.class);
  +   PojoCache cache_;
  +   PojoCache cache1_;
  +
  +   public ReplicatedTest(String name)
  +   {
  +      super(name);
  +   }
  +
  +   protected void setUp() throws Exception
  +   {
  +      super.setUp();
  +      Properties prop = new Properties();
  +      prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
  +      cache_ = new PojoCache();
  +      PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache.
  +      config.configure(cache_, "META-INF/replSync-service.xml");
  +
  +      cache1_ = new PojoCache();
  +      config.configure(cache1_, "META-INF/replSync-service.xml");
  +      cache_.start();
  +      cache1_.start();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      super.tearDown();
  +      cache_.remove("/");
  +      cache_.stop();
  +      cache1_.stop();
  +   }
  +
  +   public void testSimple() throws Exception
  +   {
  +      Element root = new Element("Root");
  +      Document doc = new Document(root);
  +      root.setText("This is a root element");
  +
  +      Element child1 = new Element("firstChild").setText("I'm number one");
  +
  +      // Add the kids
  +      root.addContent(child1);
  +
  +      XMLOutputter out = new XMLOutputter();
  +
  +      out.output(doc, System.out);
  +
  +      assertEquals("doc size ", 1, doc.getContentSize());
  +
  +      cache_.putObject("/jdom/doc", doc);
  +//      System.out.println("*********");
  +//      System.out.println(cache_.printDetails());
  +//      System.out.println("*********");
  +   }
  +
  +   public void testSimple1() throws Exception
  +   {
  +      Element root = new Element("Root");
  +      Document doc = new Document(root);
  +      root.setText("This is a root element");
  +
  +      Element child1 = new Element("firstChild").setText("I'm number one");
  +      Element child2 = new Element("secondChild").setText("I'm number two");
  +
  +      // Add the kids
  +      root.addContent(child1);
  +      root.addContent(child2);
  +
  +      XMLOutputter out = new XMLOutputter();
  +
  +      out.output(doc, System.out);
  +
  +      assertEquals("doc size ", 1, doc.getContentSize());
  +      assertEquals("children size ", 2, doc.getRootElement().getChildren().size());
  +
  +      cache_.putObject("/jdom/doc", doc);
  +
  +      root.removeContent(child2);
  +      root.addContent(child2);
  +      cache_.removeObject("/jdom/doc");
  +   }
  +
  +
  +   public void testSimple2() throws Exception
  +   {
  +      Element root = new Element("Organization");
  +      Document doc = new Document(root);
  +      root.setText("Great OSS Company");
  +
  +      Element ben = new Element("Author").setText("Code author");
  +      root.addContent(ben);
  +      ben.addContent(new Element("Last").setText("Wang"));
  +      ben.addContent(new Element("First").setText("Ben"));
  +      ben.addContent(new Element("City").setText("Taipei"));
  +
  +      Element elynne = new Element("Author").setText("Cook book");
  +      root.addContent(elynne);
  +      elynne.addContent(new Element("Last").setText("Tei"));
  +      elynne.addContent(new Element("First").setText("Elynne"));
  +      elynne.addContent(new Element("City").setText("Taipei"));
  +
  +      assertEquals("doc size ", 1, doc.getContentSize());
  +      assertEquals("children size ", 2, doc.getRootElement().getChildren().size());
  +
  +      cache_.putObject("/jdom/doc", doc);
  +
  +      Document doc1 = (Document)cache1_.getObject("/jdom/doc");
  +
  +      Element kid = new Element("Author").setText("Powder");
  +      kid.addContent(new Element("Last").setText("Wang"));
  +      kid.addContent(new Element("First").setText("Ian"));
  +      kid.addContent(new Element("City").setText("Taipei"));
  +
  +      root.addContent(kid);
  +
  +      XMLOutputter out = new XMLOutputter();
  +      Format form = Format.getPrettyFormat();
  +      out.setFormat(form);
  +      out.output(doc1, System.out);
  +
  +      assertEquals("children size ", 3, doc.getRootElement().getChildren().size());
  +      assertEquals("children size ", 3, doc1.getRootElement().getChildren().size());
  +      cache_.removeObject("/jdom/doc");
  +   }
  +
  +   public void testRepl1() throws Exception
  +   {
  +      Element root = new Element("Root");
  +      Document doc = new Document(root);
  +      root.setText("This is a root element");
  +
  +      Element child1 = new Element("firstChild").setText("I'm number one");
  +      Element child2 = new Element("secondChild").setText("I'm number two");
  +
  +      // Add the kids
  +      root.addContent(child1);
  +      root.addContent(child2);
  +
  +      XMLOutputter out = new XMLOutputter();
  +
  +      List list = root.getChildren();
  +      Element child3 = new Element("thirdChild").setText("I'm number three");
  +      list.add(child3);
  +      out.output(doc, System.out);
  +
  +      assertEquals("doc size ", 1, doc.getContentSize());
  +
  +      cache_.putObject("/jdom/doc", doc);
  +//      System.out.println("*********");
  +//      System.out.println(cache_.printDetails());
  +//      System.out.println("*********");
  +
  +      Document doc1 = (Document)cache_.getObject("/jdom/doc");
  +      out.output(doc1, System.out);
  +      assertEquals("doc size ", 1, doc1.getContentSize());
  +      assertEquals("Children size ", 3, doc1.getRootElement().getChildren().size());
  +
  +      Element child4 = new Element("fourthChild").setText("I'm number four");
  +      list.add(child4);
  +      assertEquals("Children size ", 4, doc1.getRootElement().getChildren().size());
  +      cache_.removeObject("/jdom/doc");
  +
  +   }
  +
  +   public void testRepl2() throws Exception
  +   {
  +      Element root = new Element("Root");
  +      Document doc = new Document(root);
  +      root.setText("This is a root element");
  +
  +      Element child1 = new Element("firstChild").setText("I'm number one");
  +      Element child2 = new Element("secondChild").setText("I'm number two");
  +
  +      // Add the kids
  +      root.addContent(child1);
  +      root.addContent(child2);
  +
  +      XMLOutputter out = new XMLOutputter();
  +
  +      List list = root.getChildren();
  +      Element child3 = new Element("thirdChild").setText("I'm number three");
  +      list.add(child3);
  +      out.output(doc, System.out);
  +
  +      assertEquals("doc size ", 1, doc.getContentSize());
  +
  +      cache_.putObject("/jdom/doc", doc);
  +
  +      Document doc1 = (Document)cache_.getObject("/jdom/doc");
  +      out.output(doc1, System.out);
  +      assertEquals("doc size ", 1, doc1.getContentSize());
  +      assertEquals("Children size ", 3, doc1.getRootElement().getChildren().size());
  +
  +      Element child4 = new Element("fourthChild").setText("I'm number four");
  +      list.add(child4);
  +      assertEquals("Children size ", 4, doc1.getRootElement().getChildren().size());
  +
  +      list.remove(child4);
  +      assertEquals("Children size ", 3, doc1.getRootElement().getChildren().size());
  +      cache_.removeObject("/jdom/doc");
  +   }
  +
  +   public void testRepl3() throws Exception
  +   {
  +      Element root = new Element("Root");
  +      Document doc = new Document(root);
  +      root.setText("This is a root element");
  +
  +      Element child1 = new Element("firstChild").setText("I'm number one");
  +      Element child2 = new Element("secondChild").setText("I'm number two");
  +
  +      // Add the kids
  +      root.addContent(child1);
  +      root.addContent(child2);
  +
  +      XMLOutputter out = new XMLOutputter();
  +
  +      List list = root.getChildren();
  +      Element child3 = new Element("thirdChild").setText("I'm number three");
  +      list.add(child3);
  +      out.output(doc, System.out);
  +
  +      assertEquals("doc size ", 1, doc.getContentSize());
  +
  +      cache_.putObject("/jdom/doc", doc);
  +//      System.out.println("*********");
  +//      System.out.println(cache_.printDetails());
  +//      System.out.println("*********");
  +
  +      Document doc1 = (Document)cache_.getObject("/jdom/doc");
  +      out.output(doc1, System.out);
  +      assertEquals("doc size ", 1, doc1.getContentSize());
  +      assertEquals("Children size ", 3, doc1.getRootElement().getChildren().size());
  +
  +      Element child4 = new Element("fourthChild").setText("I'm number four");
  +      list.add(child4);
  +      assertEquals("Children size ", 4, doc1.getRootElement().getChildren().size());
  +
  +      list.remove(child4);
  +      assertEquals("Children size ", 3, doc1.getRootElement().getChildren().size());
  +
  +      String str = "Im a floating element";
  +      Element floating = new Element("floating").setText(str);
  +      list.add(1, floating);
  +      assertEquals("Children size ", 4, doc1.getRootElement().getChildren().size());
  +
  +      floating = (Element)list.remove(1);
  +      assertEquals("Children size ", 3, doc1.getRootElement().getChildren().size());
  +
  +      child1.addContent(floating);
  +      assertEquals("floating Text ", str,
  +              doc1.getRootElement().getChild("firstChild").getChild("floating").getText());
  +      cache_.removeObject("/jdom/doc");
  +
  +   }
  +
  +   public static Test suite() throws Exception
  +   {
  +      return new TestSuite(ReplicatedTest.class);
  +   }
  +
  +
  +   public static void main(String[] args) throws Exception
  +   {
  +      junit.textui.TestRunner.run(ReplicatedTest.suite());
  +   }
  +
  +}
  
  
  
  1.1.2.1   +138 -0    JBossCache/tests/functional/org/jboss/cache/aop/jdom/Attic/TestDocument.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TestDocument.java
  ===================================================================
  RCS file: TestDocument.java
  diff -N TestDocument.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ TestDocument.java	10 Aug 2006 16:12:41 -0000	1.1.2.1
  @@ -0,0 +1,138 @@
  +package org.jboss.cache.aop.jdom;
  +
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +import org.jdom.Comment;
  +import org.jdom.Document;
  +import org.jdom.Element;
  +import org.jdom.IllegalAddException;
  +import org.jdom.output.XMLOutputter;
  +
  +import java.util.ArrayList;
  +import java.util.List;
  +
  +public final class TestDocument
  +        extends junit.framework.TestCase
  +{
  +   /**
  +    * Construct a new instance.
  +    */
  +   public TestDocument(String name)
  +   {
  +      super(name);
  +   }
  +
  +   /**
  +    * The main method runs all the tests in the text ui
  +    */
  +   public static void main(String args[])
  +   {
  +      junit.textui.TestRunner.run(suite());
  +   }
  +
  +   /**
  +    * This method is called before a test is executed.
  +    */
  +   public void setUp()
  +   {
  +   }
  +
  +   /**
  +    * The suite method runs all the tests
  +    */
  +   public static Test suite()
  +   {
  +      TestSuite suite = new TestSuite(TestDocument.class);
  +      return suite;
  +   }
  +
  +   /**
  +    * This method is called after a test is executed.
  +    */
  +   public void tearDown()
  +   {
  +   }
  +
  +   public void testSimple() throws Exception
  +   {
  +      Element root = new Element("Root");
  +      Document doc = new Document(root);
  +      root.setText("This is a root element");
  +
  +      Element child1 = new Element("firstChild").setText("I'm number one");
  +      Element child2 = new Element("secondChild").setText("I'm number two");
  +
  +      // Add the kids
  +      root.addContent(child1);
  +      root.addContent(child2);
  +
  +      XMLOutputter out = new XMLOutputter();
  +      out.output(doc, System.out);
  +
  +      List list = root.getChildren();
  +      Element child3 = new Element("thirdChild").setText("I'm number three");
  +      list.add(child3);
  +      out.output(doc, System.out);
  +   }
  +
  +   /**
  +    * Test constructor of Document with a List of content including the root element.
  +    */
  +   public void testList()
  +   {
  +      Element bogus = new Element("bogus-root");
  +      Element element = new Element("element");
  +      Comment comment = new Comment("comment");
  +      List list = new ArrayList();
  +
  +      list.add(element);
  +      list.add(comment);
  +      Document doc = new Document(list);
  +      // Get a live list back
  +      list = doc.getContent();
  +      assertEquals("incorrect root element returned", element, doc.getRootElement());
  +
  +      //no root element
  +      element.detach();
  +      try
  +      {
  +         doc.getRootElement();
  +         fail("didn't catch missing root element");
  +      } catch (IllegalStateException e)
  +      {
  +      }
  +
  +      //set root back, then try to add another element to our
  +      //live list
  +      doc.setRootElement(element);
  +      try
  +      {
  +         list.add(bogus);
  +         fail("didn't catch duplicate root element");
  +      } catch (IllegalAddException e)
  +      {
  +      }
  +      assertEquals("incorrect root element returned", element, doc.getRootElement());
  +
  +      //and through the document
  +      try
  +      {
  +         doc.setRootElement(element);
  +      } catch (Exception e)
  +      {
  +         fail("Root replacement shouldn't have throw a exception");
  +      }
  +
  +      list = null;
  +      try
  +      {
  +         doc = new Document(list);
  +      } catch (IllegalAddException e)
  +      {
  +         fail("didn't handle null list");
  +      } catch (NullPointerException e)
  +      {
  +         fail("didn't handle null list");
  +      }
  +   }
  +}
  
  
  
  1.1.2.1   +167 -0    JBossCache/tests/functional/org/jboss/cache/aop/jdom/Attic/XPathTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: XPathTest.java
  ===================================================================
  RCS file: XPathTest.java
  diff -N XPathTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ XPathTest.java	10 Aug 2006 16:12:41 -0000	1.1.2.1
  @@ -0,0 +1,167 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +
  +package org.jboss.cache.aop.jdom;
  +
  +import junit.framework.TestCase;
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.aop.PojoCache;
  +import org.jboss.cache.PropertyConfigurator;
  +import org.jdom.Element;
  +import org.jdom.Document;
  +import org.jdom.xpath.XPath;
  +import org.jdom.output.XMLOutputter;
  +import org.jdom.output.Format;
  +
  +import javax.naming.Context;
  +import java.util.Properties;
  +import java.util.List;
  +
  +/**
  + *
  + * @author Ben Wang
  + */
  +
  +public class XPathTest extends TestCase
  +{
  +   Log log_= LogFactory.getLog(XPathTest.class);
  +   PojoCache cache_;
  +   PojoCache cache1_;
  +
  +   public XPathTest(String name)
  +   {
  +      super(name);
  +   }
  +
  +   protected void setUp() throws Exception
  +   {
  +      super.setUp();
  +      Properties prop = new Properties();
  +      prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
  +      cache_ = new PojoCache();
  +      PropertyConfigurator config = new PropertyConfigurator(); // configure tree cache.
  +      config.configure(cache_, "META-INF/replSync-service.xml");
  +
  +      cache1_ = new PojoCache();
  +      config.configure(cache1_, "META-INF/replSync-service.xml");
  +      cache_.start();
  +      cache1_.start();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      super.tearDown();
  +      cache_.remove("/");
  +      cache_.stop();
  +      cache1_.stop();
  +   }
  +
  +   public void testSimple1() throws Exception
  +   {
  +      Element root = new Element("Organization");
  +      Document doc = new Document(root);
  +      root.setText("Great OSS Company");
  +
  +      Element ben = new Element("Author").setText("Code author");
  +      root.addContent(ben);
  +      ben.addContent(new Element("Last").setText("Wang"));
  +      ben.addContent(new Element("First").setText("Ben"));
  +      ben.addContent(new Element("City").setText("Taipei"));
  +
  +      Element elynne = new Element("Author").setText("Cook book");
  +      root.addContent(elynne);
  +      elynne.addContent(new Element("Last").setText("Tei"));
  +      elynne.addContent(new Element("First").setText("Elynne"));
  +      elynne.addContent(new Element("City").setText("Taipei"));
  +
  +      assertEquals("doc size ", 1, doc.getContentSize());
  +      assertEquals("children size ", 2, doc.getRootElement().getChildren().size());
  +
  +      cache_.putObject("/jdom/doc", doc);
  +
  +      XPath apath = XPath.newInstance("//Author");
  +      List authors = apath.selectNodes(doc);
  +      assertEquals("List size ", 2, authors.size());
  +
  +      Element kid = new Element("Author").setText("Powder");
  +      kid.addContent(new Element("Last").setText("Wang"));
  +      kid.addContent(new Element("First").setText("Ian"));
  +      kid.addContent(new Element("City").setText("Taipei"));
  +
  +//      XMLOutputter out = new XMLOutputter();
  +//      Format form = Format.getPrettyFormat();
  +//      out.setFormat(form);
  +//      out.output(doc, System.out);
  +      assertEquals("children size ", 2, doc.getRootElement().getChildren().size());
  +
  +   }
  +
  +   public void testSimple2() throws Exception
  +   {
  +      Element root = new Element("Organization");
  +      Document doc = new Document(root);
  +      root.setText("Great OSS Company");
  +
  +      Element ben = new Element("Author").setText("Code author");
  +      root.addContent(ben);
  +      ben.addContent(new Element("Last").setText("Wang"));
  +      ben.addContent(new Element("First").setText("Ben"));
  +      ben.addContent(new Element("City").setText("Taipei"));
  +
  +      Element elynne = new Element("Author").setText("Cook book");
  +      root.addContent(elynne);
  +      elynne.addContent(new Element("Last").setText("Tei"));
  +      elynne.addContent(new Element("First").setText("Elynne"));
  +      elynne.addContent(new Element("City").setText("Taipei"));
  +
  +      assertEquals("doc size ", 1, doc.getContentSize());
  +      assertEquals("children size ", 2, doc.getRootElement().getChildren().size());
  +
  +      cache_.putObject("/jdom/doc", doc);
  +
  +      XPath apath = XPath.newInstance("//Author");
  +      List authors = apath.selectNodes(doc);
  +      assertEquals("List size ", 2, authors.size());
  +
  +      Document doc1 = (Document)cache1_.getObject("/jdom/doc");
  +      authors = apath.selectNodes(doc1);
  +      assertEquals("List size ", 2, authors.size());
  +
  +      Element kid = new Element("Author").setText("Powder");
  +      kid.addContent(new Element("Last").setText("Wang"));
  +      kid.addContent(new Element("First").setText("Ian"));
  +      kid.addContent(new Element("City").setText("Taipei"));
  +
  +      root.addContent(kid);
  +
  +//      XMLOutputter out = new XMLOutputter();
  +//      Format form = Format.getPrettyFormat();
  +//      out.setFormat(form);
  +//      out.output(doc, System.out);
  +      assertEquals("children size ", 3, doc.getRootElement().getChildren().size());
  +      assertEquals("children size ", 3, doc1.getRootElement().getChildren().size());
  +
  +      authors = apath.selectNodes(doc1);
  +      assertEquals("List size ", 3, authors.size());
  +
  +   }
  +
  +   public static Test suite() throws Exception
  +   {
  +      return new TestSuite(XPathTest.class);
  +   }
  +
  +
  +   public static void main(String[] args) throws Exception
  +   {
  +      junit.textui.TestRunner.run(XPathTest.suite());
  +   }
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list