/*
 * TestResponseXmlAction.java
 *
 * Created on 2007/11/15, 9:28
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package test.org.itscool.weber.action;

import org.itscool.weber.controller.Globals;
import org.itscool.weber.testcase.WeberTestCase;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 *
 * @author ios
 */
public class TestResponseXmlAction extends WeberTestCase{
    public void testDoExecute(){
        XmlResponseAction action = new XmlResponseAction();
        try{
            this.assertDoExecute(action, null, Globals.RET_NOFORWARD);
            Element root = responseXml.getDocumentElement();
            assertEquals("root tagName", root.getTagName(), "result" );
            
            NodeList nodeList = root.getElementsByTagName("bean");
            int size = nodeList.getLength();
            assertEquals("bean num", size, 1);
            Node node = nodeList.item(0);
            assertEquals("bean nodeName", node.getNodeName(), "bean");
            NodeList childs = node.getChildNodes();
            for(int i=0; i<childs.getLength(); i++){
                Node child = childs.item(i);
                if( child.getNodeName().equals("id") ){
                    assertEquals("id compare", child.getChildNodes().item(0).getNodeValue(), "1");
                }
            }
        }catch(Exception e){
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
}
