From: Astrid S. <ast...@us...> - 2008-01-19 23:11:04
|
Update of /cvsroot/arianne/stendhal/tests/conf In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv6684/tests/conf Modified Files: PortalMatchTest.java PortalMatchTestTest.java Log Message: portalmatch test now searches all *xml in /data/conf/zones Index: PortalMatchTestTest.java =================================================================== RCS file: /cvsroot/arianne/stendhal/tests/conf/PortalMatchTestTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PortalMatchTestTest.java 18 Jan 2008 01:01:16 -0000 1.7 --- PortalMatchTestTest.java 19 Jan 2008 23:11:03 -0000 1.8 *************** *** 10,13 **** --- 10,15 ---- import javax.xml.parsers.DocumentBuilderFactory; + import marauroa.common.Log4J; + import org.junit.Test; import org.w3c.dom.Document; *************** *** 19,22 **** --- 21,25 ---- @Test public void testvalidate() throws Exception { + Log4J.init(); LinkedList<PortalTestObject> portals = new LinkedList<PortalTestObject>(); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory Index: PortalMatchTest.java =================================================================== RCS file: /cvsroot/arianne/stendhal/tests/conf/PortalMatchTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PortalMatchTest.java 18 Jan 2008 01:01:15 -0000 1.10 --- PortalMatchTest.java 19 Jan 2008 23:11:03 -0000 1.11 *************** *** 2,12 **** import static org.junit.Assert.assertTrue; ! import java.io.File; import java.util.LinkedList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.junit.Test; import org.w3c.dom.Document; --- 2,17 ---- import static org.junit.Assert.assertTrue; ! import static org.junit.Assert.*; import java.io.File; + import java.io.FileFilter; import java.util.LinkedList; + import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; + import marauroa.common.Log4J; + + import org.apache.log4j.Logger; import org.junit.Test; import org.w3c.dom.Document; *************** *** 16,51 **** public class PortalMatchTest { ! private LinkedList<PortalTestObject> portals = new LinkedList<PortalTestObject>(); @Test ! public void testread() throws Exception { ! try { ! DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); ! DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); ! // todo:make this read directory content ! String[] zonesxml = { "ados.xml", "amazon.xml", "athor.xml", ! "fado.xml", "kalavan.xml", "kikareukin.xml", "kirdneh.xml", ! "misc.xml", "nalwor.xml", "orril.xml", "semos.xml" }; ! for (int zone = 0; zone < zonesxml.length; zone++) { ! Document doc = docBuilder.parse(new File("data/conf/zones/" ! + zonesxml[zone])); portals.addAll(proceedDocument(doc)); } } catch (SAXParseException err) { ! System.out.println("** Parsing error" + ", line " ! + err.getLineNumber() + ", uri " + err.getSystemId()); ! System.out.println(" " + err.getMessage()); } catch (SAXException e) { ! Exception x = e.getException(); ! ((x == null) ? e : x).printStackTrace(); ! ! } catch (Throwable t) { ! t.printStackTrace(); } --- 21,59 ---- public class PortalMatchTest { ! private static final Logger logger = Logger.getLogger(PortalMatchTest.class); ! private final transient List<PortalTestObject> portals = new LinkedList<PortalTestObject>(); @Test ! public void testread() { ! Log4J.init(); try { ! final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); ! final DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); ! ! final File directory = new File("data/conf/zones/"); ! final File[] files = directory.listFiles(new FileFilter() { ! public boolean accept(File file) { ! return file.getName().endsWith("xml"); ! } ! }); + assertFalse("files should not be empty", files.length == 0); + for (File f : files) { + final Document doc = docBuilder.parse(f); portals.addAll(proceedDocument(doc)); } } catch (SAXParseException err) { ! ! fail(err.toString()); } catch (SAXException e) { ! ! fail(e.toString()); ! } catch (Exception t) { ! ! fail(t.toString()); } *************** *** 54,60 **** } ! LinkedList<PortalTestObject> proceedDocument(Document xmldoc) { // normalize text representation ! LinkedList<PortalTestObject> tempList = new LinkedList<PortalTestObject>(); String zone = ""; String destZone = ""; --- 62,68 ---- } ! List<PortalTestObject> proceedDocument(final Document xmldoc) { // normalize text representation ! final List<PortalTestObject> tempList = new LinkedList<PortalTestObject>(); String zone = ""; String destZone = ""; *************** *** 63,75 **** xmldoc.getDocumentElement().normalize(); ! NodeList listOfPortals = xmldoc.getElementsByTagName("portal"); if (listOfPortals.getLength() > 0) { ! listOfPortals.item(0).getAttributes().item(0).toString(); for (int s = 0; s < listOfPortals.getLength(); s++) { zone = listOfPortals.item(s).getParentNode().getAttributes().getNamedItem( "name").getNodeValue(); name = listOfPortals.item(s).getAttributes().getNamedItem("ref").getNodeValue(); ! listOfPortals.item(s).getNodeName(); ! NodeList listofChildren = listOfPortals.item(s).getChildNodes(); for (int i = 0; i < listofChildren.getLength(); i++) { if ("destination".equals(listofChildren.item(i).getNodeName())) { --- 71,83 ---- xmldoc.getDocumentElement().normalize(); ! final NodeList listOfPortals = xmldoc.getElementsByTagName("portal"); if (listOfPortals.getLength() > 0) { ! for (int s = 0; s < listOfPortals.getLength(); s++) { zone = listOfPortals.item(s).getParentNode().getAttributes().getNamedItem( "name").getNodeValue(); name = listOfPortals.item(s).getAttributes().getNamedItem("ref").getNodeValue(); ! ! final NodeList listofChildren = listOfPortals.item(s).getChildNodes(); for (int i = 0; i < listofChildren.getLength(); i++) { if ("destination".equals(listofChildren.item(i).getNodeName())) { *************** *** 88,92 **** } ! public boolean isValid(LinkedList<PortalTestObject> testList) { boolean result = true; --- 96,100 ---- } ! public boolean isValid(final List<PortalTestObject> testList) { boolean result = true; *************** *** 101,105 **** } if (!founddestination) { ! System.out.println(x.toString()); } --- 109,113 ---- } if (!founddestination) { ! logger.warn(x.toString()); } |