Skip to content
Snippets Groups Projects
Commit 7e40976f authored by Goik Martin's avatar Goik Martin
Browse files

Well-formedness becomes precondition (Junit Assume) for test executions

parent 4131d880
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ public class Memo2HtmlHandler extends DefaultHandler implements SaxFilter {
@Override
public void startDocument() throws SAXException {
out.print("<html>" + "\n <head>" + "\n <title>Memo message</title>"
out.print("<html" + "\n <head>" + "\n <title>Memo message</title>"
+ "\n </head>" + "\n <body>");
}
......
package de.hdm_stuttgart.de.testing.dom;
package de.hdm_stuttgart.de.mi.exam.testing;
import java.util.List;
......
package de.hdm_stuttgart.de.testing.dom;
package de.hdm_stuttgart.de.mi.exam.testing;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
......@@ -13,6 +13,8 @@ import javax.xml.parsers.SAXParserFactory;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.junit.Assume;
import org.junit.Before;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
......@@ -28,7 +30,7 @@ public abstract class SaxFilterTest {
public final String xmlInputFileName, htmlOutputFileName;
final SaxFilter saxHandler;
protected static String errorInitString = null;
protected static String initializationErrorString = null;
protected static Element htmlRootElement = null;
......@@ -39,14 +41,14 @@ public abstract class SaxFilterTest {
htmlOutputFileName = xmlInputFileName + resultFileExtension;
this.saxHandler = saxHandler;
if (null == htmlRootElement) {
if (null == htmlRootElement && null == initializationErrorString) {
final PrintStream out;
try {
out = new PrintStream(htmlOutputFileName);
} catch (FileNotFoundException e1) {
errorInitString = "Unable to open file '" + htmlOutputFileName
initializationErrorString = "Unable to open file '" + htmlOutputFileName
+ "' for writing";
return;
}
......@@ -62,13 +64,13 @@ public abstract class SaxFilterTest {
xmlReader.setErrorHandler(new StandardErrorHandler());
} catch (SAXException | ParserConfigurationException e) {
errorInitString = "Unable to create XMLparser instance: " + e.getLocalizedMessage();
initializationErrorString = "Unable to create XMLparser instance: " + e.getLocalizedMessage();
return;
}
try {
xmlReader.parse(xmlInputFileName);
} catch (SAXException | IOException e) {
errorInitString = "Unable parse file '" + xmlInputFileName
initializationErrorString = "Unable parse file '" + xmlInputFileName
+ "': " + e.getLocalizedMessage();
return;
}
......@@ -80,18 +82,21 @@ public abstract class SaxFilterTest {
final SAXBuilder parser = new SAXBuilder();
try {
htmlRootElement = parser.build(htmlOutputFileName)
.getRootElement();
htmlRootElement = parser.build(htmlOutputFileName).getRootElement();
} catch (JDOMException | IOException e1) {
System.err.print(
errorInitString = "Unable to parse file '" + htmlOutputFileName
+ "':\n" + e1.getLocalizedMessage() +
"\n, exiting");
System.exit(1);
initializationErrorString = "Unable to parse file '" + htmlOutputFileName
+ "':\n" + e1.getLocalizedMessage());
return;
}
}
}
@Before
public void checkWellFormedness() {
Assume.assumeTrue("Previous error:" + initializationErrorString, null == initializationErrorString);
//Assert.assertNull("Unable to parse generated file:" + errorInitString, errorInitString);
}
private void printResultToStdout() {
try {
......@@ -103,7 +108,7 @@ public abstract class SaxFilterTest {
}
saxResult.close();
} catch (IOException e) {
errorInitString = "Unable to open expected result output file '"
initializationErrorString = "Unable to open expected result output file '"
+ htmlOutputFileName + "' :" + e.getLocalizedMessage();
}
}
......
package de.hdm_stuttgart.de.sda1.saxhtml.v1.test;
import org.junit.Assert;
import org.junit.Test;
import de.hdm_stuttgart.de.testing.dom.SaxFilterTest;
import de.hdm_stuttgart.de.testing.dom.DomAssert;
import de.hdm_stuttgart.de.mi.exam.testing.DomAssert;
import de.hdm_stuttgart.de.mi.exam.testing.SaxFilterTest;
import de.hdm_stuttgart.mi.sda1.saxhtml.v1.Memo2HtmlHandler;
/**
......@@ -17,10 +16,6 @@ public class TestSimpleSaxTransform extends SaxFilterTest {
super("src/main/resources/memo.xml", new Memo2HtmlHandler(), ".1.html");
}
@Test public void checkWellFormedness() {
Assert.assertNull("Unable to parse generated file:" + errorInitString, errorInitString);
}
@Test public void testSenderInHeader() {
DomAssert.assertSingleNodeContent("<title>Memo message</title> must be the only child of <head>", htmlRootElement, "head/*", "title", "Memo message");
}
......
......@@ -2,8 +2,8 @@ package de.hdm_stuttgart.de.sda1.saxhtml.v2.test;
import org.junit.Test;
import de.hdm_stuttgart.de.testing.dom.SaxFilterTest;
import de.hdm_stuttgart.de.testing.dom.DomAssert;
import de.hdm_stuttgart.de.mi.exam.testing.DomAssert;
import de.hdm_stuttgart.de.mi.exam.testing.SaxFilterTest;
import de.hdm_stuttgart.mi.sda1.saxhtml.v2.Memo2HtmlHandler;
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment