stendhal/tests/conf/PortalMatchTestTest.java

64 lines
2.5 KiB
Java
Raw Permalink Normal View History

2010-09-19 01:29:21 +00:00
/***************************************************************************
* (C) Copyright 2003-2015 - Stendhal *
2010-09-19 01:29:21 +00:00
***************************************************************************
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
package conf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import java.io.File;
2008-01-20 00:10:48 +00:00
import java.io.IOException;
import java.util.LinkedList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
2008-01-20 00:10:48 +00:00
import javax.xml.parsers.ParserConfigurationException;
import org.junit.Test;
import org.w3c.dom.Document;
2008-01-20 00:10:48 +00:00
import org.xml.sax.SAXException;
import marauroa.common.Log4J;
2007-08-15 21:16:46 +00:00
/**
* Tests for PortalMatcherTest
*/
public class PortalMatchTestTest {
2007-08-15 21:16:46 +00:00
/**
* Test the validation method
*
* @throws ParserConfigurationException in case of an invalid zone file
* @throws SAXException in case of an invalid zone file
* @throws IOException in case of an input/output error
*/
2007-08-15 21:16:46 +00:00
@Test
2008-01-20 00:10:48 +00:00
public void testvalidate() throws ParserConfigurationException, SAXException, IOException {
Log4J.init();
2008-01-20 00:10:48 +00:00
final PortalMatchTest pmt = new PortalMatchTest();
LinkedList<PortalTestObject> portals = new LinkedList<PortalTestObject>();
2008-01-20 00:10:48 +00:00
final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
2007-08-15 21:16:46 +00:00
.newInstance();
2008-01-20 00:10:48 +00:00
final DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
2007-08-15 21:16:46 +00:00
Document xmldoc = docBuilder.parse(new File("tests/conf/valid.xml"));
portals.addAll(pmt.proceedDocument(xmldoc));
assertThat("all portals in this test file are valid", pmt.isValid(portals), equalTo(""));
portals = new LinkedList<PortalTestObject>();
2007-08-15 21:16:46 +00:00
xmldoc = docBuilder.parse(new File("tests/conf/invalid.xml"));
portals.addAll(pmt.proceedDocument(xmldoc));
assertThat("there is a known bad in it", pmt.isValid(portals), not(equalTo("")));
2007-08-15 21:16:46 +00:00
}
}