Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 348   Methods: 25
NCLOC: 200   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XMLTestSuiteT.java 100% 100% 100% 100%
coverage
 1   
 package junit.extensions.xml;
 2   
 
 3   
 import java.io.File;
 4   
 import java.io.FileInputStream;
 5   
 import java.io.IOException;
 6   
 
 7   
 import org.w3c.dom.Element;
 8   
 import junit.extensions.xml.elements.ElementFixture;
 9   
 import junit.framework.TestCase;
 10   
 import java.util.Arrays;
 11   
 import java.util.List;
 12   
 
 13   
 /**
 14   
  * <p>Title: Test the XMLTestSuite. </p>
 15   
  * <p>Description: Test cases for the XMLTestSuite class.</p>
 16   
  * <p>Copyright: Copyright (c) 2003</p>
 17   
  * <p>Company: JFCUnit OpenSource Project</p>
 18   
  * @author Kevin Wilson
 19   
  * @version 1.0
 20   
  */
 21   
 public class XMLTestSuiteT extends TestCase {
 22   
   /**
 23   
    * test suite being tested.
 24   
    */
 25   
   private XMLTestSuite m_xmlTestSuite = null;
 26   
   /**
 27   
    * Element fixture.
 28   
    */
 29   
   private ElementFixture m_elementFixture;
 30   
   /**
 31   
    * Second Element fixture to allow creation of two
 32   
    * documents at once.
 33   
    */
 34   
   private ElementFixture m_ef2;
 35   
 
 36   
   /**
 37   
    * Setup the test case.
 38   
    * @throws Exception may be thrown.
 39   
    */
 40  22
   protected void setUp() throws Exception {
 41  22
     super.setUp();
 42  22
     m_xmlTestSuite = new XMLTestSuite();
 43  22
     m_elementFixture = new ElementFixture(this);
 44   
 
 45  22
     m_elementFixture.setUp();
 46   
   }
 47   
 
 48   
   /**
 49   
    * Setup the second element fixutre.
 50   
    */
 51  3
   protected void setUpEf2() {
 52  3
     m_ef2 = new ElementFixture(this);
 53  3
     m_ef2.setUp();
 54   
   }
 55   
 
 56   
   /**
 57   
    * Tear down the test fixtures.
 58   
    * @throws Exception may be thrown.
 59   
    */
 60  22
   protected void tearDown() throws Exception {
 61  22
     m_xmlTestSuite = null;
 62  22
     m_elementFixture.tearDown();
 63  22
     m_elementFixture = null;
 64   
 
 65  22
     if (m_ef2 != null) {
 66  3
       m_ef2.tearDown();
 67  3
       m_ef2 = null;
 68   
     }
 69  22
     super.tearDown();
 70   
   }
 71   
 
 72   
   /**
 73   
    * Test the null constructor.
 74   
    */
 75  1
   public void testXMLTestSuite() {
 76  1
     m_xmlTestSuite = new XMLTestSuite();
 77   
   }
 78   
 
 79   
   /**
 80   
    * Test the consturctor with file name.
 81   
    * @throws IOException may be thrown.
 82   
    */
 83  1
   public void testXMLTestSuite1() throws IOException {
 84  1
     m_elementFixture.newElement("echo", new String[] {
 85   
                               "message", "test"
 86   
     });
 87  1
     File file = m_elementFixture.getSuiteFile();
 88  1
     String name = file.getCanonicalPath();
 89  1
     m_xmlTestSuite = new XMLTestSuite(name);
 90   
   }
 91   
 
 92   
   /**
 93   
    * Test a invalid file.
 94   
    * @throws IOException may be thrown.
 95   
    */
 96  1
   public void testXMLTestSuite1InvalidFile() throws java.io.IOException {
 97  1
     Exception ex = null;
 98  1
     try {
 99  1
       m_xmlTestSuite = new XMLTestSuite("InvalidFile.xml");
 100   
     } catch (RuntimeException re) {
 101  1
       ex = re;
 102   
     }
 103  1
     assertNotNull("Exception should be thrown", ex);
 104   
   }
 105   
 
 106   
   /**
 107   
    * Test a constructor with element and name.
 108   
    * @throws IOException may be thrown.
 109   
    */
 110  1
   public void testXMLTestSuite2() throws IOException {
 111   
 
 112  1
     setUpEf2();
 113  1
     IXMLTestSuite suite = m_ef2.getTestSuite();
 114  1
     File f = m_ef2.getSuiteFile();
 115   
 
 116  1
     String name = f.getCanonicalPath();
 117  1
     Element element = m_ef2.getSuiteElement();
 118  1
     m_xmlTestSuite = new XMLTestSuite(name, element);
 119   
   }
 120   
 
 121   
   /**
 122   
    * Test a constructor with input stream.
 123   
    * @throws IOException may be thrown.
 124   
    */
 125  1
   public void testXMLTestSuite3() throws IOException {
 126  1
     File f = m_elementFixture.getSuiteFile();
 127  1
     FileInputStream fis = new FileInputStream(f);
 128   
 
 129  1
     m_xmlTestSuite = new XMLTestSuite("Test", fis);
 130   
   }
 131   
 
 132   
   /**
 133   
    * Test adding a file.
 134   
    * @throws IOException may be thrown.
 135   
    */
 136  1
   public void testAddFile() throws IOException {
 137  1
     m_xmlTestSuite = new XMLTestSuite();
 138  1
     this.setUpEf2();
 139  1
     File f = m_ef2.getSuiteFile();
 140  1
     m_xmlTestSuite.addFile(f.getAbsolutePath());
 141   
   }
 142   
 
 143   
   /**
 144   
    * Test adding a procedure.
 145   
    */
 146  1
   public void testAddProcedure() {
 147  1
     Element suite = m_elementFixture.getSuiteElement();
 148  1
     Element procElement = m_elementFixture.newChild(suite, "procedure", new String[] {
 149   
                                            "name", "testprocedure"
 150   
     });
 151  1
     m_xmlTestSuite = new XMLTestSuite("test", suite);
 152   
 
 153  1
     IXMLProcedure proc = new XMLProcedure(procElement);
 154  1
     m_xmlTestSuite.addProcedure(proc);
 155   
   }
 156   
 
 157   
   /**
 158   
    * Test adding a null procedure.
 159   
    */
 160  1
   public void testAddNullProcedure() {
 161  1
     Element suite = m_elementFixture.getSuiteElement();
 162  1
     m_xmlTestSuite = new XMLTestSuite("test", suite);
 163   
 
 164  1
     IXMLProcedure proc = null;
 165  1
     Exception ex = null;
 166  1
     try {
 167  1
       m_xmlTestSuite.addProcedure(proc);
 168   
     } catch (Exception e) {
 169  1
       ex = e;
 170   
     }
 171  1
     assertNotNull("Exception expected", ex);
 172   
   }
 173   
 
 174   
   /**
 175   
    * Test adding a property.
 176   
    */
 177  1
   public void testAddProperty() {
 178  1
     String name = "ABC";
 179  1
     java.awt.Point value = new java.awt.Point(1, 1);
 180  1
     m_xmlTestSuite.addProperty(name, value);
 181   
 
 182  1
     Object o = m_xmlTestSuite.getProperty(name);
 183  1
     assertSame("Values should be the same object", value, o);
 184   
   }
 185   
 
 186   
   /**
 187   
    * Test clear properties.
 188   
    */
 189  1
   public void testClearProperties() {
 190  1
     m_xmlTestSuite.addProperty("TEST", "ABC");
 191  1
     m_xmlTestSuite.clearProperties();
 192  1
     Object o = m_xmlTestSuite.getProperty("TEST");
 193  1
     assertNull("Property should not be found", o);
 194   
   }
 195   
 
 196   
   /**
 197   
    * Test get debug.
 198   
    */
 199  1
   public void testGetDebug() {
 200  1
     boolean expectedReturn = false;
 201  1
     boolean actualReturn = m_xmlTestSuite.getDebug();
 202  1
     assertEquals("return value", expectedReturn, actualReturn);
 203   
 
 204  1
     m_xmlTestSuite.addProperty("debug", "false");
 205  1
     actualReturn = m_xmlTestSuite.getDebug();
 206  1
     assertEquals("return value", expectedReturn, actualReturn);
 207   
 
 208  1
     m_xmlTestSuite.addProperty("debug", "true");
 209  1
     expectedReturn = true;
 210  1
     actualReturn = m_xmlTestSuite.getDebug();
 211  1
     assertEquals("return value", expectedReturn, actualReturn);
 212   
 
 213  1
     m_xmlTestSuite.addProperty("debug", Boolean.TRUE);
 214  1
     actualReturn = m_xmlTestSuite.getDebug();
 215  1
     assertEquals("return value", expectedReturn, actualReturn);
 216   
 
 217  1
     m_xmlTestSuite.addProperty("debug", Boolean.FALSE);
 218  1
     expectedReturn = false;
 219  1
     actualReturn = m_xmlTestSuite.getDebug();
 220  1
     assertEquals("return value", expectedReturn, actualReturn);
 221   
   }
 222   
 
 223   
   /**
 224   
    * Test getFileName.
 225   
    */
 226  1
   public void testGetFileName() {
 227  1
     String expectedReturn = null;
 228  1
     String actualReturn = m_xmlTestSuite.getFileName();
 229  1
     assertEquals("return value", expectedReturn, actualReturn);
 230   
   }
 231   
 
 232   
   /**
 233   
    * Test getProcedure.
 234   
    */
 235  1
   public void testGetProcedure() {
 236  1
     String name = "";
 237  1
     IXMLProcedure expectedReturn = null;
 238  1
     IXMLProcedure actualReturn = m_xmlTestSuite.getProcedure(name);
 239  1
     assertEquals("return value", expectedReturn, actualReturn);
 240   
   }
 241   
 
 242   
   /**
 243   
    * test getProcedureCache.
 244   
    */
 245  1
   public void testGetProcedureCache() {
 246  1
     XMLObjectCache actualReturn = m_xmlTestSuite.getProcedureCache();
 247  1
     assertNotNull("return value", actualReturn);
 248   
   }
 249   
 
 250   
   /**
 251   
    * Test getProperty.
 252   
    */
 253  1
   public void testGetProperty() {
 254  1
     m_xmlTestSuite.addProperty("TEST", "ABC");
 255  1
     Object expectedReturn = "ABC";
 256  1
     Object actualReturn = m_xmlTestSuite.getProperty("TEST");
 257  1
     assertEquals("return value", expectedReturn, actualReturn);
 258   
   }
 259   
 
 260   
   /**
 261   
    * Test getPropertyCache.
 262   
    */
 263  1
   public void testGetPropertyCache() {
 264  1
     XMLObjectCache expectedReturn = null;
 265  1
     XMLObjectCache actualReturn = m_xmlTestSuite.getPropertyCache();
 266  1
     assertNotNull("property cache", actualReturn);
 267   
   }
 268   
 
 269   
   /**
 270   
    * Test getPropertyName.
 271   
    */
 272  1
   public void testGetPropertyName() {
 273  1
     m_xmlTestSuite.addProperty("TEST", "ABC");
 274  1
     m_xmlTestSuite.addProperty("ABC", "DEF");
 275  1
     Object value = "DEF";
 276  1
     String expectedReturn = "ABC";
 277  1
     String actualReturn = m_xmlTestSuite.getPropertyName(value);
 278  1
     assertEquals("return value", expectedReturn, actualReturn);
 279   
   }
 280   
 
 281   
   /**
 282   
    * Test getPropertyNames.
 283   
    */
 284  1
   public void testGetPropertyNames() {
 285  1
     m_xmlTestSuite.addProperty("TEST", "ABC");
 286  1
     m_xmlTestSuite.addProperty("ABC", "DEF");
 287  1
     String[] expectedReturn = {"TEST", "ABC"};
 288  1
     String[] actualReturn = m_xmlTestSuite.getPropertyNames();
 289   
 
 290  1
     List l = Arrays.asList(actualReturn);
 291  1
     assertEquals("return value", expectedReturn.length, actualReturn.length);
 292  1
     for (int i = 0; i < expectedReturn.length; i++) {
 293  2
       assertTrue("does not contain" + expectedReturn[i], l.contains(expectedReturn[i]));
 294   
     }
 295   
   }
 296   
 
 297   
   /**
 298   
    * Test removeProperty.
 299   
    */
 300  1
   public void testRemoveProperty() {
 301  1
     String name = "TEST";
 302  1
     m_xmlTestSuite.addProperty(name, "ABC");
 303  1
     m_xmlTestSuite.removeProperty(name);
 304  1
     Object o = m_xmlTestSuite.getProperty(name);
 305  1
     assertNull("Property should not exist", o);
 306   
   }
 307   
 
 308   
   /**
 309   
    * Simply verify that the resolver of the property
 310   
    * Cache gets called.
 311   
    */
 312  1
   public void testResolveProperties() {
 313   
     // Value without ${..} should return the value.
 314  1
     m_xmlTestSuite = new XMLTestSuite("test", m_elementFixture.getSuiteElement());
 315  1
     m_xmlTestSuite.addProperty("subs", "success");
 316  1
     String s = "abc";
 317  1
     String expectedReturn = "abc";
 318  1
     String actualReturn = m_xmlTestSuite.resolveProperties(s);
 319  1
     assertEquals("return value", expectedReturn, actualReturn);
 320   
   }
 321   
 
 322   
   /**
 323   
    * Simply verify that the resolver of the property
 324   
    * Cache gets called.
 325   
    */
 326  1
   public void testResolveProperties2() {
 327   
     // Value without ${..} should return the value.
 328  1
     m_xmlTestSuite = new XMLTestSuite("test", m_elementFixture.getSuiteElement());
 329  1
     m_xmlTestSuite.addProperty("subs", "success");
 330  1
     String s = "${subs}";
 331  1
     String expectedReturn = "success";
 332  1
     String actualReturn = m_xmlTestSuite.resolveProperties(s);
 333  1
     assertEquals("return value", expectedReturn, actualReturn);
 334   
   }
 335   
 
 336   
   /**
 337   
    * Test setParent().
 338   
    */
 339  1
   public void testSetParent() {
 340  1
     this.setUpEf2();
 341  1
     m_xmlTestSuite = new XMLTestSuite("test", m_elementFixture.getSuiteElement());
 342   
 
 343  1
     IXMLTest parent = m_ef2.getTestSuite();
 344  1
     m_xmlTestSuite.setParent(parent);
 345   
   }
 346   
 
 347   
 }
 348