]> source.dussan.org Git - sonarqube.git/commitdiff
checkstyle unit tests must not request http://www.puppycrawl.com when parsing XML...
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 28 Sep 2010 12:52:26 +0000 (12:52 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 28 Sep 2010 12:52:26 +0000 (12:52 +0000)
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java

index ab91ee2f6470dea27ccae262cc9c11b24d051511..96b8acfe714858a9cf8d4bee20fdaeb445139454 100644 (file)
@@ -39,6 +39,7 @@ import java.util.List;
 
 public class CheckstyleProfileExporter extends ProfileExporter {
 
+  static final String DOCTYPE_DECLARATION = "<!DOCTYPE module PUBLIC \"-//Puppy Crawl//DTD Check Configuration 1.2//EN\" \"http://www.puppycrawl.com/dtds/configuration_1_2.dtd\">";
   private Configuration conf;
 
   public CheckstyleProfileExporter(Configuration conf) {
@@ -76,7 +77,7 @@ public class CheckstyleProfileExporter extends ProfileExporter {
 
   private void appendXmlHeader(Writer writer) throws IOException {
     writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-        + "<!DOCTYPE module PUBLIC \"-//Puppy Crawl//DTD Check Configuration 1.2//EN\" \"http://www.puppycrawl.com/dtds/configuration_1_2.dtd\">"
+        + DOCTYPE_DECLARATION
         + "<!-- Generated by Sonar -->"
         + "<module name=\"Checker\">");
   }
index a7c4ff76e720615f818882202f761499af7d6e35..88010b7a9190ad51359914699f8d50cc67f1f1f7 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.plugins.checkstyle;
 
 import org.apache.commons.configuration.BaseConfiguration;
 import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
 import org.junit.Test;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.rules.Rule;
@@ -42,7 +43,7 @@ public class CheckstyleProfileExporterTest {
 
     TestUtils.assertSimilarXml(
         TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/alwaysSetFileContentsHolderAndSuppressionCommentFilter.xml"),
-        writer.toString());
+        sanitizeForTests(writer.toString()));
   }
   @Test
   public void noCheckstyleRulesToExport() throws IOException, SAXException {
@@ -56,7 +57,7 @@ public class CheckstyleProfileExporterTest {
 
     TestUtils.assertSimilarXml(
         TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/noCheckstyleRulesToExport.xml"),
-        writer.toString());
+        sanitizeForTests(writer.toString()));
   }
 
   @Test
@@ -77,7 +78,7 @@ public class CheckstyleProfileExporterTest {
 
     TestUtils.assertSimilarXml(
         TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/singleCheckstyleRulesToExport.xml"),
-        writer.toString());
+        sanitizeForTests(writer.toString()));
   }
 
   @Test
@@ -94,7 +95,7 @@ public class CheckstyleProfileExporterTest {
 
     TestUtils.assertSimilarXml(
         TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addTheIdPropertyWhenManyInstancesWithTheSameConfigKey.xml"),
-        writer.toString());
+        sanitizeForTests(writer.toString()));
   }
 
   @Test
@@ -114,7 +115,7 @@ public class CheckstyleProfileExporterTest {
 
     TestUtils.assertSimilarXml(
         TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/exportParameters.xml"),
-        writer.toString());
+        sanitizeForTests(writer.toString()));
   }
 
 
@@ -137,6 +138,12 @@ public class CheckstyleProfileExporterTest {
 
     TestUtils.assertSimilarXml(
         TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addCustomFilters.xml"),
-        writer.toString());
+        sanitizeForTests(writer.toString()));
+  }
+
+
+  private static String sanitizeForTests(String xml) {
+    // remove the doctype declaration, else the unit test fails when executed offline
+    return StringUtils.remove(xml, CheckstyleProfileExporter.DOCTYPE_DECLARATION);
   }
 }