[Batchserver-cvs] batchserver/test/org/jmonks/batchserver/framework/util FrameworkUtilTest.java, N
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-05 18:16:55
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batchserver/framework/util In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14133 Added Files: FrameworkUtilTest.java Log Message: no message --- NEW FILE: FrameworkUtilTest.java --- package org.jmonks.batchserver.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; } } |