Clover coverage report - angkor - 0.4
Coverage timestamp: ti okt 15 2002 22:32:48 CEST
file stats: LOC: 96   Methods: 6
NCLOC: 71   Classes: 1
Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
TestUtility.java 100% 60,6% 66,7% 68,1%
 1   
 /*
 2   
  * Angkor Web Framework
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at gnu.org.
 6   
  */
 7   
 
 8   
 package com.tirsen.angkor.test.unit;
 9   
 
 10   
 import com.tirsen.angkor.Component;
 11   
 import com.tirsen.angkor.test.unit.mock.MockRenderContext;
 12   
 import junit.framework.Assert;
 13   
 import org.w3c.dom.Document;
 14   
 import org.w3c.dom.Element;
 15   
 import org.w3c.dom.NodeList;
 16   
 import org.jaxen.jdom.JDOMXPath;
 17   
 import org.jaxen.JaxenException;
 18   
 
 19   
 import java.io.IOException;
 20   
 
 21   
 /**
 22   
  * TODO document TestUtility.
 23   
  *
 24   
  * @author $Author: tirsen $
 25   
  * @version $Revision: 1.7 $
 26   
  * <BR>
 27   
  * $Id: TestUtility.java,v 1.7 2002/10/13 19:59:23 tirsen Exp $
 28   
  */
 29   
 public class TestUtility extends Assert
 30   
 {
 31  2
     public static org.jdom.Element selectElement(org.jdom.Document document, String xpath)
 32   
     {
 33  2
         org.jdom.Element element = null;
 34  2
         try
 35   
         {
 36  2
             JDOMXPath jdomxPath = new JDOMXPath(xpath);
 37  2
             element = (org.jdom.Element) jdomxPath.selectSingleNode(document);
 38   
         }
 39   
         catch (JaxenException e)
 40   
         {
 41  0
             throw new RuntimeException(e);
 42   
         }
 43  2
         return element;
 44   
     }
 45   
 
 46  6
     public static Element findElementById(Document doc, String id)
 47   
     {
 48  6
         String idAttr = "id";
 49  6
         return findElementById(doc.getDocumentElement(), id, idAttr);
 50   
     }
 51   
 
 52  50
     public static Element findElementById(Element element, String id, String idAttr)
 53   
     {
 54  6
         if (id.equals(element.getAttribute(idAttr))) return element;
 55  44
         NodeList children = element.getChildNodes();
 56  44
         for (int i = 0; i < children.getLength(); i++)
 57   
         {
 58  48
             if (children.item(i) instanceof Element)
 59   
             {
 60  44
                 Element result = findElementById((Element) children.item(i), id, idAttr);
 61  23
                 if (result != null) return result;
 62   
             }
 63   
         }
 64  21
         return null;
 65   
     }
 66   
 
 67  0
     public static Element testComponent(MockRenderContext context, String componentName) throws IOException
 68   
     {
 69  0
         Component component = (Component) context.getApplication().getComponent(componentName).getView();
 70  0
         component.render(context);
 71  0
         Document doc = context.parseRenderedHTML();
 72  0
         System.out.println("component = " + component);
 73  0
         Element element = findElementById(doc, component.getId());
 74  0
         assertNotNull("component " + componentName + " was not rendered", element);
 75  0
         assertTrue("id not rendered correctly", component.getId().equals(element.getAttribute("id")));
 76   
 
 77  0
         return element;
 78   
     }
 79   
 
 80  0
     public static Element testComponent(MockRenderContext context, Component component) throws IOException
 81   
     {
 82  0
         component.render(context);
 83  0
         Document doc = context.parseRenderedHTML();
 84  0
         System.out.println("component = " + component);
 85  0
         return testComponent(doc, component);
 86   
     }
 87   
 
 88  3
     public static Element testComponent(Document doc, Component component)
 89   
     {
 90  3
         Element element = findElementById(doc, component.getId());
 91  3
         assertNotNull("component " + component + " was not rendered", element);
 92  3
         assertTrue("id not rendered correctly", component.getId().equals(element.getAttribute("id")));
 93  3
         return element;
 94   
     }
 95   
 }
 96