Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 106   Methods: 6
NCLOC: 71   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JDBCCacheLoaderTest.java 100% 92.9% 100% 94.4%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.loader;
 8   
 9    import junit.framework.Test;
 10    import junit.framework.TestSuite;
 11    import org.jboss.cache.Fqn;
 12   
 13    import java.util.Properties;
 14   
 15    /**
 16    * This test runs cache loader tests using Database as the cache loader store.
 17    * The default test is configured using Derby embedded framework.
 18    * The server and database configuration is read from a properties file located at
 19    * /etc/cache-jdbc.properties.
 20    * <p/>
 21    * To run this test with any other RDBMS, The appropriate JDBC driver
 22    * (i.e mysql-connector-java-3.0.10-stable-bin.jar)
 23    * must be in the lib directory.
 24    *
 25    * @author <a href="hmesha@novell.com">Hany Mesha</a>
 26    * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
 27    * @version <tt>$Revision: 1.11 $</tt>
 28    */
 29    public class JDBCCacheLoaderTest extends CacheLoaderTestsBase
 30    {
 31  126 public JDBCCacheLoaderTest(String name)
 32    {
 33  126 super(name);
 34    }
 35   
 36  63 protected void configureCache() throws Exception
 37    {
 38  63 Properties prop = getProperties();
 39   
 40  63 String props = "cache.jdbc.driver =" + prop.getProperty("cache.jdbc.driver") + "\n" +
 41    "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
 42    "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
 43    "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
 44    "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
 45    "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat");
 46   
 47  63 cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
 48    "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false));
 49    }
 50   
 51  2 public void testLargeObject()
 52    {
 53  2 try
 54    {
 55  2 String key = "LargeObj";
 56    // create an object with size bigger than 4k (k=1024 bytes)
 57  2 StringBuffer text = new StringBuffer("LargeObject");
 58  2 while (text.toString().getBytes().length < (1024 * 100))
 59    {
 60  28 text.append(text);
 61    }
 62  2 String initialValue = text.toString();
 63    // insert it into the cache loader
 64  2 loader.remove(Fqn.fromString("/"));
 65   
 66  2 Object retVal = loader.put(FQN, key, initialValue);
 67  2 assertNull(retVal);
 68  2 addDelay();
 69    // load the object from the cache loader and validate it
 70  2 assertEquals(initialValue, (String) loader.get(FQN).get(key));
 71    // update the object and validate it
 72  2 String updatedValue = initialValue.concat(("UpdatedValue"));
 73  2 retVal = loader.put(FQN, key, updatedValue);
 74  2 assertEquals(initialValue, (String) retVal);
 75  2 assertEquals(updatedValue, (String) loader.get(FQN).get(key));
 76    } catch (Exception e)
 77    {
 78  0 fail(e.toString());
 79    }
 80    }
 81   
 82  126 protected Properties getProperties() throws Exception
 83    {
 84  126 Properties properties = new Properties();
 85  126 try
 86    {
 87  126 properties.load(this.getClass().getClassLoader().getResourceAsStream("cache-jdbc.properties"));
 88  126 return properties;
 89    }
 90    catch (Exception e)
 91    {
 92  0 throw new Exception("Error loading jdbc properties ", e);
 93    }
 94    }
 95   
 96  2 public void testRootIsCreated() throws Exception
 97    {
 98  2 loader.put(Fqn.fromString("/a/b/c"), "a", "b");
 99  2 assertTrue(loader.exists(Fqn.ROOT));
 100    }
 101   
 102  1 public static Test suite()
 103    {
 104  1 return new TestSuite(JDBCCacheLoaderTest.class);
 105    }
 106    }