Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 99   Methods: 5
NCLOC: 65   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JDBCCacheLoaderTest.java 100% 92.3% 100% 93.9%
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.10 $</tt>
 28    */
 29    public class JDBCCacheLoaderTest extends CacheLoaderTestsBase
 30    {
 31  120 public JDBCCacheLoaderTest(String name)
 32    {
 33  120 super(name);
 34    }
 35   
 36  60 protected void configureCache() throws Exception
 37    {
 38  60 Properties prop = getProperties();
 39   
 40  60 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");
 45   
 46  60 cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("",
 47    "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false));
 48    }
 49   
 50  2 public void testLargeObject()
 51    {
 52  2 try
 53    {
 54  2 String key = "LargeObj";
 55    // create an object with size bigger than 4k (k=1024 bytes)
 56  2 StringBuffer text = new StringBuffer("LargeObject");
 57  2 while (text.toString().getBytes().length < (1024 * 100))
 58    {
 59  28 text.append(text);
 60    }
 61  2 String initialValue = text.toString();
 62    // insert it into the cache loader
 63  2 loader.remove(Fqn.fromString("/"));
 64   
 65  2 Object retVal = loader.put(FQN, key, initialValue);
 66  2 assertNull(retVal);
 67  2 addDelay();
 68    // load the object from the cache loader and validate it
 69  2 assertEquals(initialValue, (String) loader.get(FQN).get(key));
 70    // update the object and validate it
 71  2 String updatedValue = initialValue.concat(("UpdatedValue"));
 72  2 retVal = loader.put(FQN, key, updatedValue);
 73  2 assertEquals(initialValue, (String) retVal);
 74  2 assertEquals(updatedValue, (String) loader.get(FQN).get(key));
 75    } catch (Exception e)
 76    {
 77  0 fail(e.toString());
 78    }
 79    }
 80   
 81  120 protected Properties getProperties() throws Exception
 82    {
 83  120 Properties properties = new Properties();
 84  120 try
 85    {
 86  120 properties.load(this.getClass().getClassLoader().getResourceAsStream("cache-jdbc.properties"));
 87  120 return properties;
 88    }
 89    catch (Exception e)
 90    {
 91  0 throw new Exception("Error loading jdbc properties ", e);
 92    }
 93    }
 94   
 95  1 public static Test suite()
 96    {
 97  1 return new TestSuite(JDBCCacheLoaderTest.class);
 98    }
 99    }