Skip to content

Commit

Permalink
Added additional test for #40
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed May 8, 2017
1 parent 4249ffd commit 2dea107
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
{}
}
16 changes: 16 additions & 0 deletions ph-schematron-ant-task/src/test/resources/issues/40v2/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="xml">
<taskdef name="schematron" classname="com.helger.schematron.ant.Schematron" />
<target name="check">
<schematron schematronFile="../sch/test.sch"
expectSuccess="true"
schematronProcessingEngine="pure">
<fileset dir=".">
<include name="test.xml" />
</fileset>
<xmlcatalog>
<dtd publicId="-//bla//DTD XML test//EN" location="../dtd/test.dtd"/>
</xmlcatalog>
</schematron>
</target>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
10 changes: 10 additions & 0 deletions ph-schematron-ant-task/src/test/resources/issues/40v2/sch/test.sch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"
xmlns="http://purl.oclc.org/dsdl/schematron"
queryBinding="xslt2">
<sch:pattern id="sampleValidation">
<sch:rule context="/">
<assert test="note">root element must be 'note'</assert>
</sch:rule>
</sch:pattern>
</sch:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE note PUBLIC "-//bla//DTD XML test//EN" "http://example.org/note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

0 comments on commit 2dea107

Please sign in to comment.