You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2013/08/10 18:39:19 UTC
svn commit: r1512793 -
/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
Author: ggregory
Date: Sat Aug 10 16:39:18 2013
New Revision: 1512793
URL: http://svn.apache.org/r1512793
Log:
Add and @Ignore a XML Schema validation test until we settle on XML Schema itself.
Modified:
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java?rev=1512793&r1=1512792&r2=1512793&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java (original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java Sat Aug 10 16:39:18 2013
@@ -23,12 +23,21 @@ import static org.junit.Assert.assertTru
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStreamReader;
+import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
+import javax.xml.XMLConstants;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -38,11 +47,14 @@ import org.apache.logging.log4j.core.Log
import org.apache.logging.log4j.core.filter.ThreadContextMapFilter;
import org.apache.logging.log4j.status.StatusLogger;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
+import org.xml.sax.SAXException;
/**
*
@@ -52,13 +64,12 @@ public class XMLConfigurationTest {
@Parameters
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {
- {"log4j-test1.xml", "target/test.log"},
- {"log4j-xinclude.xml", "target/test.log"}});
+ return Arrays.asList(new Object[][] { { "log4j-test1.xml", "target/test.log" },
+ { "log4j-xinclude.xml", "target/test.log" } });
}
private final String configFile;
- private final String logFile ;
+ private final String logFile;
public XMLConfigurationTest(String configFile, String logFile) {
super();
@@ -102,7 +113,7 @@ public class XMLConfigurationTest {
ctx.reconfigure();
}
}
-
+
@After
public void tearDown() {
System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
@@ -139,4 +150,17 @@ public class XMLConfigurationTest {
assertEquals(a.getName(), "STDOUT");
}
+ @Test
+ @Ignore
+ public void testValidation() throws SAXException, IOException {
+ URL schemaFile = ClassLoader.getSystemResource("Log4j-config.xsd");
+ URL xmlFile = ClassLoader.getSystemResource(configFile);
+ Assert.assertNotNull(schemaFile);
+ Source xmlSource = new StreamSource(xmlFile.toString());
+ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema schema = schemaFactory.newSchema(schemaFile);
+ Validator validator = schema.newValidator();
+ validator.validate(xmlSource);
+ }
+
}