Clover coverage report - JFCUnit Test Coverage
Coverage timestamp: Mon Dec 20 2004 23:38:10 MST
file stats: LOC: 772   Methods: 26
NCLOC: 490   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
AbstractTagHandlerT.java 75% 99.3% 96.2% 98.4%
coverage coverage
 1   
 package junit.extensions.xml.elements;
 2   
 
 3   
 import java.awt.Point;
 4   
 
 5   
 import org.w3c.dom.Element;
 6   
 import junit.extensions.xml.IXMLTestCase;
 7   
 import junit.extensions.xml.IXMLTestSuite;
 8   
 import junit.extensions.xml.XMLException;
 9   
 import junit.framework.TestCase;
 10   
 
 11   
 /**
 12   
  * <p>Title: Test AbstractTagHandler.</p>
 13   
  * <p>Copyright: Copyright (c) 2003</p>
 14   
  * <p>Company: JFCUnit OpenSource Project</p>
 15   
  * @author Kevin Wilson
 16   
  * @version 1.0
 17   
  */
 18   
 public class AbstractTagHandlerT
 19   
     extends TestCase {
 20   
 
 21   
   /**
 22   
    * Hold the current tag handler being tested.
 23   
    */
 24   
   private ImplTagHandler m_abstractTagHandler = null;
 25   
 
 26   
   /**
 27   
    * Create the element fixture.
 28   
    */
 29   
   private ElementFixture m_fixture = new ElementFixture(this);
 30   
 
 31   
   /**
 32   
    * Constructor.
 33   
    * @param name Name of the test case.
 34   
    */
 35  20
   public AbstractTagHandlerT(final String name) {
 36  20
     super(name);
 37   
   }
 38   
 
 39   
   /**
 40   
    * <p>Title: class ImplTagHandler </p>
 41   
    * <p>Description: This class provides a concrete implementation
 42   
    * for testing the abstract class. </p>
 43   
    * <p>Copyright: Copyright (c) 2003</p>
 44   
    * <p>Company: JFCUnit OpenSource Project</p>
 45   
    * @author Kevin Wilson
 46   
    * @version 1.0
 47   
    */
 48   
   private static class ImplTagHandler extends AbstractTagHandler {
 49   
     /**
 50   
      * Constructor.
 51   
      * @param e Element which defines the action for the tag handler.
 52   
      * @param tc IXMLTestCase parent test case.
 53   
      */
 54  19
     public ImplTagHandler(final Element e, final IXMLTestCase tc) {
 55  19
       super(e, tc);
 56   
     }
 57   
 
 58   
     /**
 59   
      * Constructor.
 60   
      * @param e Element defining the parameters for this tag handler.
 61   
      * @param ts IXMLTestSuite parent test suite.
 62   
      */
 63  1
     public ImplTagHandler(final Element e, final IXMLTestSuite ts) {
 64  1
       super(e, ts);
 65   
     }
 66   
 
 67   
     /**
 68   
      * Process the tag.
 69   
      * @throws XMLException may be thrown.
 70   
      */
 71  0
     public void processElement() throws XMLException {
 72   
     }
 73   
 
 74   
   }
 75   
 
 76   
   /**
 77   
    * Setup the test case.
 78   
    * @throws Exception may be thrown.
 79   
    */
 80  20
   protected void setUp() throws Exception {
 81  20
     super.setUp();
 82  20
     m_fixture.setUp();
 83   
   }
 84   
 
 85   
   /**
 86   
    * Tear down the test case.
 87   
    * @throws Exception may be thrown.
 88   
    */
 89  20
   protected void tearDown() throws Exception {
 90  20
     m_abstractTagHandler = null;
 91  20
     m_fixture.tearDown();
 92  20
     super.tearDown();
 93   
   }
 94   
 
 95   
   /**
 96   
    * Test the constructor with test case.
 97   
    */
 98  1
   public void testAbstractTagHandlerWithTestCase() {
 99  1
     Element element = m_fixture.newElement("test", new String[] {"testAttr", "automatedTest1"});
 100  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 101  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 102   
 
 103  1
     assertSame("Element", element, m_abstractTagHandler.getElement());
 104  1
     assertSame("TestCase:", testCase, m_abstractTagHandler.getTestCase());
 105  1
     assertSame("XMLTestCase:", testCase, m_abstractTagHandler.getXMLTestCase());
 106   
 
 107   
   }
 108   
 
 109   
   /**
 110   
    * Test the constructor with a test suite.
 111   
    */
 112  1
   public void testAbstractTagHandlerWithTestSuite() {
 113  1
     Element element = m_fixture.newElement("suite", new String[] {"name", "automatedTest2"});
 114  1
     IXMLTestSuite testSuite = m_fixture.getTestSuite();
 115  1
     m_abstractTagHandler = new ImplTagHandler(element, testSuite);
 116   
 
 117  1
     assertSame("Element", element, m_abstractTagHandler.getElement());
 118  1
     assertSame("TestCase:", testSuite, m_abstractTagHandler.getXMLTestSuite());
 119   
 
 120   
   }
 121   
 
 122   
   /**
 123   
    * Test checkAtLeastOneRequiredAttribute.
 124   
    * @throws XMLException may be thrown.
 125   
    */
 126  1
   public void testCheckAtLeastOneRequiredAttribute() throws XMLException {
 127  1
     Element element = m_fixture.newElement("testElement", new String[] {
 128   
                                          "testAttr1", "automatedTest1",
 129   
                                          "testAttr2", "automatedTest2"
 130   
     });
 131  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 132  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 133   
 
 134   
     // Should not throw an exception.
 135  1
     m_abstractTagHandler.checkAtLeastOneRequiredAttribute(element, new String[] {"testAttr1"});
 136   
 
 137   
     // Should not throw an exception.
 138  1
     m_abstractTagHandler.checkAtLeastOneRequiredAttribute(element, new String[] {"testAttr2"});
 139   
 
 140   
     // Missing attribute
 141  1
     boolean assrt = false;
 142  1
     try {
 143  1
       m_abstractTagHandler.checkAtLeastOneRequiredAttribute(element,
 144   
           new String[] {"testAttr3"});
 145   
     } catch (XMLException e) {
 146  1
       assrt = true;
 147   
     }
 148  1
     assertTrue("XMLException was not thrown", assrt);
 149   
   }
 150   
 
 151   
   /**
 152   
    * check at least one required attribute.
 153   
    * @throws XMLException may be thrown.
 154   
    */
 155  1
   public void testCheckAtLeastOneRequiredAttributeNoElement() throws XMLException {
 156  1
     Element element = m_fixture.newElement("testElement", new String[] {
 157   
                                          "testAttr1", "automatedTest1",
 158   
                                          "testAttr2", "automatedTest2"
 159   
     });
 160  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 161  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 162   
 
 163   
     // Should not throw an exception.
 164  1
     m_abstractTagHandler.checkAtLeastOneRequiredAttribute(new String[] {"testAttr1"});
 165   
 
 166   
     // Should not throw an exception.
 167  1
     m_abstractTagHandler.checkAtLeastOneRequiredAttribute(new String[] {"testAttr2"});
 168   
 
 169   
     // Missing attribute
 170  1
     boolean assrt = false;
 171  1
     try {
 172  1
       m_abstractTagHandler.checkAtLeastOneRequiredAttribute(new String[] {"testAttr3"});
 173   
     } catch (XMLException e) {
 174  1
       assrt = true;
 175   
     }
 176  1
     assertTrue("XMLException was not thrown", assrt);
 177   
   }
 178   
 
 179   
   /**
 180   
    * Check Element tag name.
 181   
    * @throws XMLException may be thrown.
 182   
    */
 183  1
   public void testCheckElementTagName() throws XMLException {
 184  1
     Element element = m_fixture.newElement("testElement", new String[] {
 185   
                                          "testAttr1", "automatedTest1",
 186   
                                          "testAttr2", "automatedTest2"
 187   
     });
 188  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 189  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 190   
 
 191   
     // Should not throw an XMLException
 192  1
     m_abstractTagHandler.checkElementTagName("testElement");
 193   
 
 194   
     // Should throw an XMLException
 195  1
     boolean assrt = false;
 196  1
     try {
 197  1
       m_abstractTagHandler.checkElementTagName("testElementABC");
 198   
     } catch (XMLException e) {
 199  1
       assrt = true;
 200   
     }
 201  1
     assertTrue("XMLException was not thrown", assrt);
 202   
   }
 203   
 
 204   
   /**
 205   
    * Check on required attribute.
 206   
    * @throws XMLException may be thrown.
 207   
    */
 208  1
   public void testCheckOneRequiredAttribute() throws XMLException {
 209  1
     Element element = m_fixture.newElement("testElement", new String[] {
 210   
                                          "testAttr1", "automatedTest1",
 211   
                                          "testAttr2", "automatedTest2"
 212   
     });
 213  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 214  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 215   
 
 216   
     // Should not throw an exception.
 217  1
     m_abstractTagHandler.checkOneRequiredAttribute(element, new String[] {"testAttr1"});
 218   
 
 219   
     // Should not throw an exception.
 220  1
     m_abstractTagHandler.checkOneRequiredAttribute(element, new String[] {"testAttr2"});
 221   
 
 222   
     // Should throw an exception when both.
 223  1
     boolean assrt = false;
 224  1
     try {
 225  1
       m_abstractTagHandler.checkOneRequiredAttribute(element,
 226   
           new String[] {"testAttr1", "testAttr2"});
 227   
     } catch (XMLException xe) {
 228  1
       assrt = true;
 229   
     }
 230  1
     assertTrue("Both attributes presen; no exception", assrt);
 231   
 
 232   
     // Missing attribute
 233  1
     assrt = false;
 234  1
     try {
 235  1
       m_abstractTagHandler.checkOneRequiredAttribute(element,
 236   
           new String[] {"testAttr3"});
 237   
     } catch (XMLException e) {
 238  1
       assrt = true;
 239   
     }
 240  1
     assertTrue("Unset attribute; no exception.", assrt);
 241   
   }
 242   
 
 243   
   /**
 244   
    * Test check one required attribute.
 245   
    * @throws XMLException may be thrown.
 246   
    */
 247  1
   public void testCheckOneRequiredAttributeNoElement() throws XMLException {
 248  1
     Element element = m_fixture.newElement("testElement", new String[] {
 249   
                                          "testAttr1", "automatedTest1",
 250   
                                          "testAttr2", "automatedTest2"
 251   
     });
 252  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 253  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 254   
 
 255   
     // Should not throw an exception.
 256  1
     m_abstractTagHandler.checkOneRequiredAttribute(new String[] {"testAttr1"});
 257   
 
 258   
     // Should not throw an exception.
 259  1
     m_abstractTagHandler.checkOneRequiredAttribute(new String[] {"testAttr2"});
 260   
 
 261   
     // Should throw an exception when both.
 262  1
     boolean assrt = false;
 263  1
     try {
 264  1
       m_abstractTagHandler.checkOneRequiredAttribute(element,
 265   
           new String[] {"testAttr1", "testAttr2"});
 266   
     } catch (XMLException xe) {
 267  1
       assrt = true;
 268   
     }
 269  1
     assertTrue("Both attributes presen; no exception", assrt);
 270   
 
 271   
     // Missing attribute
 272  1
     assrt = false;
 273  1
     try {
 274  1
       m_abstractTagHandler.checkOneRequiredAttribute(new String[] {"testAttr3"});
 275   
     } catch (XMLException e) {
 276  1
       assrt = true;
 277   
     }
 278  1
     assertTrue("Unset attribute; no exception.", assrt);
 279   
   }
 280   
 
 281   
   /**
 282   
    * Check required Attribute.
 283   
    * @throws XMLException may be thrown.
 284   
    */
 285  1
   public void testCheckRequiredAttribute() throws XMLException {
 286  1
     Element element = m_fixture.newElement("testElement", new String[] {
 287   
                                          "testAttr1", "automatedTest1",
 288   
                                          "testAttr2", "automatedTest2"
 289   
     });
 290  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 291  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 292   
 
 293   
     // Should not throw an exception.
 294  1
     m_abstractTagHandler.checkRequiredAttribute(element, "testAttr1");
 295   
 
 296   
     // Should not throw an exception.
 297  1
     m_abstractTagHandler.checkRequiredAttribute(element, "testAttr2");
 298   
 
 299   
     // Missing attribute
 300  1
     boolean assrt = false;
 301  1
     try {
 302  1
       m_abstractTagHandler.checkRequiredAttribute(element, "testAttr3");
 303   
     } catch (XMLException e) {
 304  1
       assrt = true;
 305   
     }
 306  1
     assertTrue("Unset attribute; no exception.", assrt);
 307   
   }
 308   
 
 309   
   /**
 310   
    * Test checkRequiredAttribute with no element passed.
 311   
    * @throws XMLException may be thrown.
 312   
    */
 313  1
   public void testCheckRequiredAttributeNoElement() throws XMLException {
 314  1
     Element element = m_fixture.newElement("testElement", new String[] {
 315   
                                          "testAttr1", "automatedTest1",
 316   
                                          "testAttr2", "automatedTest2"
 317   
     });
 318  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 319  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 320   
 
 321   
     // Should not throw an exception.
 322  1
     m_abstractTagHandler.checkRequiredAttribute("testAttr1");
 323   
 
 324   
     // Should not throw an exception.
 325  1
     m_abstractTagHandler.checkRequiredAttribute("testAttr2");
 326   
 
 327   
     // Missing attribute
 328  1
     boolean assrt = false;
 329  1
     try {
 330  1
       m_abstractTagHandler.checkRequiredAttribute("testAttr3");
 331   
     } catch (XMLException e) {
 332  1
       assrt = true;
 333   
     }
 334  1
     assertTrue("Unset attribute; no exception.", assrt);
 335   
   }
 336   
 
 337   
   /**
 338   
    * Test getBoolean with no element passed.
 339   
    * @throws XMLException may be thrown.
 340   
    */
 341  1
   public void testGetBooleanNoElement() throws XMLException {
 342  1
     Element element = m_fixture.newElement("testElement", new String[] {
 343   
                                          "testTrue", "true",
 344   
                                          "testFalse", "false",
 345   
                                          "testInvalid", "invalid"
 346   
     });
 347   
 
 348  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 349  1
     m_abstractTagHandler = new ImplTagHandler(element, testCase);
 350   
 
 351   
     // Should not throw an exception.
 352  1
     assertTrue("Get true value", m_abstractTagHandler.getBoolean("testTrue"));
 353   
     // Should not throw an exception.
 354  1
     assertTrue("Get false value", !m_abstractTagHandler.getBoolean("testFalse"));
 355   
 
 356   
     // Missing attribute
 357  1
     boolean result = true;
 358  1
     result = m_abstractTagHandler.getBoolean("testInvalid");
 359  1
     assertTrue("Incorrect default value should be false", !result);
 360   
   }
 361   
 
 362   
   /**
 363   
    * Test getBoolean().
 364   
    * @throws XMLException may be thrown.
 365   
    */
 366  1
   public void testGetBoolean() throws XMLException {
 367  1
     Element element1 = m_fixture.newElement("testElement", new String[] {
 368   
                                          "testTrue", "true",
 369   
                                          "testFalse", "false",
 370   
                                          "testInvalid", "invalid"
 371   
     });
 372  1
     Element element2 = m_fixture.newElement("testElement", new String[] {
 373   
                                          "testTrue", "true",
 374   
                                          "testFalse", "false",
 375   
                                          "testInvalid", "invalid"
 376   
     });
 377   
 
 378  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 379  1
     m_abstractTagHandler = new ImplTagHandler(element2, testCase);
 380   
 
 381   
     // Should not throw an exception.
 382  1
     assertTrue("Get true value", m_abstractTagHandler.getBoolean(element1, "testTrue"));
 383   
     // Should not throw an exception.
 384  1
     assertTrue("Get false value", !m_abstractTagHandler.getBoolean(element1, "testFalse"));
 385   
 
 386   
     // Missing attribute
 387  1
     boolean result = true;
 388  1
     result = m_abstractTagHandler.getBoolean(element1, "testInvalid");
 389  1
     assertTrue("Incorrect default value should be false", !result);
 390   
   }
 391   
 
 392   
   /**
 393   
    * Test getBoolean variations with default.
 394   
    * @throws XMLException may be thrown.
 395   
    */
 396  1
   public void testGetBooleanWithDefault() throws XMLException {
 397  1
     Element element1 = m_fixture.newElement("testElement", new String[] {
 398   
                                          "testTrue", "true",
 399   
                                          "testFalse", "false",
 400   
                                          "testInvalid", "invalid"
 401   
     });
 402  1
     Element element2 = m_fixture.newElement("testElement", new String[] {
 403   
                                          "testTrue", "true",
 404   
                                          "testFalse", "false",
 405   
                                          "testInvalid", "invalid"
 406   
     });
 407   
 
 408  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 409  1
     m_abstractTagHandler = new ImplTagHandler(element2, testCase);
 410   
 
 411   
     // Should not throw an exception.
 412  1
     assertTrue("Get true value", m_abstractTagHandler.getBoolean("testTrue", false));
 413   
     // Should not throw an exception.
 414  1
     assertTrue("Get false value", !m_abstractTagHandler.getBoolean("testFalse", true));
 415   
 
 416   
     // Non-existent attribute
 417  1
     boolean result = false;
 418  1
     result = m_abstractTagHandler.getBoolean("bogus", true);
 419  1
     assertTrue("Incorrect default value should be true", result);
 420   
 
 421   
     // Invaid attribute format.
 422  1
     result = true;
 423  1
     result = m_abstractTagHandler.getBoolean("invalidAttr", false);
 424  1
     assertTrue("Incorrect default value should be true", !result);
 425   
   }
 426   
 
 427   
   /**
 428   
    * Test getBoolean variations with element.
 429   
    * @throws XMLException may be thrown.
 430   
    */
 431  1
   public void testGetBooleanWithElementWithDefault() throws XMLException {
 432  1
     Element element1 = m_fixture.newElement("testElement", new String[] {
 433   
                                           "testTrue", "true",
 434   
                                           "testFalse", "false",
 435   
                                           "testInvalid", "invalid"
 436   
     });
 437  1
     Element element2 = m_fixture.newElement("testElement", new String[] {
 438   
                                           "testTrue", "true",
 439   
                                           "testFalse", "false",
 440   
                                           "testInvalid", "invalid"
 441   
     });
 442   
 
 443  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 444  1
     m_abstractTagHandler = new ImplTagHandler(element2, testCase);
 445   
 
 446   
     // Should not throw an exception.
 447  1
     assertTrue("Get true value", m_abstractTagHandler.getBoolean(element1, "testTrue", false));
 448   
     // Should not throw an exception.
 449  1
     assertTrue("Get false value", !m_abstractTagHandler.getBoolean(element1, "testFalse", true));
 450   
 
 451   
     // Non-existent attribute
 452  1
     boolean result = false;
 453  1
     result = m_abstractTagHandler.getBoolean(element1, "bogus", true);
 454  1
     assertTrue("Incorrect default value should be true", result);
 455   
 
 456   
     // Invaid attribute format.
 457  1
     result = true;
 458  1
     result = m_abstractTagHandler.getBoolean(element1, "invalidAttr", false);
 459  1
     assertTrue("Incorrect default value should be true", !result);
 460   
 
 461   
   }
 462   
 
 463   
   /**
 464   
    * Test getElement.
 465   
    */
 466  1
   public void testGetElement() {
 467  1
     Element expectedReturn = m_fixture.newElement("testElement", new String[] {
 468   
                                           "testTrue", "true",
 469   
                                           "testFalse", "false",
 470   
                                           "testInvalid", "invalid"
 471   
     });
 472   
 
 473  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 474  1
     m_abstractTagHandler = new ImplTagHandler(expectedReturn, testCase);
 475  1
     Element actualReturn = m_abstractTagHandler.getElement();
 476  1
     assertSame("return value", expectedReturn, actualReturn);
 477   
   }
 478   
 
 479   
   /**
 480   
    * test getInt.
 481   
    */
 482  1
   public void testGetInt() {
 483  1
     Element element1 = m_fixture.newElement("testElement", new String[] {
 484   
                                           "testZero", "0",
 485   
                                           "testOne", "1",
 486   
                                           "testNeg", "-1",
 487   
                                           "testBig", "50000",
 488   
                                           "testSmall", "-50000",
 489   
                                           "invalid", "xxxx"
 490   
     });
 491   
 
 492  1
     Element element2 = m_fixture.newElement("testElement", new String[] {
 493   
                                           "testZero", "0",
 494   
                                           "testTwo", "2",
 495   
                                           "testNeg", "-2",
 496   
                                           "testBig", "50001",
 497   
                                           "testSmall", "-50001",
 498   
                                           "invalid", "xxxx"
 499   
     });
 500   
 
 501  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 502  1
     m_abstractTagHandler = new ImplTagHandler(element1, testCase);
 503   
 
 504  1
     assertEquals(0, m_abstractTagHandler.getInt("testZero", -1));
 505  1
     assertEquals(-2, m_abstractTagHandler.getInt("notpresent", -2));
 506  1
     assertEquals(-1, m_abstractTagHandler.getInt("invalid", -1));
 507  1
     assertEquals(1, m_abstractTagHandler.getInt("testOne", -1));
 508  1
     assertEquals(-1, m_abstractTagHandler.getInt("testNeg", 1));
 509  1
     assertEquals(50000, m_abstractTagHandler.getInt("testBig", -1));
 510  1
     assertEquals(-50000, m_abstractTagHandler.getInt("testSmall", -1));
 511   
 
 512  1
     assertEquals(-3, m_abstractTagHandler.getInt(element2, "notpresent", -3));
 513  1
     assertEquals(-1, m_abstractTagHandler.getInt(element2, "invalid", -1));
 514  1
     assertEquals(2, m_abstractTagHandler.getInt(element2, "testTwo", -1));
 515  1
     assertEquals(-2, m_abstractTagHandler.getInt(element2, "testNeg", 2));
 516  1
     assertEquals(50001, m_abstractTagHandler.getInt(element2, "testBig", -1));
 517  1
     assertEquals(-50001, m_abstractTagHandler.getInt(element2, "testSmall", -1));
 518   
   }
 519   
 
 520   
   /**
 521   
    * test getLong().
 522   
    */
 523  1
   public void testGetLong() {
 524  1
     Element element1 = m_fixture.newElement("testElement", new String[] {
 525   
                                           "testZero", "0",
 526   
                                           "testOne", "1",
 527   
                                           "testNeg", "-1",
 528   
                                           "testBig", "50000000",
 529   
                                           "testSmall", "-50000000",
 530   
                                           "invalid", "xxxx"
 531   
     });
 532   
 
 533  1
     Element element2 = m_fixture.newElement("testElement", new String[] {
 534   
                                           "testZero", "0",
 535   
                                           "testTwo", "2",
 536   
                                           "testNeg", "-2",
 537   
                                           "testBig", "50000001",
 538   
                                           "testSmall", "-50000001",
 539   
                                           "invalid", "xxxx"
 540   
     });
 541   
 
 542  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 543  1
     m_abstractTagHandler = new ImplTagHandler(element1, testCase);
 544   
 
 545  1
     assertEquals(0, m_abstractTagHandler.getLong("testZero", -1));
 546  1
     assertEquals(-2, m_abstractTagHandler.getLong("notpresent", -2));
 547  1
     assertEquals(-1, m_abstractTagHandler.getLong("invalid", -1));
 548  1
     assertEquals(1, m_abstractTagHandler.getLong("testOne", -1));
 549  1
     assertEquals(-1, m_abstractTagHandler.getLong("testNeg", 1));
 550  1
     assertEquals(50000000, m_abstractTagHandler.getLong("testBig", -1));
 551  1
     assertEquals(-50000000, m_abstractTagHandler.getLong("testSmall", -1));
 552   
 
 553  1
     assertEquals(-3, m_abstractTagHandler.getLong(element2, "notpresent", -3));
 554  1
     assertEquals(-1, m_abstractTagHandler.getLong(element2, "invalid", -1));
 555  1
     assertEquals(2, m_abstractTagHandler.getLong(element2, "testTwo", -1));
 556  1
     assertEquals(-2, m_abstractTagHandler.getLong(element2, "testNeg", 2));
 557  1
     assertEquals(50000001, m_abstractTagHandler.getLong(element2, "testBig", -1));
 558  1
     assertEquals(-50000001, m_abstractTagHandler.getLong(element2, "testSmall", -1));
 559   
   }
 560   
 
 561   
   /**
 562   
    * Test getPoint.
 563   
    * @throws XMLException may be thrown.
 564   
    */
 565  1
   public void testGetPoint() throws XMLException {
 566   
 
 567  1
     String[] attributes = {
 568   
         "testNE", "5,5",
 569   
         "testNW", "-5,5",
 570   
         "testSW", "-5,-5",
 571   
         "testSE", "5,-5",
 572   
         "testS", "0,-5",
 573   
         "testN", "0,5",
 574   
         "testE", "5,0",
 575   
         "testW", "-5,0",
 576   
         "testCenter", "0,0",
 577   
         "testInvalid", "Invalid"
 578   
     };
 579  1
     Point[] points = {
 580   
         new Point(5, 5),
 581   
         new Point(-5, 5),
 582   
         new Point(-5, -5),
 583   
         new Point(5, -5),
 584   
         new Point(0, -5),
 585   
         new Point(0, 5),
 586   
         new Point(5, 0),
 587   
         new Point(-5, 0),
 588   
         new Point(0, 0)
 589   
     };
 590   
 
 591  1
     Element element1 = m_fixture.newElement("testElement", attributes);
 592  1
     Element element2 = m_fixture.newElement("testElement", attributes);
 593   
 
 594  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 595  1
     m_abstractTagHandler = new ImplTagHandler(element1, testCase);
 596   
 
 597  1
     Point actual;
 598  1
     String attribute;
 599  1
     Point defaultPoint = new Point(9, 9);
 600   
     // Test the common pointes.
 601  1
     for (int i = 0; i < points.length; i++) {
 602  9
       attribute = attributes[i * 2];
 603  9
       Point expected = points[i];
 604  9
       actual = m_abstractTagHandler.getPoint(element2, attribute, defaultPoint);
 605  9
       assertEquals(attribute + "With element", expected, actual);
 606   
 
 607  9
       actual = m_abstractTagHandler.getPoint(attribute, new Point(0, 0));
 608  9
       assertEquals(attribute, expected, actual);
 609   
     }
 610   
     // Now test the not present case.
 611  1
     actual = m_abstractTagHandler.getPoint("testNotPresent", defaultPoint);
 612  1
     assertSame("Default point returned.", defaultPoint, actual);
 613   
 
 614  1
     actual = m_abstractTagHandler.getPoint(element2, "testNotPresent", defaultPoint);
 615  1
     assertSame("Default point returned. with Element", defaultPoint, actual);
 616   
 
 617   
     // Now test the exception cases: Invalid point
 618  1
     boolean assrt;
 619  1
    assrt = false;
 620  1
     try {
 621  1
       actual = m_abstractTagHandler.getPoint("testInvalid", new Point(0, 0));
 622   
     } catch (Exception e) {
 623  1
       assrt = true;
 624   
     }
 625  1
     assertTrue("invalid point format: no exception", assrt);
 626   
 
 627  1
     assrt = false;
 628  1
      try {
 629  1
        actual = m_abstractTagHandler.getPoint(element2, "testInvalid", new Point(0, 0));
 630   
      } catch (Exception e) {
 631  1
        assrt = true;
 632   
      }
 633  1
      assertTrue("invalid point format: no exception with element", assrt);
 634   
   }
 635   
 
 636   
   /**
 637   
    * Test getString.
 638   
    */
 639  1
   public void testGetString() {
 640  1
     String[] attributes = {
 641   
        "testData", "data",
 642   
        "testEmpty", ""
 643   
    };
 644   
 
 645  1
    Element element1 = m_fixture.newElement("testElement", attributes);
 646  1
    Element element2 = m_fixture.newElement("testElement", attributes);
 647   
 
 648  1
    IXMLTestCase testCase = m_fixture.getTestCase();
 649  1
    m_abstractTagHandler = new ImplTagHandler(element1, testCase);
 650  1
    String defaultValue = "default";
 651  1
    String actual;
 652  1
    String exp;
 653  1
    String attr;
 654   
 
 655   
    // Data String
 656  1
    attr = "testData";
 657  1
    exp  = "data";
 658   
 
 659  1
    actual = m_abstractTagHandler.getString(attr);
 660  1
    assertEquals("getString(attr)", exp, actual);
 661   
 
 662  1
    actual = m_abstractTagHandler.getString(attr, defaultValue);
 663  1
    assertEquals("getString(attr, default)", exp, actual);
 664   
 
 665  1
    actual = m_abstractTagHandler.getString(element2, attr);
 666  1
    assertEquals("getString(element, attr)", exp, actual);
 667   
 
 668  1
    actual = m_abstractTagHandler.getString(element2, attr, defaultValue);
 669  1
    assertEquals("getString(element, attr, default)", exp, actual);
 670   
 
 671   
    // Empty String
 672  1
    attr = "testEmpty";
 673  1
    exp  = null;
 674   
 
 675  1
    actual = m_abstractTagHandler.getString(attr);
 676  1
    assertEquals("empty getString(attr)", exp, actual);
 677   
 
 678  1
    actual = m_abstractTagHandler.getString(attr, defaultValue);
 679  1
    assertEquals("empty getString(attr, default)", exp, actual);
 680   
 
 681  1
    actual = m_abstractTagHandler.getString(element2, attr);
 682  1
    assertEquals("empty getString(element, attr)", exp, actual);
 683   
 
 684  1
    actual = m_abstractTagHandler.getString(element2, attr, defaultValue);
 685  1
    assertEquals("empty getString(element, attr, default)", exp, actual);
 686   
 
 687   
    // Now lets test cases where the value does not exist
 688  1
    attr = "notpresent";
 689  1
    exp = null;
 690   
 
 691  1
    actual = m_abstractTagHandler.getString(attr);
 692  1
    assertEquals("getString(attr)", exp, actual);
 693   
 
 694  1
    actual = m_abstractTagHandler.getString(attr, defaultValue);
 695  1
    assertEquals("getString(attr, default)", defaultValue, actual);
 696   
 
 697  1
    actual = m_abstractTagHandler.getString(element2, attr);
 698  1
    assertEquals("getString(element, attr)", exp, actual);
 699   
 
 700  1
    actual = m_abstractTagHandler.getString(element2, attr, defaultValue);
 701  1
    assertEquals("getString(element, attr, default)", defaultValue, actual);
 702   
 
 703   
   }
 704   
 
 705   
   /**
 706   
    * Test getTagName.
 707   
    */
 708  1
   public void testGetTagName() {
 709  1
     String elementName = "testElementA";
 710  1
     String[] attributes = {"ABC", "DEF"};
 711  1
     Element element1 = m_fixture.newElement(elementName, attributes);
 712  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 713  1
     m_abstractTagHandler = new ImplTagHandler(element1, testCase);
 714   
 
 715  1
     String actualReturn = m_abstractTagHandler.getTagName();
 716  1
     assertEquals("return value", elementName, actualReturn);
 717   
   }
 718   
 
 719   
   /**
 720   
    * Test variable resolution.
 721   
    */
 722  1
   public void testResolveVariables() {
 723  1
     String elementName = "testElementA";
 724  1
     String[] attributes = {};
 725  1
     String[] expressions = {
 726   
         // expression, result, expecption
 727   
         "${variable}", "localvalue", "false",
 728   
         "${../variable}", "parentvalue", "false",
 729   
         "${parentvariable}", "parentvalue", "false",
 730   
         "${./parentvariable}", "", "true",
 731   
         "${invalid}", "", "true"
 732   
     };
 733   
 
 734  1
     Element element1 = m_fixture.newElement(elementName, attributes);
 735   
 
 736  1
     IXMLTestCase testCase = m_fixture.getTestCase();
 737  1
     IXMLTestSuite testSuite = m_fixture.getTestSuite();
 738   
 
 739  1
     m_abstractTagHandler = new ImplTagHandler(element1, testCase);
 740   
 
 741   
     // Load the properties into the test case and suite.
 742  1
     testCase.addProperty("variable", "localvalue");
 743  1
     testSuite.addProperty("variable", "parentvalue");
 744  1
     testSuite.addProperty("parentvariable", "parentvalue");
 745   
 
 746  1
     String expression;
 747  1
     String result;
 748  1
     String expect;
 749  1
     boolean expException;
 750  1
     for (int i = 0; i < expressions.length; i += 3) {
 751   
 
 752  5
       expException = false;
 753  5
       if ("true".equals(expressions[i + 2])) {
 754  2
           expException = true;
 755   
       }
 756  5
       expect = expressions[i + 1];
 757  5
       expression = expressions[i];
 758   
 
 759  5
       boolean exception = false;
 760  5
       try {
 761  5
         result = m_abstractTagHandler.resolveVariables(expression);
 762  5
         assertEquals("Compare results:" + expression, expect, result);
 763   
       } catch (RuntimeException e) {
 764  0
         if (!expException) {
 765  0
           throw e;
 766   
         }
 767   
       }
 768   
     }
 769   
   }
 770   
 
 771   
 }
 772