[Batchserver-cvs] batchserver/test/org/jmonks/batch/framework/util FrameworkUtilTest.java, NONE, 1
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-15 20:22:18
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batch/framework/util In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27118 Added Files: FrameworkUtilTest.java JdbcConnectionHelperTest.java Log Message: no message --- NEW FILE: FrameworkUtilTest.java --- package org.jmonks.batch.framework.util; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class FrameworkUtilTest extends TestCase { public FrameworkUtilTest(String testName) { super(testName); } /** * Test case to check that FrameworkUtil cannot be instantiated. */ public void testInstantiation() { try { FrameworkUtil utility=(FrameworkUtil)FrameworkUtil.class.newInstance(); fail("FrameworkUtil should not be instantiated."); } catch(InstantiationException ex) { /** * This is expected as Frameworkutil cannot be instantiated. */ } catch(IllegalAccessException ex) { /** * This is expected as the constructor of FrameworkUtil is private. */ } } /** * Test to make sure method "loadPropertiesFromElementToMap" is not accepting null * parameters as input and loading the properties as inteded. */ public void testLoadPropertiesFromElementToMap() throws Exception { Element configElement=null; Map propertyMap=null; try { FrameworkUtil.loadPropertiesFromElementToMap(configElement,propertyMap); fail("Accepting the null valuse as input parameters."); } catch(IllegalArgumentException exception) { /** * This is as expected. */ } try { FrameworkUtil.loadPropertiesFromElementToMap(configElement,new HashMap()); fail("Accepting the null element as input parameter "); } catch(IllegalArgumentException exception) { /** * This is as expected. */ } DocumentBuilderFactory builderFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder=builderFactory.newDocumentBuilder(); Document document=documentBuilder.newDocument(); configElement=document.createElement("some-config"); Element propertyElement1=document.createElement("property"); propertyElement1.setAttribute("key","config-key1"); Node textNode1=document.createTextNode("config-value1"); propertyElement1.appendChild(textNode1); Element propertyElement2=document.createElement("property"); propertyElement2.setAttribute("key","config-key2"); Node textNode2=document.createCDATASection("This is CDATA section"); propertyElement2.appendChild(textNode2); configElement.appendChild(propertyElement1); configElement.appendChild(propertyElement2); try { FrameworkUtil.loadPropertiesFromElementToMap(configElement,propertyMap); fail("Accepting the property map uninitialized."); } catch(IllegalArgumentException exception) { /** * This is as expected. */ } propertyMap=new HashMap(); FrameworkUtil.loadPropertiesFromElementToMap(configElement, propertyMap); assertEquals(2,propertyMap.size()); } protected void tearDown() throws Exception { super.tearDown(); } protected void setUp() throws Exception { super.setUp(); } public static Test suite() { TestSuite suite=new TestSuite(FrameworkUtilTest.class); return suite; } } --- NEW FILE: JdbcConnectionHelperTest.java --- /* * JdbcConnectionHelperTest.java * JUnit based test * * Created on September 10, 2006, 5:18 PM */ package org.jmonks.batch.framework.util; import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; import junit.framework.*; import java.util.Map; /** * * @author Suresh Pragada */ public class JdbcConnectionHelperTest extends TestCase { public JdbcConnectionHelperTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new JdbcConnectionHelperTest("testGetConnection")); suite.addTest(new JdbcConnectionHelperTest("testCloseConnection")); return suite; } /** * Test of getConnection method, of class org.jmonks.batchserver.framework.util.JdbcConnectionHelper. */ public void testGetConnection() { try { Map configMap=new HashMap(); configMap.put(JdbcConnectionHelper.PROPERTY_JDBC_DRIVER_CLASS_NAME, "com.mysql.jdbc.Driver"); configMap.put(JdbcConnectionHelper.PROPERTY_JDBC_URL, "jdbc:mysql://localhost:3306/batchserver"); configMap.put(JdbcConnectionHelper.PROPERTY_DATABASE_USER_NAME, "root"); configMap.put(JdbcConnectionHelper.PROPERTY_DATABASE_PASSWORD, "ramesh"); Connection connection=JdbcConnectionHelper.getConnection(configMap); assertNotNull(connection); assertEquals(false, connection.getAutoCommit()); assertEquals(false, connection.isClosed()); JdbcConnectionHelper.closeConnection(connection); } catch(SQLException exception) { fail("Exception while trying to test JdbcConnectionHelper :: " + exception.getMessage()); } } /** * Test of closeConnection method, of class org.jmonks.batchserver.framework.util.JdbcConnectionHelper. */ public void testCloseConnection() { try { Map configMap=new HashMap(); configMap.put(JdbcConnectionHelper.PROPERTY_JDBC_DRIVER_CLASS_NAME, "com.mysql.jdbc.Driver"); configMap.put(JdbcConnectionHelper.PROPERTY_JDBC_URL, "jdbc:mysql://localhost:3306/batchserver"); configMap.put(JdbcConnectionHelper.PROPERTY_DATABASE_USER_NAME, "root"); configMap.put(JdbcConnectionHelper.PROPERTY_DATABASE_PASSWORD, "ramesh"); Connection connection=JdbcConnectionHelper.getConnection(configMap); assertNotNull(connection); assertEquals(false, connection.getAutoCommit()); assertEquals(false, connection.isClosed()); JdbcConnectionHelper.closeConnection(connection); assertEquals(true, connection.isClosed()); } catch(SQLException exception) { fail("Exception while trying to test JdbcConnectionHelper :: " + exception.getMessage()); } } } |