[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/pojo/util ...

Ben Wang bwang at jboss.com
Sat Jan 13 10:55:11 EST 2007


  User: bwang   
  Date: 07/01/13 10:55:11

  Added:       tests/functional/org/jboss/cache/pojo/util  
                        ObjectUtilTest.java MethodCallTest.java
  Log:
  JBCACHE-922 Merged src-50 and tests-50 into src and tests, respectively.
  
  Revision  Changes    Path
  1.1      date: 2007/01/13 15:55:11;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/util/ObjectUtilTest.java
  
  Index: ObjectUtilTest.java
  ===================================================================
  package org.jboss.cache.pojo.util;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.pojo.PojoCache;
  import org.jboss.cache.pojo.PojoCacheFactory;
  import org.jboss.cache.pojo.impl.PojoCacheImpl;
  import org.jboss.cache.pojo.test.NodeManager;
  import org.jboss.cache.pojo.test.TestNode;
  
  
  /**
   * Test case for ObjectUtil
   *
   * @author Ben Wang
   */
  
  public class ObjectUtilTest extends TestCase
  {
     Log log_ = LogFactory.getLog(ObjectUtilTest.class);
     PojoCache cache_;
  
     public ObjectUtilTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log_.info("setUp() ....");
        String configFile = "META-INF/local-service.xml";
        boolean toStart = false;
        cache_ = PojoCacheFactory.createCache(configFile, toStart);
        cache_.start();
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
        cache_.stop();
     }
  
  //   public void testDummy() {}
  
     public void testIsReachable() throws Exception
     {
        log_.info("testIsReachable() ....");
        NodeManager pm_ = new NodeManager();
  
        pm_.setRootNode("root");
        pm_.addNode("root", "kanto");
        pm_.addNode("root.kanto", "tokyo");
        pm_.addNode("root.kanto", "yakahoma");
        pm_.addNode("root.kanto.tokyo", "handanshita");
  
        TestNode kanto = pm_.findNode("root.kanto");
        TestNode yakahoma = pm_.findNode("root.kanto.yakahoma");
        TestNode hadanshita = pm_.findNode("root.kanto.tokyo.handanshita");
  
        pm_ = new NodeManager();
        pm_.setRootNode("rt");
        pm_.addNode("rt", "test");
        TestNode test = pm_.findNode("rt.test");
  
  //      cache_.putObject("/pm", pm_);
  
        assertTrue("Hadanshita should be reachable from Kanto ",
                ObjectUtil.isReachable((PojoCacheImpl)cache_, kanto, hadanshita));
        assertTrue("Hadanshita should also be reachable from Yakahoma! ",
                ObjectUtil.isReachable((PojoCacheImpl) cache_, yakahoma, hadanshita));
        assertFalse("Kanto should not be reachable from test! ",
                ObjectUtil.isReachable((PojoCacheImpl) cache_, kanto, test));
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(ObjectUtilTest.class);
     }
  
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(suite());
     }
  
  }
  
  
  
  
  1.1      date: 2007/01/13 15:55:11;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/util/MethodCallTest.java
  
  Index: MethodCallTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.util;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import java.lang.reflect.Method;
  
  /**
   * @author Ben Wang
   */
  
  public class MethodCallTest extends TestCase
  {
     Log log_ = LogFactory.getLog(MethodCallTest.class);
  
     public MethodCallTest(String name)
     {
        super(name);
     }
  
     protected void setUp() throws Exception
     {
        super.setUp();
        log_.info("setUp() ....");
     }
  
     protected void tearDown() throws Exception
     {
        super.tearDown();
     }
  
  //   public void testDummy() {}
  
     public void testBasic() throws Throwable
     {
        Integer i = 1;
        Method method = Foo.class.getDeclaredMethod("setFoo",
                new Class[]{Integer.class});
  
        Object[] args = new Object[]{i};
        Foo foo = new Foo();
        MethodCall mc = new MethodCall(method, args, foo);
  
        mc.invoke();
     }
  
     public static Test suite() throws Exception
     {
        return new TestSuite(MethodCallTest.class);
     }
  
  
     public static void main(String[] args) throws Exception
     {
        junit.textui.TestRunner.run(MethodCallTest.suite());
     }
  
     public static class Foo
     {
        Integer i;
  
        public void setFoo(Integer i)
        {
           this.i = i;
        }
  
        public Integer getFoo()
        {
           return i;
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list