Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 155   Methods: 5
NCLOC: 130   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LocalTest.java 50% 87.5% 100% 86.4%
coverage coverage
 1    package org.jboss.cache.marshall;
 2   
 3    import junit.framework.Test;
 4    import junit.framework.TestSuite;
 5    import org.jboss.cache.CacheImpl;
 6    import org.jboss.cache.DefaultCacheFactory;
 7    import org.jboss.cache.Fqn;
 8    import org.jboss.cache.config.Configuration;
 9    import org.jboss.cache.lock.IsolationLevel;
 10    import org.jboss.cache.marshall.data.Debug;
 11   
 12    import javax.transaction.Transaction;
 13    import java.io.File;
 14    import java.lang.reflect.Method;
 15    import java.net.URL;
 16    import java.net.URLClassLoader;
 17   
 18    /**
 19    * Simple functional tests for LegacyTreeCacheMarshaller
 20    *
 21    * @author Ben Wang
 22    * @version $Id: LocalTest.java,v 1.13 2007/01/11 13:49:05 msurtani Exp $
 23    */
 24    public class LocalTest extends RegionBasedMarshallingTestBase
 25    {
 26    CacheImpl cache = null;
 27    Transaction tx = null;
 28    final Fqn FQN = Fqn.fromString("/myNode");
 29    final String KEY = "key";
 30    final String VALUE = "value";
 31    Exception ex;
 32   
 33   
 34  1 protected void setUp() throws Exception
 35    {
 36  1 super.setUp();
 37  1 cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
 38  1 cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
 39  1 cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
 40  1 cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
 41  1 cache.create();
 42  1 cache.start();
 43  1 ex = null;
 44    }
 45   
 46  1 protected void tearDown() throws Exception
 47    {
 48  1 super.tearDown();
 49  1 if (cache != null)
 50    {
 51  1 cache.stop();
 52  1 cache.destroy();
 53  1 cache = null;
 54    }
 55  1 if (ex != null)
 56    {
 57  0 throw ex;
 58    }
 59    }
 60   
 61  1 public void testClassloader() throws Exception
 62    {
 63  1 String jarDir = System.getProperty("test.jar.dir");
 64  1 File jar0 = new File(jarDir + "/testMarshall.jar");
 65  1 URL[] cp0 = {jar0.toURL()};
 66  1 URLClassLoader ucl0 = new URLClassLoader(cp0);
 67  1 Thread.currentThread().setContextClassLoader(ucl0);
 68  1 Class clasz1 = ucl0.loadClass(PERSON_CLASSNAME);
 69  1 StringBuffer buffer = new StringBuffer("Person Info");
 70  1 Debug.displayClassInfo(clasz1, buffer, false);
 71  1 log(buffer.toString());
 72  1 Object ben = clasz1.newInstance();
 73  1 Object value;
 74  1 try
 75    {
 76    {
 77  1 Class[] types = {String.class};
 78  1 Method setValue = clasz1.getMethod("setName", types);
 79  1 Object[] margs = {"Ben"};
 80  1 value = setValue.invoke(ben, margs);
 81    }
 82  1 Class[] types = {};
 83  1 Class[] margs = {};
 84  1 Method getValue = clasz1.getMethod("getLastElementAsString", types);
 85  0 value = getValue.invoke(ben, margs);
 86  0 buffer.setLength(0);
 87  0 buffer.append("main.obj.CodeSource: ");
 88  0 Debug.displayClassInfo(value.getClass(), buffer, false);
 89  0 log(buffer.toString());
 90    }
 91    catch (Exception e)
 92    {
 93  1 e.printStackTrace();
 94  1 log("Failed to invoke getLastElementAsString: " + e);
 95    }
 96   
 97  1 cache.put("/a/b/c", "ben", ben);
 98  1 assertNotNull(cache.get("/a/b/c"));
 99  1 assertEquals(cache.get("/a/b/c", "ben"), ben);
 100  1 Object obj = cache.get("/a/b/c", "ben");
 101   
 102  1 Class claszAddr = ucl0.loadClass(ADDRESS_CLASSNAME);
 103  1 buffer = new StringBuffer("Address Info");
 104  1 Debug.displayClassInfo(claszAddr, buffer, false);
 105  1 log(buffer.toString());
 106  1 Object addr = claszAddr.newInstance();
 107  1 try
 108    {
 109    {
 110  1 Class[] types = {String.class};
 111  1 Method setValue = claszAddr.getMethod("setCity", types);
 112  1 Object[] margs = {"SF"};
 113  1 value = setValue.invoke(addr, margs);
 114    }
 115   
 116    {
 117  1 Class[] types = {claszAddr};
 118  1 Method setValue = clasz1.getMethod("setAddress", types);
 119  1 Object[] margs = {addr};
 120  1 value = setValue.invoke(obj, margs);
 121    }
 122   
 123  1 Class[] types = {};
 124  1 Class[] margs = {};
 125  1 Method getValue = clasz1.getMethod("getAddress", types);
 126  1 value = getValue.invoke(obj, margs);
 127  1 buffer.setLength(0);
 128  1 buffer.append("main.obj.CodeSource: ");
 129  1 Debug.displayClassInfo(value.getClass(), buffer, false);
 130  1 log(buffer.toString());
 131    }
 132    catch (Exception e)
 133    {
 134  0 e.printStackTrace();
 135  0 log("Failed to invoke: " + e);
 136  0 throw e;
 137    }
 138   
 139    }
 140   
 141  4 void log(String msg)
 142    {
 143  4 System.out.println("-- " + msg);
 144    }
 145   
 146  1 public static Test suite()
 147    {
 148  1 return new TestSuite(LocalTest.class);
 149    }
 150   
 151    //public static void main(String[] args) {
 152    // junit.textui.TestRunner.run(suite());
 153    //}
 154   
 155    }