2010-09-19 01:29:21 +00:00
|
|
|
/***************************************************************************
|
2015-08-16 18:33:08 +02: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. *
|
|
|
|
|
* *
|
|
|
|
|
***************************************************************************/
|
2007-04-19 15:06:31 +00:00
|
|
|
package conf;
|
|
|
|
|
|
2015-08-16 18:33:08 +02:00
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
|
|
import static org.hamcrest.CoreMatchers.not;
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
2007-04-19 15:06:31 +00:00
|
|
|
|
|
|
|
|
import java.io.File;
|
2008-01-20 00:10:48 +00:00
|
|
|
import java.io.IOException;
|
2007-04-19 15:06:31 +00:00
|
|
|
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;
|
2007-04-19 15:06:31 +00:00
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.w3c.dom.Document;
|
2008-01-20 00:10:48 +00:00
|
|
|
import org.xml.sax.SAXException;
|
2007-04-19 15:06:31 +00:00
|
|
|
|
2015-08-16 18:33:08 +02:00
|
|
|
import marauroa.common.Log4J;
|
2007-08-15 21:16:46 +00:00
|
|
|
|
2015-08-16 18:33:08 +02:00
|
|
|
/**
|
|
|
|
|
* Tests for PortalMatcherTest
|
|
|
|
|
*/
|
|
|
|
|
public class PortalMatchTestTest {
|
2007-08-15 21:16:46 +00:00
|
|
|
|
2015-08-16 18:33:08 +02: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 {
|
2008-01-19 23:11:03 +00:00
|
|
|
Log4J.init();
|
2008-01-20 00:10:48 +00:00
|
|
|
final PortalMatchTest pmt = new PortalMatchTest();
|
2008-01-18 01:01:16 +00:00
|
|
|
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));
|
2015-08-16 18:33:08 +02:00
|
|
|
assertThat("all portals in this test file are valid", pmt.isValid(portals), equalTo(""));
|
2008-01-18 01:01:16 +00:00
|
|
|
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));
|
2015-08-16 18:33:08 +02:00
|
|
|
assertThat("there is a known bad in it", pmt.isValid(portals), not(equalTo("")));
|
2007-08-15 21:16:46 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-19 15:06:31 +00:00
|
|
|
}
|