From 2dea10709aad6557b911902056d6ed7f6467fee7 Mon Sep 17 00:00:00 2001 From: Philip Helger Date: Mon, 8 May 2017 10:07:18 +0200 Subject: [PATCH] Added additional test for #40 --- .../helger/schematron/ant/Issue40Test.java | 38 +--------------- .../helger/schematron/ant/Issue40v2Test.java | 38 ++++++++++++++++ .../schematron/ant/LoggingBuildListener.java | 44 +++++++++++++++++++ .../src/test/resources/issues/40v2/build.xml | 16 +++++++ .../test/resources/issues/40v2/dtd/test.dtd | 5 +++ .../test/resources/issues/40v2/sch/test.sch | 10 +++++ .../test/resources/issues/40v2/xml/test.xml | 8 ++++ 7 files changed, 122 insertions(+), 37 deletions(-) create mode 100644 ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/Issue40v2Test.java create mode 100644 ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/LoggingBuildListener.java create mode 100644 ph-schematron-ant-task/src/test/resources/issues/40v2/build.xml create mode 100644 ph-schematron-ant-task/src/test/resources/issues/40v2/dtd/test.dtd create mode 100644 ph-schematron-ant-task/src/test/resources/issues/40v2/sch/test.sch create mode 100644 ph-schematron-ant-task/src/test/resources/issues/40v2/xml/test.xml diff --git a/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/Issue40Test.java b/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/Issue40Test.java index 27b8878f8..dca13bde2 100644 --- a/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/Issue40Test.java +++ b/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/Issue40Test.java @@ -1,10 +1,7 @@ package com.helger.schematron.ant; -import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; -import org.apache.tools.ant.BuildListener; -import org.apache.tools.ant.Project; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -22,40 +19,7 @@ public final class Issue40Test public void init () { m_aBuildRule.configureProject ("src/test/resources/issues/40/build.xml"); - m_aBuildRule.getProject ().addBuildListener (new BuildListener () - { - public void taskStarted (final BuildEvent aEvent) - {} - - public void taskFinished (final BuildEvent aEvent) - {} - - public void targetStarted (final BuildEvent aEvent) - {} - - public void targetFinished (final BuildEvent aEvent) - {} - - public void messageLogged (final BuildEvent aEvent) - { - if (aEvent.getPriority () <= Project.MSG_ERR) - s_aLogger.error (aEvent.getMessage (), aEvent.getException ()); - else - if (aEvent.getPriority () <= Project.MSG_WARN) - s_aLogger.warn (aEvent.getMessage (), aEvent.getException ()); - else - if (aEvent.getPriority () <= Project.MSG_INFO) - s_aLogger.info (aEvent.getMessage (), aEvent.getException ()); - else - s_aLogger.debug (aEvent.getMessage (), aEvent.getException ()); - } - - public void buildStarted (final BuildEvent aEvent) - {} - - public void buildFinished (final BuildEvent aEvent) - {} - }); + m_aBuildRule.getProject ().addBuildListener (new LoggingBuildListener ()); } @Test diff --git a/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/Issue40v2Test.java b/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/Issue40v2Test.java new file mode 100644 index 000000000..c1d23f12f --- /dev/null +++ b/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/Issue40v2Test.java @@ -0,0 +1,38 @@ +package com.helger.schematron.ant; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class Issue40v2Test +{ + private static final Logger s_aLogger = LoggerFactory.getLogger (Issue40v2Test.class); + + @Rule + public final BuildFileRule m_aBuildRule = new BuildFileRule (); + + @Before + public void init () + { + m_aBuildRule.configureProject ("src/test/resources/issues/40v2/build.xml"); + m_aBuildRule.getProject ().addBuildListener (new LoggingBuildListener ()); + } + + @Test + public void testWithExternalDTD () + { + try + { + // Do not redirect stdout etc. + m_aBuildRule.getProject ().executeTarget ("check"); + } + catch (final BuildException ex) + { + s_aLogger.error ("Ooops", ex); + } + } +} diff --git a/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/LoggingBuildListener.java b/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/LoggingBuildListener.java new file mode 100644 index 000000000..92c6dd7cf --- /dev/null +++ b/ph-schematron-ant-task/src/test/java/com/helger/schematron/ant/LoggingBuildListener.java @@ -0,0 +1,44 @@ +package com.helger.schematron.ant; + +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildListener; +import org.apache.tools.ant.Project; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class LoggingBuildListener implements BuildListener +{ + private static final Logger s_aLogger = LoggerFactory.getLogger (LoggingBuildListener.class); + + public void taskStarted (final BuildEvent aEvent) + {} + + public void taskFinished (final BuildEvent aEvent) + {} + + public void targetStarted (final BuildEvent aEvent) + {} + + public void targetFinished (final BuildEvent aEvent) + {} + + public void messageLogged (final BuildEvent aEvent) + { + if (aEvent.getPriority () <= Project.MSG_ERR) + s_aLogger.error (aEvent.getMessage (), aEvent.getException ()); + else + if (aEvent.getPriority () <= Project.MSG_WARN) + s_aLogger.warn (aEvent.getMessage (), aEvent.getException ()); + else + if (aEvent.getPriority () <= Project.MSG_INFO) + s_aLogger.info (aEvent.getMessage (), aEvent.getException ()); + else + s_aLogger.info (aEvent.getMessage (), aEvent.getException ()); + } + + public void buildStarted (final BuildEvent aEvent) + {} + + public void buildFinished (final BuildEvent aEvent) + {} +} diff --git a/ph-schematron-ant-task/src/test/resources/issues/40v2/build.xml b/ph-schematron-ant-task/src/test/resources/issues/40v2/build.xml new file mode 100644 index 000000000..2217851a5 --- /dev/null +++ b/ph-schematron-ant-task/src/test/resources/issues/40v2/build.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/ph-schematron-ant-task/src/test/resources/issues/40v2/dtd/test.dtd b/ph-schematron-ant-task/src/test/resources/issues/40v2/dtd/test.dtd new file mode 100644 index 000000000..971736ab1 --- /dev/null +++ b/ph-schematron-ant-task/src/test/resources/issues/40v2/dtd/test.dtd @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/ph-schematron-ant-task/src/test/resources/issues/40v2/sch/test.sch b/ph-schematron-ant-task/src/test/resources/issues/40v2/sch/test.sch new file mode 100644 index 000000000..cacddcab3 --- /dev/null +++ b/ph-schematron-ant-task/src/test/resources/issues/40v2/sch/test.sch @@ -0,0 +1,10 @@ + + + + + root element must be 'note' + + + diff --git a/ph-schematron-ant-task/src/test/resources/issues/40v2/xml/test.xml b/ph-schematron-ant-task/src/test/resources/issues/40v2/xml/test.xml new file mode 100644 index 000000000..99d98efc5 --- /dev/null +++ b/ph-schematron-ant-task/src/test/resources/issues/40v2/xml/test.xml @@ -0,0 +1,8 @@ + + + + Tove + Jani + Reminder + Don't forget me this weekend! + \ No newline at end of file