]> source.dussan.org Git - sonarqube.git/commitdiff
Remove XMLUnit from sonar-testing-harness
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 Apr 2014 13:17:18 +0000 (15:17 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 Apr 2014 13:17:48 +0000 (15:17 +0200)
sonar-server/pom.xml
sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java
sonar-testing-harness/pom.xml
sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java
sonar-testing-harness/src/test/java/org/sonar/test/TestUtilsTest.java

index 9b798cee8d8dfbcb73c9c1cafe50be7c191834b7..36162c19afeddc42ae9a8097422924ccc7a2a667 100644 (file)
       <artifactId>elasticsearch-test</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>xmlunit</groupId>
+      <artifactId>xmlunit</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 
index ff7cf0916252ee9fe38350e294de394de5e44a20..5629a09dbcb579fc86fdc0669f3a9d737d680b20 100644 (file)
 package org.sonar.server.debt;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.CharUtils;
 import org.apache.commons.lang.SystemUtils;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
@@ -34,6 +37,7 @@ import java.util.regex.Pattern;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.assertTrue;
 import static org.sonar.server.debt.DebtModelXMLExporter.DebtModel;
 import static org.sonar.server.debt.DebtModelXMLExporter.RuleDebt;
 
@@ -63,7 +67,14 @@ public class DebtModelXMLExporterTest {
         .setSubCharacteristicKey("MEMORY_USE").setFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()).setCoefficient("3d").setOffset("15min")
     );
 
-    TestUtils.assertSimilarXml(getFileContent("export_xml.xml"), xmlExporter.export(debtModel, rules));
+    assertSimilarXml(getFileContent("export_xml.xml"), xmlExporter.export(debtModel, rules));
+  }
+
+  public static void assertSimilarXml(String expectedXml, String xml) throws Exception {
+    XMLUnit.setIgnoreWhitespace(true);
+    Diff diff = XMLUnit.compareXML(xml, expectedXml);
+    String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml;
+    assertTrue(message, diff.similar());
   }
 
   @Test
index ebab6e6459e9b3d139d99572832b07ac9ad3e733..65d7a16745aeeabeed3229f2fd71c2b3ae4eea3c 100644 (file)
@@ -49,9 +49,5 @@
       <version>${project.version}</version>
       <type>test-jar</type>
     </dependency>
-    <dependency>
-      <groupId>xmlunit</groupId>
-      <artifactId>xmlunit</artifactId>
-    </dependency>
   </dependencies>
 </project>
index 3b4d68448ca6d94e6e37d5f38d7729f386fb2f0c..eedcee75337fa78e8c875626d03dd2648ef816a2 100644 (file)
  */
 package org.sonar.test;
 
-import com.google.common.base.Throwables;
 import org.apache.commons.io.Charsets;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharUtils;
 import org.apache.commons.lang.StringUtils;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
 import org.sonar.api.utils.SonarException;
 
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 
-import static org.junit.Assert.assertTrue;
-
 /**
  * Utilities for unit tests
  *
@@ -90,50 +84,4 @@ public final class TestUtils {
     resourcePath += path;
     return getResource(resourcePath);
   }
-
-  /**
-   * Shortcut for getTestTempDir(baseClass, testName, true) : cleans the unit test directory
-   */
-  public static File getTestTempDir(Class baseClass, String testName) {
-    return getTestTempDir(baseClass, testName, true);
-  }
-
-  /**
-   * Create a temporary directory for unit tests.
-   *
-   * @param baseClass the unit test class
-   * @param testName  the test name
-   * @param clean     remove all the sub-directories and files ?
-   */
-  public static File getTestTempDir(Class baseClass, String testName, boolean clean) {
-    File dir = new File("target/test-tmp/" + baseClass.getCanonicalName() + "/" + testName);
-    if (clean && dir.exists()) {
-      try {
-        FileUtils.deleteDirectory(dir);
-      } catch (IOException e) {
-        throw new SonarException("Can not delete the directory " + dir, e);
-      }
-    }
-    try {
-      FileUtils.forceMkdir(dir);
-    } catch (IOException e) {
-      throw new SonarException("Can not create the directory " + dir, e);
-    }
-    return dir;
-  }
-
-  public static void assertSimilarXml(String expectedXml, String xml) {
-    Diff diff = isSimilarXml(expectedXml, xml);
-    String message = "Diff: " + diff.toString() + CharUtils.LF + "XML: " + xml;
-    assertTrue(message, diff.similar());
-  }
-
-  static Diff isSimilarXml(String expectedXml, String xml) {
-    XMLUnit.setIgnoreWhitespace(true);
-    try {
-      return XMLUnit.compareXML(xml, expectedXml);
-    } catch (Exception e) {
-      throw Throwables.propagate(e);
-    }
-  }
 }
index 0f44c7443f72f66c337ef2baa81154634f8be903..54a0d903357f1f99cc3b18c4c9bafb989aba5cdd 100644 (file)
  */
 package org.sonar.test;
 
-import static org.fest.assertions.Assertions.assertThat;
-import static org.sonar.test.TestUtils.assertSimilarXml;
-import static org.sonar.test.TestUtils.getResource;
-import static org.sonar.test.TestUtils.getTestTempDir;
-import static org.sonar.test.TestUtils.isSimilarXml;
+import org.junit.Test;
 
 import java.io.File;
 
-import org.apache.commons.io.FileUtils;
-import org.junit.Test;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.sonar.test.TestUtils.getResource;
 
 public class TestUtilsTest {
 
@@ -49,39 +45,4 @@ public class TestUtilsTest {
     File file = getResource("org/sonar/test/TestUtilsTest/unknown.txt");
     assertThat(file).isNull();
   }
-
-  @Test
-  public void testTempDir() throws Exception {
-    File dir = getTestTempDir(getClass(), "testTempDir");
-    assertThat(dir).exists().isDirectory();
-    assertThat(dir.listFiles()).isEmpty();
-
-    FileUtils.writeStringToFile(new File(dir, "bar.txt"), "some text");
-    assertThat(dir.listFiles()).hasSize(1);
-
-    // the directory is cleaned
-    dir = getTestTempDir(getClass(), "testTempDir");
-    assertThat(dir).exists().isDirectory();
-    assertThat(dir.listFiles()).isEmpty();
-  }
-
-  @Test
-  public void testAssertSimilarXml() throws Exception {
-    assertSimilarXml("<foo></foo>", "<foo />");
-
-    // order of attributes
-    assertSimilarXml("<foo><bar id='1' key='one' /></foo>", "<foo><bar key='one' id='1' /></foo>");
-
-    // whitespaces are ignored
-    assertSimilarXml("<foo>     <bar />   </foo>", "<foo><bar/></foo>");
-
-    // attribute values are checked
-    assertThat(isSimilarXml("<foo id='1' />", "<foo id='2'/>").similar()).isFalse();
-
-    // different xml
-    assertThat(isSimilarXml("<foo id='1' />", "<foo id='2'/>").similar()).isFalse();
-
-    // order of nodes is important
-    assertThat(isSimilarXml("<foo><bar id='1' /><bar id='2' /></foo>", "<foo><bar id='2' /><bar id='1' /></foo>").similar()).isFalse();
-  }
 }