You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
3.1 KiB
82 lines
3.1 KiB
package de.memtext.util; |
|
|
|
import java.io.File; |
|
import java.io.FileFilter; |
|
import java.util.ArrayList; |
|
|
|
import javax.xml.transform.TransformerConfigurationException; |
|
|
|
import org.apache.log4j.Logger; |
|
import org.apache.log4j.spi.LoggingEvent; |
|
import org.apache.log4j.Level; |
|
//import org.apache.log4j.ConsoleAppender; |
|
//import org.apache.log4j.Layout; |
|
//import org.apache.log4j.PatternLayout; |
|
import org.junit.Assert; |
|
import org.junit.Test; |
|
|
|
import de.superx.util.UnittestAppender; |
|
|
|
public class TransletUtilsTest { |
|
|
|
private FileFilter filter = new XslFilter(); |
|
|
|
/** |
|
* @author Witt |
|
* this test checks the 'xml' folder for xsl files and tries to compile template from them |
|
* some xsl's are excluded from the test, as they are only meant to be included in other xsl's and will not work in isolation |
|
*/ |
|
@Test |
|
public void testXSLs() { |
|
Logger logger = Logger.getLogger(TransletUtils.class); |
|
logger.setAdditivity(false); |
|
logger.removeAllAppenders(); |
|
logger.setLevel(Level.ERROR); |
|
UnittestAppender ta = new UnittestAppender(); |
|
logger.addAppender(ta); |
|
//Layout layout = new PatternLayout(); |
|
//rl.addAppender(new ConsoleAppender(layout)); |
|
|
|
String cwd = System.getProperty("user.dir"); |
|
File folder = new File(cwd + File.separator + "superx" + File.separator + "xml" + File.separator); |
|
File[] xslFiles = folder.listFiles(this.filter); |
|
for(File file : xslFiles) { |
|
String url = "file:///" + file.getAbsoluteFile().toString(); |
|
try { |
|
TransletUtils.createTemplate(url); |
|
} |
|
catch (TransformerConfigurationException tce) { |
|
// Exceptions are handled by error listener in TransUtils and collected by UnittestAppender |
|
} |
|
} |
|
for (LoggingEvent event : ta.loggingEventList) { |
|
System.err.println(event.getMessage()); |
|
} |
|
Assert.assertTrue("there should be no errors logged", ta.loggingEventList.size() == 0); |
|
} |
|
|
|
private static class XslFilter implements FileFilter { |
|
|
|
private ArrayList<String> excludedFiles = new ArrayList<String>(); |
|
|
|
public XslFilter() { |
|
// exclude some files, as they have dependencies, that will only be available in a context, where they are included themselves |
|
this.excludedFiles.add("interLinks_html.xsl"); |
|
this.excludedFiles.add("interLinks_html_bil.xsl"); |
|
this.excludedFiles.add("man_patch.xsl"); |
|
this.excludedFiles.add("maskComponents_html.xsl"); |
|
this.excludedFiles.add("tabelle_fo_pdf_kopffusszeile.xsl"); |
|
this.excludedFiles.add("tabelle_html_doc_p.xsl"); |
|
this.excludedFiles.add("tabelle_html_ohne_legende.xsl"); |
|
this.excludedFiles.add("tabelle_rtf_doc.xsl"); |
|
} |
|
|
|
@Override |
|
public boolean accept(File pathname) { |
|
if (!pathname.toString().endsWith("xsl")) { return false; } |
|
if (this.excludedFiles.contains(pathname.getName())) { return false; } |
|
return true; |
|
} |
|
} |
|
|
|
}
|
|
|