]> source.dussan.org Git - sonarqube.git/commitdiff
Replace lib org.skyscreamer.jsonassert by org.sonar.test.JsonAssert.
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 19 Mar 2015 13:46:58 +0000 (14:46 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 20 Mar 2015 10:07:24 +0000 (11:07 +0100)
This class supports lenient comparison of datetime values.

45 files changed:
pom.xml
server/sonar-server/pom.xml
server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ws/HistoryWsActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueWsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsJsonWriterTest.java
server/sonar-server/src/test/java/org/sonar/server/es/SearchOptionsTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueActionsWriterTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueTagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/L10nWsTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmWriterTest.java
server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
server/sonar-server/src/test/resources/org/sonar/server/issue/ws/ComponentTagsActionTest/component-tags.json
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/get_tags.json
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules.json
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_debt_rules_sticky.json
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_profile_active_rules_inheritance.json
sonar-batch-protocol/pom.xml
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectRepositoriesTest.java
sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/GlobalRepositoriesTest/expected.json [new file with mode: 0644]
sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/ProjectRepositoriesTest/testToJson.json [new file with mode: 0644]
sonar-batch/pom.xml
sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json
sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json
sonar-testing-harness/pom.xml
sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java [new file with mode: 0644]
sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java [new file with mode: 0644]
sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java [new file with mode: 0644]
sonar-testing-harness/src/test/java/org/sonar/test/JsonComparisonTest.java [new file with mode: 0644]
sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample1.json [new file with mode: 0644]
sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample2.json [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index aff4f463020b264ac395d3aab30d081624688fe8..47fd2355e8d309485247306629f25b087be8f785 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>jetty-server</artifactId>
         <version>${jetty.version}</version>
       </dependency>
-      <dependency>
-        <groupId>org.skyscreamer</groupId>
-        <artifactId>jsonassert</artifactId>
-        <version>1.2.3</version>
-      </dependency>
       <dependency>
         <groupId>org.hamcrest</groupId>
         <artifactId>hamcrest-all</artifactId>
index da5049e8286cdec38c96fe5f4b1578b8fdf523e2..bc6768f29a93632fb021a7a6f2305042e147c07a 100644 (file)
       <artifactId>elasticsearch-test</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.skyscreamer</groupId>
-      <artifactId>jsonassert</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>xmlunit</groupId>
       <artifactId>xmlunit</artifactId>
index 36f91833e9fec0f05fec2c8a3d80662effd250d4..8c8e4670c7102cec54b1d7b6d321b69616111f36 100644 (file)
@@ -88,7 +88,7 @@ public class SearchActionTest {
     MockUserSession.set().setLogin("john").addProjectUuidPermissions(UserRole.USER, "EFGH");
 
     WsTester.TestRequest request = tester.newGetRequest("api/components", "search").setParam("componentUuid", "EFGH").setParam("q", "st").setParam("p", "2").setParam("ps", "1");
-    request.execute().assertJson(getClass(), "return_paged_result.json", false);
+    request.execute().assertJson(getClass(), "return_paged_result.json");
   }
 
   @Test
@@ -97,7 +97,7 @@ public class SearchActionTest {
     MockUserSession.set().setLogin("john").addProjectUuidPermissions(UserRole.USER, "EFGH");
 
     WsTester.TestRequest request = tester.newGetRequest("api/components", "search").setParam("componentUuid", "EFGH").setParam("q", "st").setParam("p", "1").setParam("ps", "1");
-    request.execute().assertJson(getClass(), "return_only_first_page.json", false);
+    request.execute().assertJson(getClass(), "return_only_first_page.json");
   }
 
   @Test
index 26fe86462b339e55e0e67e02e227f8705761bf6f..d04c2c21cf711e5099d7f6ecb221d98580774685 100644 (file)
@@ -77,7 +77,7 @@ public class HistoryWsActionMediumTest {
     MockUserSession.set().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
 
     WsTester.TestRequest request = tester.wsTester().newGetRequest("api/computation", "history");
-    request.execute().assertJson(getClass(), "list_history_reports.json", false);
+    request.execute().assertJson(getClass(), "list_history_reports.json");
   }
 
   @Test(expected = ForbiddenException.class)
index 846f8d095b30b2ddb763f6a95b1df72c052a5737..ebf3bf043f4d7aafa6f471b559bcb2ccec91725d 100644 (file)
@@ -60,7 +60,7 @@ public class QueueWsActionTest {
     when(queue.all()).thenReturn(reports);
 
     WsTester.TestRequest request = tester.newGetRequest(ComputationWebService.API_ENDPOINT, "queue");
-    request.execute().assertJson(getClass(), "list_queue_reports.json", false);
+    request.execute().assertJson(getClass(), "list_queue_reports.json");
   }
 
   @Test
index 73df3a7c82735b74366e5b3a3f062ac5c257eb27..18fd62b7fec4b5438b229f4b36d60c4a1ce798f4 100644 (file)
 
 package org.sonar.server.duplication.ws;
 
-import org.json.JSONException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.core.component.ComponentDto;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.server.component.ComponentTesting;
 import org.sonar.server.component.db.ComponentDao;
+import org.sonar.test.JsonAssert;
 
 import java.io.StringWriter;
 import java.util.Collections;
@@ -40,9 +39,7 @@ import java.util.List;
 import static com.google.common.collect.Lists.newArrayList;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 @RunWith(MockitoJUnitRunner.class)
 public class DuplicationsJsonWriterTest {
@@ -77,14 +74,15 @@ public class DuplicationsJsonWriterTest {
 
     when(componentDao.getNullableByKey(session, key1)).thenReturn(file1);
     when(componentDao.getNullableByKey(session, key2)).thenReturn(file2);
-    when(componentDao.getNullableById(5L, session)).thenReturn(new ComponentDto().setId(5L).setKey("org.codehaus.sonar:sonar-ws-client").setLongName("SonarQube :: Web Service Client"));
+    when(componentDao.getNullableById(5L, session)).thenReturn(
+      new ComponentDto().setId(5L).setKey("org.codehaus.sonar:sonar-ws-client").setLongName("SonarQube :: Web Service Client"));
     when(componentDao.getNullableByUuid(session, project.uuid())).thenReturn(project);
 
     List<DuplicationsParser.Block> blocks = newArrayList();
     blocks.add(new DuplicationsParser.Block(newArrayList(
       new DuplicationsParser.Duplication(file1, 57, 12),
       new DuplicationsParser.Duplication(file2, 73, 12)
-    )));
+      )));
 
     test(blocks,
       "{\n" +
@@ -118,8 +116,7 @@ public class DuplicationsJsonWriterTest {
         "      \"subProjectName\": \"SonarQube :: Web Service Client\"\n" +
         "    }\n" +
         "  }" +
-        "}"
-    );
+        "}");
 
     verify(componentDao, times(2)).getNullableByKey(eq(session), anyString());
     // Verify call to dao is cached when searching for project / sub project
@@ -142,7 +139,7 @@ public class DuplicationsJsonWriterTest {
     blocks.add(new DuplicationsParser.Block(newArrayList(
       new DuplicationsParser.Duplication(file1, 57, 12),
       new DuplicationsParser.Duplication(file2, 73, 12)
-    )));
+      )));
 
     test(blocks,
       "{\n" +
@@ -172,8 +169,7 @@ public class DuplicationsJsonWriterTest {
         "      \"projectName\": \"SonarQube\"\n" +
         "    }\n" +
         "  }" +
-        "}"
-    );
+        "}");
   }
 
   @Test
@@ -190,7 +186,7 @@ public class DuplicationsJsonWriterTest {
       new DuplicationsParser.Duplication(file1, 57, 12),
       // Duplication on a removed file
       new DuplicationsParser.Duplication(null, 73, 12)
-    )));
+      )));
 
     test(blocks,
       "{\n" +
@@ -214,8 +210,7 @@ public class DuplicationsJsonWriterTest {
         "      \"projectName\": \"SonarQube\"\n" +
         "    }\n" +
         "  }" +
-        "}"
-    );
+        "}");
   }
 
   @Test
@@ -223,13 +218,13 @@ public class DuplicationsJsonWriterTest {
     test(Collections.<DuplicationsParser.Block>emptyList(), "{\"duplications\": [], \"files\": {}}");
   }
 
-  private void test(List<DuplicationsParser.Block> blocks, String expected) throws JSONException {
+  private void test(List<DuplicationsParser.Block> blocks, String expected) {
     StringWriter output = new StringWriter();
     JsonWriter jsonWriter = JsonWriter.of(output);
     jsonWriter.beginObject();
     writer.write(blocks, jsonWriter, session);
     jsonWriter.endObject();
-    JSONAssert.assertEquals(expected, output.toString(), false);
+    JsonAssert.assertJson(output.toString()).isSimilarTo(expected);
   }
 
 }
index 8eea2257555c65c7aff7bf9143726aeefc42915a..6c1db01f58233b1c4f8fe6ef85f98e70b6cb06d1 100644 (file)
@@ -20,9 +20,9 @@
 package org.sonar.server.es;
 
 import org.junit.Test;
-import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.server.search.QueryContext;
+import org.sonar.test.JsonAssert;
 
 import java.io.StringWriter;
 
@@ -129,7 +129,7 @@ public class SearchOptionsTest {
     options.writeJson(jsonWriter, 42L);
     jsonWriter.endObject().close();
 
-    JSONAssert.assertEquals("{\"total\": 42, \"p\": 3, \"ps\": 10}", json.toString(), true);
+    JsonAssert.assertJson(json.toString()).isSimilarTo("{\"total\": 42, \"p\": 3, \"ps\": 10}");
   }
 
   @Test
@@ -140,7 +140,7 @@ public class SearchOptionsTest {
     options.writeDeprecatedJson(jsonWriter, 42L);
     jsonWriter.endObject().close();
 
-    JSONAssert.assertEquals("{\"paging\": {\"pageIndex\": 3, \"pageSize\": 10, \"total\": 42, \"fTotal\": \"42\", \"pages\": 5}}", json.toString(), true);
+    JsonAssert.assertJson(json.toString()).isSimilarTo("{\"paging\": {\"pageIndex\": 3, \"pageSize\": 10, \"total\": 42, \"fTotal\": \"42\", \"pages\": 5}}");
   }
 
   @Test
@@ -151,6 +151,6 @@ public class SearchOptionsTest {
     options.writeDeprecatedJson(jsonWriter, 30L);
     jsonWriter.endObject().close();
 
-    JSONAssert.assertEquals("{\"paging\": {\"pageIndex\": 3, \"pageSize\": 10, \"total\": 30, \"fTotal\": \"30\", \"pages\": 3}}", json.toString(), true);
+    JsonAssert.assertJson(json.toString()).isSimilarTo("{\"paging\": {\"pageIndex\": 3, \"pageSize\": 10, \"total\": 30, \"fTotal\": \"30\", \"pages\": 3}}");
   }
 }
index 8ab060920163dd87794b357fa414beb5cadabd24..35bce3508179c3ea18c7882cc8583abe8385314a 100644 (file)
@@ -58,7 +58,7 @@ public class FavoritesActionTest {
     MockUserSession.set();
 
     tester.newGetRequest("api/issue_filters", "favorites").execute()
-      .assertJson("{'favoriteFilters': []}");
+      .assertJson("{\"favoriteFilters\": []}");
   }
 
   @Test
@@ -69,7 +69,7 @@ public class FavoritesActionTest {
     ));
 
     tester.newGetRequest("api/issue_filters", "favorites").execute()
-      .assertJson("{'favoriteFilters': [{'id': 13, 'name': 'Blocker issues', 'user': 'simon', 'shared': true}]}");
+      .assertJson("{\"favoriteFilters\": [{\"id\": 13, \"name\": \"Blocker issues\", \"user\": \"simon\", \"shared\": true}]}");
   }
 
 }
index d9e71d9180080ac161f429a14b0eced3e9b9931d..a468eeb70ad50dbd6c966aa80cd5cc11188d1e76 100644 (file)
@@ -20,9 +20,7 @@
 
 package org.sonar.server.issue.filter;
 
-import org.json.JSONException;
 import org.junit.Test;
-import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.core.issue.db.IssueFilterDto;
 import org.sonar.core.permission.GlobalPermissions;
@@ -31,6 +29,8 @@ import org.sonar.server.user.UserSession;
 
 import java.io.StringWriter;
 
+import static org.sonar.test.JsonAssert.assertJson;
+
 public class IssueFilterWriterTest {
 
   IssueFilterWriter writer = new IssueFilterWriter();
@@ -54,8 +54,7 @@ public class IssueFilterWriterTest {
         "        \"query\":\"severity=BLOCKER\",\n" +
         "        \"user\":\"simon\",\n" +
         "        \"canModify\":false\n" +
-        "    }}"
-    );
+        "    }}");
   }
 
   @Test
@@ -77,8 +76,7 @@ public class IssueFilterWriterTest {
         "        \"query\":\"severity=BLOCKER\",\n" +
         "        \"user\":\"simon\",\n" +
         "        \"canModify\":true\n" +
-        "    }}"
-    );
+        "    }}");
   }
 
   @Test
@@ -100,16 +98,15 @@ public class IssueFilterWriterTest {
         "        \"query\":\"severity=BLOCKER\",\n" +
         "        \"user\":\"julien\",\n" +
         "        \"canModify\":true\n" +
-        "    }}"
-    );
+        "    }}");
   }
 
-  private void test(UserSession userSession, IssueFilterDto filter, String expected) throws JSONException {
+  private void test(UserSession userSession, IssueFilterDto filter, String expected) {
     StringWriter output = new StringWriter();
     JsonWriter jsonWriter = JsonWriter.of(output);
     jsonWriter.beginObject();
     writer.write(userSession, filter, jsonWriter);
     jsonWriter.endObject();
-    JSONAssert.assertEquals(output.toString(), expected, true);
+    assertJson(output.toString()).isSimilarTo(expected);
   }
 }
index fe6472b390cc4a69b5158a9b920f4d61fed55f58..4dd53d9bf0f86b9571c46d1b2b4f3c30a3f9d212 100644 (file)
@@ -86,7 +86,7 @@ public class ComponentTagsActionTest {
 
   @Test
   public void should_return_empty_list() throws Exception {
-    tester.newGetRequest("api/issues", "component_tags").setParam("componentUuid", "polop").execute().assertJson("{tags:[]}");
+    tester.newGetRequest("api/issues", "component_tags").setParam("componentUuid", "polop").execute().assertJson("{\"tags\":[]}");
   }
 
   @Test
index 73f0d301ff365e498a3931308e1ae8c74f5e2e7b..d4f10786a6aaf3e26d59f21c6dab6b5426330ce1 100644 (file)
 
 package org.sonar.server.issue.ws;
 
-import org.json.JSONException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.action.Action;
 import org.sonar.api.issue.internal.DefaultIssue;
@@ -37,6 +35,7 @@ import org.sonar.core.issue.workflow.Transition;
 import org.sonar.server.issue.ActionService;
 import org.sonar.server.issue.IssueService;
 import org.sonar.server.user.MockUserSession;
+import org.sonar.test.JsonAssert;
 
 import java.io.StringWriter;
 
@@ -181,22 +180,22 @@ public class IssueActionsWriterTest {
       "{\"transitions\": []}");
   }
 
-  private void testActions(Issue issue, String expected) throws JSONException {
+  private void testActions(Issue issue, String expected) {
     StringWriter output = new StringWriter();
     JsonWriter jsonWriter = JsonWriter.of(output);
     jsonWriter.beginObject();
     writer.writeActions(issue, jsonWriter);
     jsonWriter.endObject();
-    JSONAssert.assertEquals(output.toString(), expected, true);
+    JsonAssert.assertJson(output.toString()).isSimilarTo(expected);
   }
 
-  private void testTransitions(Issue issue, String expected) throws JSONException {
+  private void testTransitions(Issue issue, String expected) {
     StringWriter output = new StringWriter();
     JsonWriter jsonWriter = JsonWriter.of(output);
     jsonWriter.beginObject();
     writer.writeTransitions(issue, jsonWriter);
     jsonWriter.endObject();
-    JSONAssert.assertEquals(output.toString(), expected, true);
+    JsonAssert.assertJson(output.toString()).isSimilarTo(expected);
   }
 
 }
index 9519396292be2ee5d09e082d4fd4597cf95979b0..3bdf5a1c37b53f929452725fc65f2c6f211255eb 100644 (file)
@@ -73,14 +73,14 @@ public class IssueTagsActionTest {
 
   @Test
   public void should_return_empty_list() throws Exception {
-    tester.newGetRequest("api/issues", "tags").execute().assertJson("{tags:[]}");
+    tester.newGetRequest("api/issues", "tags").execute().assertJson("{\"tags\":[]}");
   }
 
   @Test
   public void should_return_tag_list() throws Exception {
     when(service.listTags("polop", 5)).thenReturn(Lists.newArrayList("tag1", "tag2", "tag3", "tag4", "tag5"));
     tester.newGetRequest("api/issues", "tags").setParam("q", "polop").setParam("ps", "5").execute()
-      .assertJson("{tags:[\"tag1\", \"tag2\", \"tag3\", \"tag4\", \"tag5\"]}");
+      .assertJson("{\"tags\":[\"tag1\", \"tag2\", \"tag3\", \"tag4\", \"tag5\"]}");
     verify(service).listTags("polop", 5);
   }
 }
index b8d6c393b92729fd36151ca790779ee048d56b78..6d6759b1575376e1a9586c302ca97efd027d33a1 100644 (file)
@@ -105,7 +105,7 @@ public class SearchActionComponentsMediumTest {
     tester.get(IssueIndexer.class).indexAll();
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
-    result.assertJson(this.getClass(), "issues_on_different_projects.json", false);
+    result.assertJson(this.getClass(), "issues_on_different_projects.json");
   }
 
   @Test
@@ -121,22 +121,22 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.PROJECT_UUIDS, project.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_project_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_project_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.PROJECT_UUIDS, "unknown")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, project.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_project_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_project_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, "unknown")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
   }
 
   @Test
@@ -162,7 +162,7 @@ public class SearchActionComponentsMediumTest {
       .setParam(IssueFilterParameters.PROJECT_UUIDS, project1.uuid())
       .setParam(WebService.Param.FACETS, "projectUuids")
       .execute()
-      .assertJson(this.getClass(), "display_sticky_project_facet.json", false);
+      .assertJson(this.getClass(), "display_sticky_project_facet.json");
   }
 
   @Test
@@ -178,22 +178,22 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.FILE_UUIDS, file.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_file_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_file_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.FILE_UUIDS, "unknown")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, file.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_file_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_file_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, "unknown")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
   }
 
   @Test
@@ -212,12 +212,12 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENTS, file.key())
       .execute()
-      .assertJson(this.getClass(), "search_by_file_key.json", false);
+      .assertJson(this.getClass(), "search_by_file_key.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENTS, unitTest.key())
       .execute()
-      .assertJson(this.getClass(), "search_by_test_key.json", false);
+      .assertJson(this.getClass(), "search_by_test_key.json");
 
   }
 
@@ -240,7 +240,7 @@ public class SearchActionComponentsMediumTest {
       .setParam(IssueFilterParameters.FILE_UUIDS, file1.uuid() + "," + file3.uuid())
       .setParam(WebService.Param.FACETS, "fileUuids")
       .execute()
-      .assertJson(this.getClass(), "display_file_facet.json", false);
+      .assertJson(this.getClass(), "display_file_facet.json");
   }
 
   @Test
@@ -257,22 +257,22 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, directory.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_file_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_file_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, "unknown")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.DIRECTORIES, "src/main/java/dir")
       .execute()
-      .assertJson(this.getClass(), "search_by_file_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_file_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.DIRECTORIES, "src/main/java")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
   }
 
   @Test
@@ -295,34 +295,34 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, directory1.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_directory_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_directory_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, directory2.uuid())
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.MODULE_UUIDS, module1.uuid())
       .setParam(IssueFilterParameters.DIRECTORIES, "src/main/java/dir")
       .execute()
-      .assertJson(this.getClass(), "search_by_directory_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_directory_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.MODULE_UUIDS, module2.uuid())
       .setParam(IssueFilterParameters.DIRECTORIES, "src/main/java/dir")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.DIRECTORIES, "src/main/java/dir")
       .execute()
-      .assertJson(this.getClass(), "search_by_directory_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_directory_uuid.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.DIRECTORIES, "src/main/java")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
   }
 
   @Test
@@ -347,7 +347,7 @@ public class SearchActionComponentsMediumTest {
       .setParam(IssueFilterParameters.MODULE_UUIDS, subModule1.uuid() + "," + subModule3.uuid())
       .setParam(WebService.Param.FACETS, "moduleUuids")
       .execute()
-      .assertJson(this.getClass(), "display_module_facet.json", false);
+      .assertJson(this.getClass(), "display_module_facet.json");
   }
 
   @Test
@@ -366,7 +366,7 @@ public class SearchActionComponentsMediumTest {
       .setParam("resolved", "false")
       .setParam(WebService.Param.FACETS, "directories")
       .execute();
-    result.assertJson(this.getClass(), "display_directory_facet.json", false);
+    result.assertJson(this.getClass(), "display_directory_facet.json");
   }
 
   @Test
@@ -385,7 +385,7 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, view.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_view_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_view_uuid.json");
   }
 
   @Test
@@ -405,7 +405,7 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, view.uuid())
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
   }
 
   @Test
@@ -426,7 +426,7 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, subView.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_view_uuid.json", false);
+      .assertJson(this.getClass(), "search_by_view_uuid.json");
   }
 
   @Test
@@ -448,7 +448,7 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, subView.uuid())
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
   }
 
   public void search_by_author() throws Exception {
@@ -467,12 +467,12 @@ public class SearchActionComponentsMediumTest {
       .setParam(IssueFilterParameters.AUTHORS, "leia")
       .setParam(WebService.Param.FACETS, "authors")
       .execute()
-      .assertJson(this.getClass(), "search_by_authors.json", false);
+      .assertJson(this.getClass(), "search_by_authors.json");
 
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.AUTHORS, "unknown")
       .execute()
-      .assertJson(this.getClass(), "no_issue.json", false);
+      .assertJson(this.getClass(), "no_issue.json");
 
   }
 
@@ -496,7 +496,7 @@ public class SearchActionComponentsMediumTest {
     wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam(IssueFilterParameters.COMPONENT_UUIDS, developer.uuid())
       .execute()
-      .assertJson(this.getClass(), "search_by_developer.json", false);
+      .assertJson(this.getClass(), "search_by_developer.json");
   }
 
   @Test
@@ -530,7 +530,7 @@ public class SearchActionComponentsMediumTest {
       .execute();
     System.out.println(result.outputAsString());
     result
-      .assertJson(this.getClass(), "search_by_developer.json", false);
+      .assertJson(this.getClass(), "search_by_developer.json");
   }
 
   private RuleDto newRule() {
index 1132c428782ddf29fa7ed1fa2ad8bb079effc680..174005a2ccff006bafeb3a9645a66ce9af9f6917 100644 (file)
@@ -97,7 +97,7 @@ public class SearchActionMediumTest {
     WsTester.Result result = request.execute();
 
     assertThat(result).isNotNull();
-    result.assertJson(this.getClass(), "empty_result.json", false);
+    result.assertJson(this.getClass(), "empty_result.json");
   }
 
   @Test
@@ -125,7 +125,7 @@ public class SearchActionMediumTest {
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
     // TODO date assertion is complex to test, and components id are not predictable, that's why strict boolean is set to false
-    result.assertJson(this.getClass(), "issue.json", false);
+    result.assertJson(this.getClass(), "issue.json");
   }
 
   @Test
@@ -159,7 +159,7 @@ public class SearchActionMediumTest {
 
     MockUserSession.set().setLogin("john");
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
-    result.assertJson(this.getClass(), "issue_with_comment.json", false);
+    result.assertJson(this.getClass(), "issue_with_comment.json");
   }
 
   @Test
@@ -193,7 +193,7 @@ public class SearchActionMediumTest {
 
     MockUserSession.set().setLogin("john");
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).setParam(IssueFilterParameters.HIDE_COMMENTS, "true").execute();
-    result.assertJson(this.getClass(), "issue_with_comment_hidden.json", false);
+    result.assertJson(this.getClass(), "issue_with_comment_hidden.json");
     assertThat(result.outputAsString()).doesNotContain("fabrice");
   }
 
@@ -221,7 +221,7 @@ public class SearchActionMediumTest {
     tester.get(IssueIndexer.class).indexAll();
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
-    result.assertJson(this.getClass(), "issue_with_action_plan.json", false);
+    result.assertJson(this.getClass(), "issue_with_action_plan.json");
   }
 
   @Test
@@ -237,7 +237,7 @@ public class SearchActionMediumTest {
     tester.get(IssueIndexer.class).indexAll();
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
-    result.assertJson(this.getClass(), "issue_with_attributes.json", false);
+    result.assertJson(this.getClass(), "issue_with_attributes.json");
   }
 
   @Test
@@ -268,7 +268,7 @@ public class SearchActionMediumTest {
     MockUserSession.set().setLogin("john");
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam("extra_fields", "actions,transitions,assigneeName,reporterName,actionPlanName").execute();
-    result.assertJson(this.getClass(), "issue_with_extra_fields.json", false);
+    result.assertJson(this.getClass(), "issue_with_extra_fields.json");
   }
 
   @Test
@@ -292,7 +292,7 @@ public class SearchActionMediumTest {
     tester.get(IssueIndexer.class).indexAll();
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
-    result.assertJson(this.getClass(), "issue_linked_on_removed_file.json", false);
+    result.assertJson(this.getClass(), "issue_linked_on_removed_file.json");
   }
 
   @Test
@@ -326,7 +326,7 @@ public class SearchActionMediumTest {
       .setParam(IssueFilterParameters.COMPONENTS, file.getKey())
       .setParam(IssueFilterParameters.IGNORE_PAGING, "true")
       .execute();
-    result.assertJson(this.getClass(), "ignore_paging_with_one_component.json", false);
+    result.assertJson(this.getClass(), "ignore_paging_with_one_component.json");
   }
 
   @Test
@@ -348,7 +348,7 @@ public class SearchActionMediumTest {
       .setParam(IssueFilterParameters.COMPONENTS, file.getKey() + "," + otherFile.getKey())
       .setParam(IssueFilterParameters.IGNORE_PAGING, "true")
       .execute();
-    result.assertJson(this.getClass(), "apply_paging_with_multiple_components.json", false);
+    result.assertJson(this.getClass(), "apply_paging_with_multiple_components.json");
   }
 
   @Test
@@ -365,7 +365,7 @@ public class SearchActionMediumTest {
     tester.get(IssueIndexer.class).indexAll();
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).setParam(IssueFilterParameters.COMPONENTS, file.getKey()).execute();
-    result.assertJson(this.getClass(), "apply_paging_with_one_component.json", false);
+    result.assertJson(this.getClass(), "apply_paging_with_one_component.json");
   }
 
   @Test
@@ -380,7 +380,7 @@ public class SearchActionMediumTest {
     tester.get(IssueIndexer.class).indexAll();
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
-    result.assertJson(this.getClass(), "components_contains_sub_projects.json", false);
+    result.assertJson(this.getClass(), "components_contains_sub_projects.json");
   }
 
   @Test
@@ -404,7 +404,7 @@ public class SearchActionMediumTest {
       .setParam("resolved", "false")
       .setParam(WebService.Param.FACETS, "statuses,severities,resolutions,projectUuids,rules,fileUuids,assignees,languages,actionPlans")
       .execute();
-    result.assertJson(this.getClass(), "display_facets.json", false);
+    result.assertJson(this.getClass(), "display_facets.json");
   }
 
   @Test
@@ -430,7 +430,7 @@ public class SearchActionMediumTest {
       .setParam("languages", "xoo,polop,palap")
       .setParam(WebService.Param.FACETS, "statuses,severities,resolutions,projectUuids,rules,fileUuids,assignees,assigned_to_me,languages,actionPlans")
       .execute();
-    result.assertJson(this.getClass(), "display_zero_facets.json", false);
+    result.assertJson(this.getClass(), "display_zero_facets.json");
   }
 
   @Test
@@ -472,7 +472,7 @@ public class SearchActionMediumTest {
       .setParam("assignees", "__me__")
       .setParam(WebService.Param.FACETS, "assignees,assigned_to_me")
       .execute()
-      .assertJson(this.getClass(), "filter_by_assigned_to_me.json", false);
+      .assertJson(this.getClass(), "filter_by_assigned_to_me.json");
   }
 
   @Test
@@ -502,7 +502,7 @@ public class SearchActionMediumTest {
       .setParam("resolved", "false")
       .setParam("assignees", "__me__")
       .execute()
-      .assertJson(this.getClass(), "empty_result.json", false);
+      .assertJson(this.getClass(), "empty_result.json");
   }
 
   @Test
@@ -544,7 +544,7 @@ public class SearchActionMediumTest {
       .setParam("assignees", "alice")
       .setParam(WebService.Param.FACETS, "assignees,assigned_to_me")
       .execute()
-      .assertJson(this.getClass(), "assigned_to_me_facet_sticky.json", false);
+      .assertJson(this.getClass(), "assigned_to_me_facet_sticky.json");
   }
 
   @Test
@@ -564,7 +564,7 @@ public class SearchActionMediumTest {
     tester.get(IssueIndexer.class).indexAll();
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).setParam(IssueFilterParameters.HIDE_RULES, "true").execute();
-    result.assertJson(this.getClass(), "hide_rules.json", false);
+    result.assertJson(this.getClass(), "hide_rules.json");
   }
 
   @Test
@@ -583,7 +583,7 @@ public class SearchActionMediumTest {
       .setParam("sort", IssueQuery.SORT_BY_UPDATE_DATE)
       .setParam("asc", "false")
       .execute();
-    result.assertJson(this.getClass(), "sort_by_updated_at.json", false);
+    result.assertJson(this.getClass(), "sort_by_updated_at.json");
   }
 
   @Test
@@ -604,7 +604,7 @@ public class SearchActionMediumTest {
     request.setParam(WebService.Param.PAGE_SIZE, "9");
 
     WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "paging.json", false);
+    result.assertJson(this.getClass(), "paging.json");
   }
 
   @Test
@@ -625,7 +625,7 @@ public class SearchActionMediumTest {
     request.setParam(WebService.Param.PAGE_SIZE, "-1");
 
     WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "paging_with_page_size_to_minus_one.json", false);
+    result.assertJson(this.getClass(), "paging_with_page_size_to_minus_one.json");
   }
 
   @Test
@@ -646,7 +646,7 @@ public class SearchActionMediumTest {
     request.setParam(IssueFilterParameters.PAGE_SIZE, "9");
 
     WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "deprecated_paging.json", false);
+    result.assertJson(this.getClass(), "deprecated_paging.json");
   }
 
   @Test
@@ -654,7 +654,7 @@ public class SearchActionMediumTest {
     WsTester.TestRequest request = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION);
 
     WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "default_page_size_is_100.json", false);
+    result.assertJson(this.getClass(), "default_page_size_is_100.json");
   }
 
   private RuleDto newRule() {
index 810f325b82724f60ffdc5535696076cc5f74e6c0..1c5dd04158f3402a178d0a08dbf684bb7a6ef905 100644 (file)
@@ -87,7 +87,7 @@ public class L10nWsTest {
     verify(i18n).message(locale, key2, key2);
     verify(i18n).message(locale, key3, key3);
 
-    result.assertJson("{key1:'key1',key2:'key2',key3:'key3'}");
+    result.assertJson("{\"key1\":\"key1\",\"key2\":\"key2\",\"key3\":\"key3\"}");
   }
 
   @Test
@@ -111,6 +111,6 @@ public class L10nWsTest {
     verify(i18n).message(override, key2, key2);
     verify(i18n).message(override, key3, key3);
 
-    result.assertJson("{key1:'key1',key2:'key2',key3:'key3'}");
+    result.assertJson("{\"key1\":\"key1\",\"key2\":\"key2\",\"key3\":\"key3\"}");
   }
 }
index d36da7bfd6039465c5afeb43e596e82b686e4814..6e531cac71c04561910a7fc848e0b4a90092ab13 100644 (file)
@@ -189,7 +189,7 @@ public class QGatesWsTest {
     String name = "New QG";
     when(qGates.create(name)).thenReturn(new QualityGateDto().setId(42L).setName(name));
     tester.newGetRequest("api/qualitygates", "create").setParam("name", name).execute()
-      .assertJson("{'id':42,'name':'New QG'}");
+      .assertJson("{\"id\":42,\"name\":\"New QG\"}");
   }
 
   @Test
@@ -197,7 +197,7 @@ public class QGatesWsTest {
     String name = "Copied QG";
     when(qGates.copy(24L, name)).thenReturn(new QualityGateDto().setId(42L).setName(name));
     tester.newGetRequest("api/qualitygates", "copy").setParam("id", "24").setParam("name", name).execute()
-      .assertJson("{'id':42,'name':'Copied QG'}");
+      .assertJson("{\"id\":42,\"name\":\"Copied QG\"}");
   }
 
   @Test(expected = IllegalArgumentException.class)
@@ -218,7 +218,7 @@ public class QGatesWsTest {
     String name = "New QG";
     when(qGates.rename(id, name)).thenReturn(new QualityGateDto().setId(id).setName(name));
     tester.newPostRequest("api/qualitygates", "rename").setParam("id", id.toString()).setParam("name", name).execute()
-      .assertJson("{'id':42,'name':'New QG'}");
+      .assertJson("{\"id\":42,\"name\":\"New QG\"}");
     ;
   }
 
@@ -263,7 +263,7 @@ public class QGatesWsTest {
       ));
     when(qGates.currentUserHasWritePermission()).thenReturn(false);
     tester.newGetRequest("api/qualitygates", "list").execute().assertJson(
-      "{'qualitygates':[{'id':42,'name':'Golden'},{'id':43,'name':'Star'},{'id':666,'name':'Ninth'}]}");
+      "{\"qualitygates\":[{\"id\":42,\"name\":\"Golden\"},{\"id\":43,\"name\":\"Star\"},{\"id\":666,\"name\":\"Ninth\"}]}");
   }
 
   @Test
@@ -276,7 +276,7 @@ public class QGatesWsTest {
       ));
     when(qGates.getDefault()).thenReturn(defaultQgate);
     tester.newGetRequest("api/qualitygates", "list").execute().assertJson(
-      "{'qualitygates':[{'id':42,'name':'Golden'},{'id':43,'name':'Star'},{'id':666,'name':'Ninth'}],'default':42}");
+      "{\"qualitygates\":[{\"id\":42,\"name\":\"Golden\"},{\"id\":43,\"name\":\"Star\"},{\"id\":666,\"name\":\"Ninth\"}],\"default\":42}");
   }
 
   @Test
@@ -284,7 +284,7 @@ public class QGatesWsTest {
     long gateId = 12345L;
     when(qGates.get(gateId)).thenReturn(new QualityGateDto().setId(gateId).setName("Golden"));
     tester.newGetRequest("api/qualitygates", "show").setParam("id", Long.toString(gateId)).execute().assertJson(
-      "{'id':12345,'name':'Golden'}");
+      "{\"id\":12345,\"name\":\"Golden\"}");
   }
 
   @Test
@@ -296,9 +296,9 @@ public class QGatesWsTest {
       new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3)
       ));
     tester.newGetRequest("api/qualitygates", "show").setParam("id", Long.toString(gateId)).execute().assertJson(
-      "{'id':12345,'name':'Golden','conditions':["
-        + "{'id':1,'metric':'ncloc','op':'GT','error':'10000'},"
-        + "{'id':2,'metric':'new_coverage','op':'LT','warning':'90','period':3}"
+      "{\"id\":12345,\"name\":\"Golden\",\"conditions\":["
+        + "{\"id\":1,\"metric\":\"ncloc\",\"op\":\"GT\",\"error\":\"10000\"},"
+        + "{\"id\":2,\"metric\":\"new_coverage\",\"op\":\"LT\",\"warning\":\"90\",\"period\":3}"
         + "]}"
       );
   }
@@ -313,9 +313,9 @@ public class QGatesWsTest {
       new QualityGateConditionDto().setId(2L).setMetricKey("new_coverage").setOperator("LT").setWarningThreshold("90").setPeriod(3)
       ));
     tester.newGetRequest("api/qualitygates", "show").setParam("name", gateName).execute().assertJson(
-      "{'id':12345,'name':'Golden','conditions':["
-        + "{'id':1,'metric':'ncloc','op':'GT','error':'10000'},"
-        + "{'id':2,'metric':'new_coverage','op':'LT','warning':'90','period':3}"
+      "{\"id\":12345,\"name\":\"Golden\",\"conditions\":["
+        + "{\"id\":1,\"metric\":\"ncloc\",\"op\":\"GT\",\"error\":\"10000\"},"
+        + "{\"id\":2,\"metric\":\"new_coverage\",\"op\":\"LT\",\"warning\":\"90\",\"period\":3}"
         + "]}"
       );
   }
@@ -347,7 +347,7 @@ public class QGatesWsTest {
       .setParam("warning", warningThreshold)
       .setParam("error", errorThreshold)
       .execute()
-      .assertJson("{'id':12345,'metric':'coverage','op':'LT','warning':'80','error':'75'}");
+      .assertJson("{\"id\":12345,\"metric\":\"coverage\",\"op\":\"LT\",\"warning\":\"80\",\"error\":\"75\"}");
   }
 
   @Test
@@ -367,7 +367,7 @@ public class QGatesWsTest {
       .setParam("warning", warningThreshold)
       .setParam("error", errorThreshold)
       .execute()
-      .assertJson("{'id':12345,'metric':'coverage','op':'LT','warning':'80','error':'75'}");
+      .assertJson("{\"id\":12345,\"metric\":\"coverage\",\"op\":\"LT\",\"warning\":\"80\",\"error\":\"75\"}");
   }
 
   @Test
@@ -395,9 +395,9 @@ public class QGatesWsTest {
       .setParam("gateId", Long.toString(gateId))
       .setParam("query", "Project")
       .execute()
-      .assertJson("{'more':true,'results':["
-        + "{'id':42,'name':'Project One','selected':false},"
-        + "{'id':24,'name':'Project Two','selected':true}"
+      .assertJson("{\"more\":true,\"results\":["
+        + "{\"id\":42,\"name\":\"Project One\",\"selected\":false},"
+        + "{\"id\":24,\"name\":\"Project Two\",\"selected\":true}"
         + "]}");
     ArgumentCaptor<ProjectQgateAssociationQuery> queryCaptor = ArgumentCaptor.forClass(ProjectQgateAssociationQuery.class);
     verify(projectFinder).find(queryCaptor.capture());
@@ -419,8 +419,8 @@ public class QGatesWsTest {
     tester.newGetRequest("api/qualitygates", "search")
       .setParam("gateId", Long.toString(gateId))
       .execute()
-      .assertJson("{'more':true,'results':["
-        + "{'id':24,'name':'Project Two','selected':true}"
+      .assertJson("{\"more\":true,\"results\":["
+        + "{\"id\":24,\"name\":\"Project Two\",\"selected\":true}"
         + "]}");
     ArgumentCaptor<ProjectQgateAssociationQuery> queryCaptor = ArgumentCaptor.forClass(ProjectQgateAssociationQuery.class);
     verify(projectFinder).find(queryCaptor.capture());
index 8ba84ec7e23f533915d71ea747eca9d2be17681b..3e432a78d2f4b2c7747073510877bdc1a94e0783 100644 (file)
@@ -87,7 +87,7 @@ public class CreateActionMediumTest {
       .setParam("severity", "MAJOR")
       .setParam("status", "BETA")
       .setParam("params", "regex=a.*");
-    request.execute().assertJson(getClass(), "create_custom_rule.json", false);
+    request.execute().assertJson(getClass(), "create_custom_rule.json");
   }
 
   @Test
@@ -101,7 +101,7 @@ public class CreateActionMediumTest {
       .setParam("name", "My manual rule")
       .setParam("markdown_description", "Description")
       .setParam("severity", "MAJOR");
-    request.execute().assertJson(getClass(), "create_manual_rule.json", false);
+    request.execute().assertJson(getClass(), "create_manual_rule.json");
   }
 
   @Test
@@ -114,7 +114,7 @@ public class CreateActionMediumTest {
       .setParam("manual_key", "MY_MANUAL")
       .setParam("name", "My manual rule")
       .setParam("markdown_description", "Description");
-    request.execute().assertJson(getClass(), "create_manual_rule_without_severity.json", false);
+    request.execute().assertJson(getClass(), "create_manual_rule_without_severity.json");
   }
 
   @Test
@@ -161,7 +161,7 @@ public class CreateActionMediumTest {
       .setParam("severity", "MAJOR")
       .setParam("prevent_reactivation", "true");
     request.execute()
-      .assertJson(getClass(), "create_rule_with_prevent_reactivation_param_to_true.json", false)
+      .assertJson(getClass(), "create_rule_with_prevent_reactivation_param_to_true.json")
       .assertStatus(409);
   }
 
index 4a97bf50e68de5a622896c4670bc3049ae3021f1..9a45b332a79b2cb127e2d82481b0009d2928ddd1 100644 (file)
@@ -126,13 +126,13 @@ public class RulesWebServiceMediumTest {
     request.setParam(ShowAction.PARAM_KEY, rule.getKey().toString());
     request.setParam(ShowAction.PARAM_ACTIVES, "true");
     WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "show_rule_active.json", false);
+    result.assertJson(this.getClass(), "show_rule_active.json");
 
     // 1. Default Activation (defaults to false)
     request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SHOW_METHOD);
     request.setParam(ShowAction.PARAM_KEY, rule.getKey().toString());
     result = request.execute();
-    result.assertJson(this.getClass(), "show_rule_no_active.json", false);
+    result.assertJson(this.getClass(), "show_rule_no_active.json");
   }
 
   @Test
@@ -156,13 +156,13 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchAction.PARAM_KEY, RuleTesting.XOO_X1.toString());
     request.setParam(SearchOptions.PARAM_FIELDS, "actives");
     WsTester.Result result = request.execute();
-    result.assertJson("{\"total\":1,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x1\"}]}", false);
+    result.assertJson("{\"total\":1,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x1\"}]}");
 
     request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(SearchAction.PARAM_KEY, RuleKey.of("xoo", "unknown").toString());
     request.setParam(SearchOptions.PARAM_FIELDS, "actives");
     result = request.execute();
-    result.assertJson("{\"total\":0,\"p\":1,\"ps\":100,\"rules\":[],\"actives\":{}}", false);
+    result.assertJson("{\"total\":0,\"p\":1,\"ps\":100,\"rules\":[],\"actives\":{}}");
 
   }
 
@@ -176,7 +176,7 @@ public class RulesWebServiceMediumTest {
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     WsTester.Result result = request.execute();
 
-    result.assertJson(getClass(), "search_2_rules.json", false);
+    result.assertJson(getClass(), "search_2_rules.json");
   }
 
   @Test
@@ -189,7 +189,7 @@ public class RulesWebServiceMediumTest {
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(SearchOptions.PARAM_FIELDS, "name,htmlDesc,mdDesc");
     WsTester.Result result = request.execute();
 
-    result.assertJson(getClass(), "search_2_rules_fields.json", false);
+    result.assertJson(getClass(), "search_2_rules_fields.json");
   }
 
   @Test
@@ -214,7 +214,7 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchOptions.PARAM_FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
     request.setParam(SearchAction.PARAM_FACETS, "debt_characteristics");
     WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "search_debt_rule.json", false);
+    result.assertJson(this.getClass(), "search_debt_rule.json");
   }
 
   @Test
@@ -345,7 +345,7 @@ public class RulesWebServiceMediumTest {
       .setParam("debt_characteristics", "SOFT_RELIABILITY")
       .setParam(SearchAction.PARAM_FACETS, "debt_characteristics")
       .execute();
-    result.assertJson(this.getClass(), "search_debt_rules_sticky.json", false);
+    result.assertJson(this.getClass(), "search_debt_rules_sticky.json");
   }
 
   @Test
@@ -397,7 +397,7 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchOptions.PARAM_FIELDS, "");
     WsTester.Result result = request.execute();
 
-    result.assertJson(this.getClass(), "search_active_rules.json", false);
+    result.assertJson(this.getClass(), "search_active_rules.json");
   }
 
   @Test
@@ -427,14 +427,14 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchAction.PARAM_QPROFILE, profile2.getKey());
     request.setParam(SearchOptions.PARAM_FIELDS, "actives");
     WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "search_profile_active_rules.json", false);
+    result.assertJson(this.getClass(), "search_profile_active_rules.json");
 
     tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD)
       .setParam(SearchAction.PARAM_ACTIVATION, "true")
       .setParam(SearchAction.PARAM_QPROFILE, "unknown_profile")
       .setParam(SearchOptions.PARAM_FIELDS, "actives")
       .execute()
-      .assertJson(this.getClass(), "search_no_rules.json", false);
+      .assertJson(this.getClass(), "search_no_rules.json");
   }
 
   @Test
@@ -464,7 +464,7 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchAction.PARAM_QPROFILE, profile2.getKey());
     request.setParam(SearchOptions.PARAM_FIELDS, "actives");
     WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "search_profile_active_rules_inheritance.json", false);
+    result.assertJson(this.getClass(), "search_profile_active_rules_inheritance.json");
   }
 
   @Test
@@ -508,7 +508,7 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchOptions.PARAM_FIELDS, "params");
     WsTester.Result result = request.execute();
 
-    result.assertJson(this.getClass(), "search_active_rules_params.json", false);
+    result.assertJson(this.getClass(), "search_active_rules_params.json");
   }
 
   @Test
@@ -528,11 +528,11 @@ public class RulesWebServiceMediumTest {
     session.commit();
 
     MockUserSession.set();
-    tester.wsTester().newGetRequest(API_ENDPOINT, API_TAGS_METHOD).execute().assertJson(this.getClass(), "get_tags.json", false);
+    tester.wsTester().newGetRequest(API_ENDPOINT, API_TAGS_METHOD).execute().assertJson(this.getClass(), "get_tags.json");
     tester.wsTester().newGetRequest(API_ENDPOINT, API_TAGS_METHOD)
-      .setParam("ps", "1").execute().assertJson(this.getClass(), "get_tags_limited.json", false);
+      .setParam("ps", "1").execute().assertJson(this.getClass(), "get_tags_limited.json");
     tester.wsTester().newGetRequest(API_ENDPOINT, API_TAGS_METHOD)
-      .setParam("q", "ll").execute().assertJson(this.getClass(), "get_tags_filtered.json", false);
+      .setParam("q", "ll").execute().assertJson(this.getClass(), "get_tags_filtered.json");
   }
 
   @Test
@@ -573,14 +573,14 @@ public class RulesWebServiceMediumTest {
   public void severities_facet_should_have_all_severities() throws Exception {
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(SearchAction.PARAM_FACETS, "severities");
-    request.execute().assertJson(this.getClass(), "severities_facet.json", false);
+    request.execute().assertJson(this.getClass(), "severities_facet.json");
   }
 
   @Test
   public void statuses_facet_should_have_all_statuses_except_removed() throws Exception {
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(SearchAction.PARAM_FACETS, "statuses");
-    request.execute().assertJson(this.getClass(), "statuses_facet.json", false);
+    request.execute().assertJson(this.getClass(), "statuses_facet.json");
   }
 
   @Test
@@ -593,7 +593,7 @@ public class RulesWebServiceMediumTest {
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
     request.setParam(SearchAction.PARAM_STATUSES, "DEPRECATED");
     request.setParam(SearchAction.PARAM_FACETS, "statuses");
-    request.execute().assertJson(this.getClass(), "statuses_facet_sticky.json", false);
+    request.execute().assertJson(this.getClass(), "statuses_facet_sticky.json");
   }
 
   @Test
@@ -611,7 +611,7 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchOptions.PARAM_ASCENDING, "true");
 
     WsTester.Result result = request.execute();
-    result.assertJson("{\"total\":3,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x2\"},{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x3\"}]}", false);
+    result.assertJson("{\"total\":3,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x2\"},{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x3\"}]}");
 
     // 2. Sort Name DESC
     request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
@@ -620,7 +620,7 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchOptions.PARAM_ASCENDING, "false");
 
     result = request.execute();
-    result.assertJson("{\"total\":3,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x3\"},{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x2\"}]}", false);
+    result.assertJson("{\"total\":3,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x3\"},{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x2\"}]}");
 
   }
 
@@ -640,7 +640,7 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchAction.PARAM_AVAILABLE_SINCE, DateUtils.formatDate(since));
     request.setParam(SearchOptions.PARAM_SORT, RuleNormalizer.RuleField.KEY.field());
     WsTester.Result result = request.execute();
-    result.assertJson("{\"total\":2,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x2\"}]}", false);
+    result.assertJson("{\"total\":2,\"p\":1,\"ps\":100,\"rules\":[{\"key\":\"xoo:x1\"},{\"key\":\"xoo:x2\"}]}");
 
     Calendar c = Calendar.getInstance();
     c.setTime(since);
index cc4819a9a582bfdda6fee57d36fb30eafdd97135..779487d4e4b7cd02f7298baf6de8b811f17be49d 100644 (file)
@@ -95,7 +95,7 @@ public class ShowActionMediumTest {
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
       .setParam("key", ruleDto.getKey().toString());
-    request.execute().assertJson(getClass(), "show_rule.json", false);
+    request.execute().assertJson(getClass(), "show_rule.json");
   }
 
   @Test
@@ -133,7 +133,7 @@ public class ShowActionMediumTest {
       .setParam("key", ruleDto.getKey().toString());
     WsTester.Result response = request.execute();
 
-    response.assertJson(getClass(), "show_rule_with_default_debt_infos.json", false);
+    response.assertJson(getClass(), "show_rule_with_default_debt_infos.json");
   }
 
   @Test
@@ -169,7 +169,7 @@ public class ShowActionMediumTest {
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
       .setParam("key", ruleDto.getKey().toString());
-    request.execute().assertJson(getClass(), "show_rule_with_overridden_debt_infos.json", false);
+    request.execute().assertJson(getClass(), "show_rule_with_overridden_debt_infos.json");
   }
 
   @Test
@@ -210,7 +210,7 @@ public class ShowActionMediumTest {
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
       .setParam("key", ruleDto.getKey().toString());
-    request.execute().assertJson(getClass(), "show_rule_with_default_and_overridden_debt_infos.json", false);
+    request.execute().assertJson(getClass(), "show_rule_with_default_and_overridden_debt_infos.json");
   }
 
   @Test
@@ -242,7 +242,7 @@ public class ShowActionMediumTest {
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
       .setParam("key", ruleDto.getKey().toString());
-    request.execute().assertJson(getClass(), "show_rule_with_no_default_and_no_overridden_debt.json", false);
+    request.execute().assertJson(getClass(), "show_rule_with_no_default_and_no_overridden_debt.json");
   }
 
   @Test
@@ -273,7 +273,7 @@ public class ShowActionMediumTest {
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
       .setParam("key", ruleDto.getKey().toString());
-    request.execute().assertJson(getClass(), "show_rule_with_overridden_disable_debt.json", false);
+    request.execute().assertJson(getClass(), "show_rule_with_overridden_disable_debt.json");
   }
 
   @Test
@@ -297,7 +297,7 @@ public class ShowActionMediumTest {
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
       .setParam("key", customRuleKey.toString());
-    request.execute().assertJson(getClass(), "encode_html_description_of_custom_rule.json", false);
+    request.execute().assertJson(getClass(), "encode_html_description_of_custom_rule.json");
   }
 
   @Test
@@ -316,7 +316,7 @@ public class ShowActionMediumTest {
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/rules", "show")
       .setParam("key", customRuleKey.toString());
-    request.execute().assertJson(getClass(), "encode_html_description_of_manual_rule.json", false);
+    request.execute().assertJson(getClass(), "encode_html_description_of_manual_rule.json");
   }
 
 }
index 68b64822c2e90b901b87878826352445a8e0236d..7ce82055083e5bd1bd82779e6d8e72807ae4a739 100644 (file)
@@ -98,7 +98,7 @@ public class UpdateActionMediumTest {
       .setParam("severity", "MAJOR")
       .setParam("status", "BETA")
       .setParam("params", "regex=a.*");
-    request.execute().assertJson(getClass(), "update_custom_rule.json", false);
+    request.execute().assertJson(getClass(), "update_custom_rule.json");
   }
 
   @Test
index d4bcee11a82b596e35847c464f36dca9587cd1bb..e69e22ee157f4a95a17e2538e6a2ed57ac37a708 100644 (file)
@@ -21,13 +21,13 @@ package org.sonar.server.search.ws;
 
 import com.google.common.collect.Lists;
 import org.junit.Test;
-import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonar.api.server.ws.RequestHandler;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.internal.SimpleGetRequest;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.server.search.QueryContext;
 import org.sonar.server.search.Result;
+import org.sonar.test.JsonAssert;
 
 import java.io.StringWriter;
 
@@ -101,7 +101,7 @@ public class SearchOptionsTest {
     options.writeStatistics(jsonWriter, result);
     jsonWriter.endObject().close();
 
-    JSONAssert.assertEquals("{\"total\": 42, \"p\": 3, \"ps\": 10}", json.toString(), true);
+    JsonAssert.assertJson(json.toString()).isSimilarTo("{\"total\": 42, \"p\": 3, \"ps\": 10}");
   }
 
   @Test
index acfc1527b63729a9739c4eae0230883282832c6b..bcd67c877c109c6e2665b8fa173a0fb886f074f3 100644 (file)
@@ -163,7 +163,7 @@ public class LinesActionTest {
 
     WsTester.TestRequest request = tester.newGetRequest("api/sources", "lines").setParam("uuid", componentUuid);
     // Using non-strict match b/c of dates
-    request.execute().assertJson(getClass(), "show_source.json", false);
+    request.execute().assertJson(getClass(), "show_source.json");
   }
 
   @Test
index bec891ff22c3c6aa8bdbbf30d2524ae5284e416b..cf05251cf345f73cb058df15361e6e7378246a2d 100644 (file)
  */
 package org.sonar.server.source.ws;
 
-import org.json.JSONException;
 import org.junit.Test;
-import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.test.JsonAssert;
 
 import java.io.StringWriter;
 
@@ -63,13 +62,12 @@ public class ScmWriterTest {
     test(authors, dates, 10, 20, false, "{\"scm\": []}");
   }
 
-
-  private void test(String authors, String dates, int from, int to, boolean group, String expected) throws JSONException {
+  private void test(String authors, String dates, int from, int to, boolean group, String expected) {
     StringWriter output = new StringWriter();
     JsonWriter jsonWriter = JsonWriter.of(output);
     jsonWriter.beginObject();
     writer.write(authors, dates, from, to, group, jsonWriter);
     jsonWriter.endObject();
-    JSONAssert.assertEquals(output.toString(), expected, true);
+    JsonAssert.assertJson(output.toString()).isSimilarTo(expected);
   }
 }
index b0e4e7264ddbee159f4517076f8dd754b56e7e5f..1be9064a18890b2c5639cb253e74bfb2c13c8fe3 100644 (file)
@@ -22,13 +22,13 @@ package org.sonar.server.ws;
 import com.google.common.collect.Maps;
 import org.apache.commons.io.Charsets;
 import org.apache.commons.io.IOUtils;
-import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.server.ws.internal.ValidatingRequest;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.api.utils.text.XmlWriter;
 import org.sonar.server.ws.WsTester.TestResponse.TestStream;
+import org.sonar.test.JsonAssert;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
@@ -185,12 +185,8 @@ public class WsTester {
     }
 
     public Result assertJson(String expectedJson) throws Exception {
-      return assertJson(expectedJson, true);
-    }
-
-    public Result assertJson(String expectedJson, boolean strict) throws Exception {
       String json = outputAsString();
-      JSONAssert.assertEquals(expectedJson, json, strict);
+      JsonAssert.assertJson(json).isSimilarTo(expectedJson);
       return this;
     }
 
@@ -203,17 +199,13 @@ public class WsTester {
      * @param expectedJsonFilename name of the file containing the expected JSON
      */
     public Result assertJson(Class clazz, String expectedJsonFilename) throws Exception {
-      return assertJson(clazz, expectedJsonFilename, true);
-    }
-
-    public Result assertJson(Class clazz, String expectedJsonFilename, boolean strict) throws Exception {
       String path = clazz.getSimpleName() + "/" + expectedJsonFilename;
       URL url = clazz.getResource(path);
       if (url == null) {
         throw new IllegalStateException("Cannot find " + path);
       }
       String json = outputAsString();
-      JSONAssert.assertEquals(IOUtils.toString(url), json, strict);
+      JsonAssert.assertJson(json).isSimilarTo(url);
       return this;
     }
 
index 38e018c645b8ba8bf45f5113bb251d0af601dda2..e3afc9a2dc4dea6ea321d04cd094c79957f5b4aa 100644 (file)
@@ -1,9 +1,9 @@
 {
-  tags: [
-    { key: "convention", value: 2771 },
-    { key: "brain-overload", value: 998 },
-    { key: "cwe", value: 89 },
-    { key: "bug", value: 32 },
-    { key: "cert", value: 2 }
+  "tags": [
+    { "key": "convention", "value": 2771 },
+    { "key": "brain-overload", "value": 998 },
+    { "key": "cwe", "value": 89 },
+    { "key": "bug", "value": 32 },
+    { "key": "cert", "value": 2 }
   ]
-}
\ No newline at end of file
+}
index 14764b48180a2f9e88dd5b14df3519d2e96eb82e..c9a14f30cd0477367c6527b0420ea02a25862775 100644 (file)
@@ -1 +1,8 @@
-{"tags": ["hello", "sys1", "java", "world"]}
\ No newline at end of file
+{
+  "tags": [
+    "sys1",
+    "java",
+    "world",
+    "hello"
+  ]
+}
index bd84f45871ebd6d2f63208fe52751bae4a7254cc..a3da4d33ff2e8f6e03a395e416f2146beed59905 100644 (file)
@@ -1,5 +1,7 @@
 {
-  "total": 2, "p": 1, "ps": 100,
+  "total": 2,
+  "p": 1,
+  "ps": 100,
   "rules": [
     {
       "key": "xoo:x2",
       "status": "READY",
       "internalKey": "InternalKeyx2",
       "isTemplate": false,
-      "tags": ["tag1", "tag2"],
-      "sysTags": ["systag1", "systag2"],
+      "tags": [
+        "tag1",
+        "tag2"
+      ],
+      "sysTags": [
+        "systag1",
+        "systag2"
+      ],
       "debtRemFnType": "LINEAR",
       "debtRemFnCoeff": "1h",
       "debtRemFnOffset": "5min",
       "status": "READY",
       "internalKey": "InternalKeyx1",
       "isTemplate": false,
-      "tags": ["tag1", "tag2"],
-      "sysTags": ["systag1", "systag2"],
+      "tags": [
+        "tag1",
+        "tag2"
+      ],
+      "sysTags": [
+        "systag1",
+        "systag2"
+      ],
       "debtRemFnType": "LINEAR",
       "debtRemFnCoeff": "1h",
       "debtRemFnOffset": "5min",
       "lang": "xoo",
       "params": []
     }
-  ]}
+  ]
+}
index a7cba30b88e457eaed38bb87552ef821ba632e6e..59441d3015d1a5a1b056fe51fe48b12566ef77fd 100644 (file)
@@ -1,41 +1,46 @@
-{"total": 1, "p": 1, "ps": 100, "rules": [
-  {
-    "key": "xoo:x2",
-    "debtChar": "RELIABILITY",
-    "debtCharName": "Reliability",
-    "debtSubChar": "SOFT_RELIABILITY",
-    "debtSubCharName": "Soft Reliability",
-    "debtRemFnType": "LINEAR_OFFSET",
-    "debtRemFnCoeff": "30min",
-    "debtRemFnOffset": "5min",
-    "debtOverloaded": true,
-    "defaultDebtChar": "RELIABILITY",
-    "defaultDebtSubChar": "HARD_RELIABILITY",
-    "defaultDebtRemFnType": "LINEAR_OFFSET",
-    "defaultDebtRemFnCoeff": "1h",
-    "defaultDebtRemFnOffset": "15min"
-  }
-],
-"facets": [
-  {
-    "property": "debt_characteristics",
-    "values": [
-      {
-        "val": "RELIABILITY",
-        "count": 2
-      },
-      {
-        "val": "SOFT_RELIABILITY",
-        "count": 1
-      },
-      {
-        "val": "HARD_RELIABILITY",
-        "count": 1
-      },
-      {
-        "val": "NONE",
-        "count": 2
-      }
-    ]
-  }
-]}
+{
+  "total": 1,
+  "p": 1,
+  "ps": 100,
+  "rules": [
+    {
+      "key": "xoo:x2",
+      "debtSubCharName": "Soft Reliability",
+      "defaultDebtRemFnType": "LINEAR_OFFSET",
+      "defaultDebtRemFnCoeff": "1h",
+      "defaultDebtRemFnOffset": "15min",
+      "debtChar": "RELIABILITY",
+      "debtOverloaded": true,
+      "debtCharName": "Reliability",
+      "debtRemFnType": "LINEAR_OFFSET",
+      "debtRemFnCoeff": "30min",
+      "debtRemFnOffset": "5min",
+      "debtSubChar": "SOFT_RELIABILITY",
+      "defaultDebtSubChar": "HARD_RELIABILITY",
+      "defaultDebtChar": "RELIABILITY"
+    }
+  ],
+  "facets": [
+    {
+      "property": "debt_characteristics",
+      "values": [
+        {
+          "val": "HARD_RELIABILITY",
+          "count": 1
+        },
+        {
+          "val": "SOFT_RELIABILITY",
+          "count": 1
+        },
+        {
+          "val": "RELIABILITY",
+          "count": 2
+        },
+        {
+          "val": "NONE",
+          "count": 2
+        }
+      ]
+    }
+  ]
+}
index 6dc19b488e3b753e48bb5edef43018eebb695473..28e8f7dfacd0a40e8f80fcd74345e4ce429f94b6 100644 (file)
       <artifactId>sonar-testing-harness</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.skyscreamer</groupId>
-      <artifactId>jsonassert</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <build>
index 2f4652d3ded1b872127e3670b9e263ee8b1468fb..fb7c5d46fb038cabca782374248cf1df6434a685 100644 (file)
@@ -19,9 +19,8 @@
  */
 package org.sonar.batch.protocol.input;
 
-import org.json.JSONException;
 import org.junit.Test;
-import org.skyscreamer.jsonassert.JSONAssert;
+import org.sonar.test.JsonAssert;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -34,16 +33,13 @@ public class GlobalRepositoriesTest {
     ref.addGlobalSetting("prop", "value");
     ref.setTimestamp(10);
 
-    JSONAssert
-      .assertEquals(
-        "{timestamp:10,"
-          + "metrics:[{id:1,key:ncloc,valueType:INT,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
-          + "globalSettings:{prop:value}}",
-        ref.toJson(), true);
+    JsonAssert
+      .assertJson(ref.toJson())
+      .isSimilarTo(getClass().getResource("GlobalRepositoriesTest/expected.json"));
   }
 
   @Test
-  public void from_json() throws JSONException {
+  public void from_json() {
     GlobalRepositories ref = GlobalRepositories
       .fromJson(
       "{timestamp:1,"
index cfb584f97e7f1b0f4024e13a4dcf0e4fe8a5fb70..b86b2938f15b5cd2cdf787359aeaad451c278f18 100644 (file)
@@ -19,9 +19,8 @@
  */
 package org.sonar.batch.protocol.input;
 
-import org.json.JSONException;
 import org.junit.Test;
-import org.skyscreamer.jsonassert.JSONAssert;
+import org.sonar.test.JsonAssert;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -31,44 +30,38 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class ProjectRepositoriesTest {
 
+  public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+
   @Test
   public void testToJson() throws Exception {
     ProjectRepositories ref = new ProjectRepositories();
     assertThat(ref.settings("foo")).isEmpty();
 
-    ref.addQProfile(new QProfile("squid-java", "Java", "java", new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984")));
-    HashMap<String, String> settings = new HashMap<String, String>();
+    ref.addQProfile(new QProfile("squid-java", "Java", "java", DATE_FORMAT.parse("2013-01-01T12:00:00+0100")));
+    HashMap<String, String> settings = new HashMap<>();
     settings.put("prop1", "value1");
     ref.addSettings("foo", settings);
-    settings = new HashMap<String, String>();
+    settings = new HashMap<>();
     settings.put("prop2", "value2");
     ref.addSettings("foo", settings);
     ref.settings("foo").put("prop", "value");
     ActiveRule activeRule = new ActiveRule("repo", "rule", "templateRule", "Rule", "MAJOR", "rule", "java");
     activeRule.addParam("param1", "value1");
     ref.addActiveRule(activeRule);
-    ref.setLastAnalysisDate(new SimpleDateFormat("dd/MM/yyyy").parse("31/10/2014"));
+    ref.setLastAnalysisDate(DATE_FORMAT.parse("2014-05-18T15:50:45+0100"));
     ref.setTimestamp(10);
     ref.addFileData("foo", "src/main/java/Foo.java", new FileData("xyz", true, "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
     ref.addFileData("foo", "src/main/java/Foo2.java", new FileData("xyz", false, "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
 
-    JSONAssert
-      .assertEquals(
-        "{timestamp:10,"
-          + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"1984-03-14T00:00:00+0100\"}},"
-          + "activeRules:[{repositoryKey:repo,ruleKey:rule,templateRuleKey:templateRule,name:Rule,severity:MAJOR,internalKey:rule,language:java,params:{param1:value1}}],"
-          + "settingsByModule:{foo:{prop1:value1,prop2:value2,prop:value}},"
-          + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,needBlame:true,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"},"
-          + "\"src/main/java/Foo2.java\":{hash:xyz,needBlame:false,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}},"
-          + "lastAnalysisDate:\"2014-10-31T00:00:00+0100\"}",
-        ref.toJson(), true);
+    JsonAssert.assertJson(ref.toJson())
+      .isSimilarTo(getClass().getResource("ProjectRepositoriesTest/testToJson.json"));
   }
 
   @Test
-  public void testFromJson() throws JSONException, ParseException {
+  public void testFromJson() throws ParseException {
     ProjectRepositories ref = ProjectRepositories
       .fromJson("{timestamp:1,"
-        + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"1984-03-14T00:00:00+0100\"}},"
+        + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"2013-01-01T12:00:00+0100\"}},"
         + "activeRules:[{repositoryKey:repo,ruleKey:rule,templateRuleKey:templateRule,name:Rule,severity:MAJOR,internalKey:rule1,language:java,params:{param1:value1}}],"
         + "settingsByModule:{foo:{prop:value}},"
         + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,needBlame:true,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}},"
@@ -89,7 +82,7 @@ public class ProjectRepositoriesTest {
     QProfile qProfile = ref.qProfiles().iterator().next();
     assertThat(qProfile.key()).isEqualTo("squid-java");
     assertThat(qProfile.name()).isEqualTo("Java");
-    assertThat(qProfile.rulesUpdatedAt()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984"));
+    assertThat(qProfile.rulesUpdatedAt().getTime()).isEqualTo(DATE_FORMAT.parse("2013-01-01T12:00:00+0100").getTime());
     assertThat(ref.settings("foo")).containsEntry("prop", "value");
 
     assertThat(ref.fileData("foo2", "src/main/java/Foo3.java")).isNull();
@@ -100,6 +93,6 @@ public class ProjectRepositoriesTest {
     assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmLastCommitDatetimesByLine()).isEqualTo("1=12345,2=3456");
     assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmRevisionsByLine()).isEqualTo("1=345,2=345");
 
-    assertThat(ref.lastAnalysisDate()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("31/10/2014"));
+    assertThat(ref.lastAnalysisDate().getTime()).isEqualTo(DATE_FORMAT.parse("2014-10-31T00:00:00+0100").getTime());
   }
 }
diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/GlobalRepositoriesTest/expected.json b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/GlobalRepositoriesTest/expected.json
new file mode 100644 (file)
index 0000000..de38ae0
--- /dev/null
@@ -0,0 +1,21 @@
+{
+  "timestamp": 10,
+  "metrics": [
+    {
+      "id": 1,
+      "key": "ncloc",
+      "valueType": "INT",
+      "description": "Description",
+      "direction": -1,
+      "name": "NCLOC",
+      "qualitative": true,
+      "userManaged": false,
+      "worstValue": 2.0,
+      "bestValue": 1.0,
+      "optimizedBestValue": true
+    }
+  ],
+  "globalSettings": {
+    "prop": "value"
+  }
+}
diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/ProjectRepositoriesTest/testToJson.json b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/ProjectRepositoriesTest/testToJson.json
new file mode 100644 (file)
index 0000000..7b5e29c
--- /dev/null
@@ -0,0 +1,49 @@
+{
+  "timestamp": 10,
+  "qprofilesByLanguage": {
+    "java": {
+      "key": "squid-java",
+      "name": "Java",
+      "language": "java",
+      "rulesUpdatedAt": "2013-01-01T12:00:00+0100"
+    }
+  },
+  "activeRules": [
+    {
+      "repositoryKey": "repo",
+      "ruleKey": "rule",
+      "templateRuleKey": "templateRule",
+      "name": "Rule",
+      "severity": "MAJOR",
+      "internalKey": "rule",
+      "language": "java",
+      "params": {"param1": "value1"}
+    }
+  ],
+  "settingsByModule": {
+    "foo": {
+      "prop1": "value1",
+      "prop2": "value2",
+      "prop": "value"
+    }
+  },
+  "fileDataByModuleAndPath": {
+    "foo": {
+      "src/main/java/Foo.java": {
+        "hash": "xyz",
+        "needBlame": true,
+        "scmLastCommitDatetimesByLine": "1\u003d12345,2\u003d3456",
+        "scmRevisionsByLine": "1\u003d345,2\u003d345",
+        "scmAuthorsByLine": "1\u003dhenryju,2\u003dgaudin"
+      },
+      "src/main/java/Foo2.java": {
+        "hash": "xyz",
+        "needBlame": false,
+        "scmLastCommitDatetimesByLine": "1\u003d12345,2\u003d3456",
+        "scmRevisionsByLine": "1\u003d345,2\u003d345",
+        "scmAuthorsByLine": "1\u003dhenryju,2\u003dgaudin"
+      }
+    }
+  },
+  "lastAnalysisDate": "2014-05-18T15:50:45+0100"
+}
index f199b70343af3b4105692e983a01a7eb4b0c9508..c2f0eaf47fdfa56c6b3676d5f5c32ffd0ef17dc3 100644 (file)
       <artifactId>javax.servlet-api</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.skyscreamer</groupId>
-      <artifactId>jsonassert</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.codehaus.sonar.plugins</groupId>
       <artifactId>sonar-xoo-plugin</artifactId>
index 1e61491a8c13f19bdcd480ef09cef98b0bc92a08..e1afdb05fcf9814b8d6c300d63aaadf1ba62b7b5 100644 (file)
@@ -21,12 +21,9 @@ package org.sonar.batch.scan.report;
 
 import com.google.common.collect.Lists;
 import com.google.common.io.Resources;
-import org.apache.commons.codec.Charsets;
-import org.json.JSONException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
-import org.skyscreamer.jsonassert.JSONAssert;
 import org.sonar.api.batch.fs.InputDir;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultFileSystem;
@@ -45,6 +42,7 @@ import org.sonar.batch.issue.IssueCache;
 import org.sonar.batch.repository.user.User;
 import org.sonar.batch.repository.user.UserRepository;
 import org.sonar.batch.scan.filesystem.InputPathCache;
+import org.sonar.test.JsonAssert;
 
 import java.io.File;
 import java.io.IOException;
@@ -119,13 +117,12 @@ public class JSONReportTest {
     when(jsonReport.getIssues()).thenReturn(Lists.newArrayList(issue));
     User user1 = new User("julien", "Julien");
     User user2 = new User("simon", "Simon");
-    when(userRepository.loadFromWs(anyListOf(String.class))).thenReturn(Lists.<User>newArrayList(user1, user2));
+    when(userRepository.loadFromWs(anyListOf(String.class))).thenReturn(Lists.newArrayList(user1, user2));
 
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
 
-    String expected = Resources.toString(Resources.getResource("org/sonar/batch/scan/report/JsonReportTest/report.json"), Charsets.UTF_8);
-    JSONAssert.assertEquals(expected, writer.toString(), false);
+    JsonAssert.assertJson(writer.toString()).isSimilarTo(Resources.getResource("org/sonar/batch/scan/report/JsonReportTest/report.json"));
   }
 
   @Test
@@ -146,19 +143,18 @@ public class JSONReportTest {
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
 
-    String expected = Resources.toString(Resources.getResource(
-      "org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json"), Charsets.UTF_8);
-    JSONAssert.assertEquals(expected, writer.toString(), false);
+    JsonAssert.assertJson(writer.toString()).isSimilarTo(Resources.getResource(
+      "org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json"));
   }
 
   @Test
-  public void should_ignore_components_without_issue() throws JSONException {
+  public void should_ignore_components_without_issue() {
     when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue>emptyList());
 
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
 
-    JSONAssert.assertEquals("{\"version\":\"3.6\"}", writer.toString(), false);
+    JsonAssert.assertJson(writer.toString()).isSimilarTo("{\"version\":\"3.6\"}");
   }
 
   @Test
index d699073ee838ea8d65144020e9fc2071582a51fd..b5af45efe6c0be9bf12d78183681ea27d2811ca3 100644 (file)
@@ -2,25 +2,27 @@
   "version": "3.6",
   "issues": [],
   "components": [
-  {
-    "key": "struts"
-  },
-  {
-    "key": "struts-core",
-    "path": "core"
-  },
-  {
-    "key": "struts-ui",
-    "path": "ui"
-  },
-  {
-    "key": "struts:src/main/java/org/apache/struts",
-    "path": "src/main/java/org/apache/struts"
-  },
-  {
-    "key": "struts:src/main/java/org/apache/struts/Action.java",
-    "path": "src/main/java/org/apache/struts/Action.java"
-  }
-],
-  "rules": []
+    {"key": "struts"},
+    {
+      "key": "struts-core",
+      "path": "core"
+    },
+    {
+      "key": "struts-ui",
+      "path": "ui"
+    },
+    {
+      "key": "struts:src/main/java/org/apache/struts/Action.java",
+      "path": "src/main/java/org/apache/struts/Action.java",
+      "moduleKey": "struts",
+      "status": "CHANGED"
+    },
+    {
+      "key": "struts:src/main/java/org/apache/struts",
+      "path": "src/main/java/org/apache/struts",
+      "moduleKey": "struts"
+    }
+  ],
+  "rules": [],
+  "users": []
 }
index 2e34d745924bb59856db4d74527b2d0d674a28c0..91c1e3a3eac4b84c4bc31dc7650f80ace94552d1 100644 (file)
@@ -1,53 +1,60 @@
-{"version": "3.6", "issues": [
-  {
-    "key": "200",
-    "component": "struts:src/main/java/org/apache/struts/Action.java",
-    "line": 1,
-    "message": "There are 2 cycles",
-    "severity": "MINOR",
-    "rule": "squid:AvoidCycles",
-    "status": "OPEN",
-    "isNew": false,
-    "assignee": "simon",
-    "effortToFix": 3.14,
-    "creationDate": "2013-04-24T00:00:00+0200"
-  }
-], "components": [
-  {
-    "key": "struts"
-  },
-  {
-    "key": "struts-core",
-    "path": "core"
-  },
-  {
-    "key": "struts-ui",
-    "path": "ui"
-  },
-  {
-    "key": "struts:src/main/java/org/apache/struts",
-    "path": "src/main/java/org/apache/struts",
-    "moduleKey": "struts",
-  },
-  {
-    "key": "struts:src/main/java/org/apache/struts/Action.java",
-    "path": "src/main/java/org/apache/struts/Action.java",
-    "moduleKey": "struts",
-    "status": "CHANGED"
-  }
-], "rules": [
-  {
-    "key": "squid:AvoidCycles",
-    "rule": "AvoidCycles",
-    "repository": "squid"
-  }
-], "users": [
-  {
-    "login": "julien",
-    "name": "Julien"
-  },
-  {
-    "login": "simon",
-    "name": "Simon"
-  }
-]}
+{
+  "version": "3.6",
+  "issues": [
+    {
+      "key": "200",
+      "component": "struts:src/main/java/org/apache/struts/Action.java",
+      "line": 1,
+      "message": "There are 2 cycles",
+      "severity": "MINOR",
+      "rule": "squid:AvoidCycles",
+      "status": "OPEN",
+      "isNew": false,
+      "assignee": "simon",
+      "effortToFix": 3.14,
+      "creationDate": "2013-04-24T00:00:00+0200"
+    }
+  ],
+  "components": [
+    {
+      "key": "struts"
+    },
+    {
+      "key": "struts-core",
+      "path": "core"
+    },
+    {
+      "key": "struts-ui",
+      "path": "ui"
+    },
+    {
+      "key": "struts:src/main/java/org/apache/struts/Action.java",
+      "path": "src/main/java/org/apache/struts/Action.java",
+      "moduleKey": "struts",
+      "status": "CHANGED"
+    },
+    {
+      "key": "struts:src/main/java/org/apache/struts",
+      "path": "src/main/java/org/apache/struts",
+      "moduleKey": "struts"
+    }
+  ],
+  "rules": [
+    {
+      "key": "squid:AvoidCycles",
+      "rule": "AvoidCycles",
+      "repository": "squid",
+      "name": "Avoid Cycles"
+    }
+  ],
+  "users": [
+    {
+      "login": "julien",
+      "name": "Julien"
+    },
+    {
+      "login": "simon",
+      "name": "Simon"
+    }
+  ]
+}
index a0af4198337f9146a1f81001022a262c3e1936ee..11126f3cbe439ef38fbce448665f241165e1753c 100644 (file)
       <artifactId>assertj-core</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.skyscreamer</groupId>
-      <artifactId>jsonassert</artifactId>
+      <groupId>com.googlecode.json-simple</groupId>
+      <artifactId>json-simple</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.code.gson</groupId>
+      <artifactId>gson</artifactId>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java b/sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java
new file mode 100644 (file)
index 0000000..ac9f247
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.test;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import org.apache.commons.io.Charsets;
+import org.apache.commons.io.IOUtils;
+import org.junit.ComparisonFailure;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * Assertion to compare JSON documents. Comparison is not strict:
+ * <ul>
+ *   <li>formatting differences are ignored</li>
+ *   <li>order of elements in objects <code>{}</code> is not verified</li>
+ *   <li>objects can contain more elements than expected, for example <code>{"one":1, "two":2}</code>
+ *   matches <code>{"one":1}</code></li>
+ *   <li>order of elements in arrays <code>[]</code> is not verified by default, for example <code>[1, 2]</code>
+ *   matches <code>[2, 1]</code>. This mode can be disabled with {@link #setStrictArrayOrder(boolean)}</li>
+ *   <li>timezones in datetime values are not strictly verified, for example <code>{"foo": "2015-01-01T13:00:00+2000"}</code>
+ *   matches <code>{"foo": "2015-01-01T10:00:00-1000"}</code>. This feature can be disabled with
+ *   {@link #setStrictTimezone(boolean)}
+ *   </li>
+ * </ul>
+ *
+ * @since 5.2
+ */
+public class JsonAssert {
+
+  private final String actualJson;
+  private final JsonComparison comparison = new JsonComparison();
+
+  private JsonAssert(String actualJson) {
+    this.actualJson = actualJson;
+  }
+
+  public JsonAssert setStrictTimezone(boolean b) {
+    comparison.setStrictTimezone(b);
+    return this;
+  }
+
+  public JsonAssert setStrictArrayOrder(boolean b) {
+    comparison.setStrictArrayOrder(b);
+    return this;
+  }
+
+  public JsonAssert isSimilarTo(String expected) {
+    boolean similar = comparison.areSimilar(expected, actualJson);
+    if (!similar) {
+      throw new ComparisonFailure("Not a super-set of expected JSON -", pretty(expected), pretty(actualJson));
+    }
+    return this;
+  }
+
+  public JsonAssert isSimilarTo(URL expected) {
+    return isSimilarTo(urlToString(expected));
+  }
+
+  public static JsonAssert assertJson(String actualJson) {
+    return new JsonAssert(actualJson);
+  }
+
+  public static JsonAssert assertJson(URL actualJson) {
+    return new JsonAssert(urlToString(actualJson));
+  }
+
+  private static String urlToString(URL url) {
+    try {
+      return IOUtils.toString(url, Charsets.UTF_8);
+    } catch (IOException e) {
+      throw new IllegalStateException("Fail to load JSON from " + url, e);
+    }
+  }
+
+  private static String pretty(String json) {
+    JsonElement gson = new JsonParser().parse(json);
+    return new GsonBuilder().setPrettyPrinting().serializeNulls().create().toJson(gson);
+  }
+}
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java b/sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java
new file mode 100644 (file)
index 0000000..1a437f5
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.test;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Not thread-safe because of field datetimeFormat which is SimpleDateFormat.
+ */
+class JsonComparison {
+
+  private static final SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+
+  private boolean strictTimezone = false;
+  private boolean strictArrayOrder = false;
+
+  boolean isStrictTimezone() {
+    return strictTimezone;
+  }
+
+  JsonComparison setStrictTimezone(boolean b) {
+    this.strictTimezone = b;
+    return this;
+  }
+
+  boolean isStrictArrayOrder() {
+    return strictArrayOrder;
+  }
+
+  JsonComparison setStrictArrayOrder(boolean b) {
+    this.strictArrayOrder = b;
+    return this;
+  }
+
+  boolean areSimilar(String expected, String actual) {
+    Object expectedJson = parse(expected);
+    Object actualJson = parse(actual);
+    return compare(expectedJson, actualJson);
+  }
+
+  private Object parse(String s) {
+    try {
+      JSONParser parser = new JSONParser();
+      return parser.parse(s);
+    } catch (Exception e) {
+      throw new IllegalStateException("Invalid JSON: " + s, e);
+    }
+  }
+
+  private boolean compare(@Nullable Object expectedObject, @Nullable Object actualObject) {
+    if (expectedObject == null) {
+      return actualObject == null;
+    }
+    if (actualObject == null) {
+      return false;
+    }
+    if (expectedObject.getClass() != actualObject.getClass()) {
+      return false;
+    }
+    if (expectedObject instanceof JSONArray) {
+      return compareArrays((JSONArray) expectedObject, (JSONArray) actualObject);
+    }
+    if (expectedObject instanceof JSONObject) {
+      return compareMaps((JSONObject) expectedObject, (JSONObject) actualObject);
+    }
+    if (expectedObject instanceof String) {
+      return compareStrings((String) expectedObject, (String) actualObject);
+    }
+    if (expectedObject instanceof Number) {
+      return compareNumbers((Number) expectedObject, (Number) actualObject);
+    }
+    return compareBooleans((Boolean) expectedObject, (Boolean) actualObject);
+  }
+
+  private boolean compareBooleans(Boolean expected, Boolean actual) {
+    return expected.equals(actual);
+  }
+
+  private boolean compareNumbers(Number expected, Number actual) {
+    double d1 = expected.doubleValue();
+    double d2 = actual.doubleValue();
+    if (Double.compare(d1, d2) == 0) {
+      return true;
+    }
+    return (Math.abs(d1 - d2) <= 0.0000001);
+  }
+
+  private boolean compareStrings(String expected, String actual) {
+    if (!strictTimezone) {
+      // two instants with different timezones are considered as identical (2015-01-01T13:00:00+0100 and 2015-01-01T12:00:00+0000)
+      Date expectedDate = tryParseDate(expected);
+      Date actualDate = tryParseDate(actual);
+      if (expectedDate != null && actualDate != null) {
+        return expectedDate.getTime() == actualDate.getTime();
+      }
+    }
+    return expected.equals(actual);
+  }
+
+  private boolean compareArrays(JSONArray expected, JSONArray actual) {
+    if (strictArrayOrder) {
+      return compareArraysByStrictOrder(expected, actual);
+    }
+    return compareArraysByLenientOrder(expected, actual);
+  }
+
+  private boolean compareArraysByStrictOrder(JSONArray expected, JSONArray actual) {
+    if (expected.size() != actual.size()) {
+      return false;
+    }
+
+    for (int index = 0; index < expected.size(); index++) {
+      Object expectedElt = expected.get(index);
+      Object actualElt = actual.get(index);
+      if (!compare(expectedElt, actualElt)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  private boolean compareArraysByLenientOrder(JSONArray expected, JSONArray actual) {
+    if (expected.size() > actual.size()) {
+      return false;
+    }
+
+    List remainingActual = new ArrayList(actual);
+    for (Object expectedElement : expected) {
+      // element can be null
+      boolean found = false;
+      for (Object actualElement : remainingActual) {
+        if (compare(expectedElement, actualElement)) {
+          found = true;
+          remainingActual.remove(actualElement);
+          break;
+        }
+      }
+      if (!found) {
+        return false;
+      }
+    }
+    if (!remainingActual.isEmpty()) {
+      return false;
+    }
+    return true;
+  }
+
+  private boolean compareMaps(JSONObject expectedMap, JSONObject actualMap) {
+    // each key-value of expected map must exist in actual map
+    for (Object expectedKey : expectedMap.keySet()) {
+      if (!actualMap.containsKey(expectedKey)) {
+        return false;
+      }
+      if (!compare(expectedMap.get(expectedKey), actualMap.get(expectedKey))) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @CheckForNull
+  Date tryParseDate(String s) {
+    try {
+      return datetimeFormat.parse(s);
+    } catch (ParseException ignored) {
+      // not a datetime
+      return null;
+    }
+  }
+}
diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java
new file mode 100644 (file)
index 0000000..59a05d6
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.test;
+
+import org.junit.ComparisonFailure;
+import org.junit.Test;
+
+import java.io.File;
+import java.net.URL;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.sonar.test.JsonAssert.assertJson;
+
+public class JsonAssertTest {
+
+  @Test
+  public void isSimilarAs_strings() throws Exception {
+    assertJson("{}").isSimilarTo("{}");
+
+    try {
+      assertJson("{}").isSimilarTo("[]");
+      fail();
+    } catch (ComparisonFailure error) {
+      assertThat(error.getMessage()).isEqualTo("Not a super-set of expected JSON - expected:<[[]]> but was:<[{}]>");
+      assertThat(error.getActual()).isEqualTo("{}");
+      assertThat(error.getExpected()).isEqualTo("[]");
+    }
+  }
+
+  @Test
+  public void isSimilarAs_urls() throws Exception {
+    URL url1 = getClass().getResource("JsonAssertTest/sample1.json");
+    URL url2 = getClass().getResource("JsonAssertTest/sample2.json");
+    assertJson(url1).isSimilarTo(url1);
+
+    try {
+      assertJson(url1).isSimilarTo(url2);
+      fail();
+    } catch (AssertionError error) {
+      // ok
+    }
+  }
+
+  @Test
+  public void actual_can_be_superset_of_expected() throws Exception {
+    assertJson("{\"foo\": \"bar\"}").isSimilarTo("{}");
+    try {
+      assertJson("{}").isSimilarTo("{\"foo\": \"bar\"}");
+      fail();
+    } catch (AssertionError error) {
+      // ok
+    }
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void fail_to_load_url() throws Exception {
+    assertJson(new File("target/missing").toURL());
+  }
+
+  @Test
+  public void enable_strict_order_of_arrays() throws Exception {
+    try {
+      assertJson("[1,2]").setStrictArrayOrder(true).isSimilarTo("[2, 1]");
+      fail();
+    } catch (AssertionError error) {
+      // ok
+    }
+  }
+
+  @Test
+  public void enable_strict_timezone() throws Exception {
+    try {
+      assertJson("[\"2010-05-18T15:50:45+0100\"]").setStrictTimezone(true).isSimilarTo("[\"2010-05-18T16:50:45+0200\"]");
+      fail();
+    } catch (AssertionError error) {
+      // ok
+    }
+  }
+}
diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/JsonComparisonTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/JsonComparisonTest.java
new file mode 100644 (file)
index 0000000..6dc5719
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.test;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JsonComparisonTest {
+
+  @Test(expected = IllegalStateException.class)
+  public void fail_if_invalid_json() {
+    areSimilar("{]", "");
+  }
+
+  @Test
+  public void syntax_agnostic() throws Exception {
+    assertThat(areSimilar("{}", " {  } ")).isTrue();
+    assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"foo\":  \"bar\" \n }")).isTrue();
+  }
+
+  @Test
+  public void object() throws Exception {
+    assertThat(areSimilar("{}", "{}")).isTrue();
+
+    // exactly the same
+    assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"foo\":\"bar\"}")).isTrue();
+
+    // same key but different value
+    assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"foo\":\"baz\"}")).isFalse();
+
+    // missing key
+    assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"xxx\":\"bar\"}")).isFalse();
+
+    // expected json can be a subset of actual json
+    assertThat(areSimilar("{\"foo\":\"bar\"}", "{\"xxx\":\"bar\", \"foo\": \"bar\"}")).isTrue();
+  }
+
+  @Test
+  public void strict_order_of_array() throws Exception {
+    assertThat(isSimilar_strict_array_order("[]", "[]")).isTrue();
+    assertThat(isSimilar_strict_array_order("[1, 2]", "[1, 2]")).isTrue();
+
+    assertThat(isSimilar_strict_array_order("[1, 2]", "[1]")).isFalse();
+    assertThat(isSimilar_strict_array_order("[1, 2]", "[2, 1]")).isFalse();
+    assertThat(isSimilar_strict_array_order("[1, 2]", "[1 , 2, 3]")).isFalse();
+    assertThat(isSimilar_strict_array_order("[1, 2]", "[1 , false]")).isFalse();
+    assertThat(isSimilar_strict_array_order("[1, 2]", "[1 , 3.14]")).isFalse();
+  }
+
+  @Test
+  public void lenient_order_of_array() throws Exception {
+    assertThat(areSimilar("[]", "[]")).isTrue();
+    assertThat(areSimilar("[1, 2]", "[1, 2]")).isTrue();
+    assertThat(areSimilar("[1, 2]", "[1]")).isFalse();
+    assertThat(areSimilar("[1, 2]", "[2, 1]")).isTrue();
+    assertThat(areSimilar("[1, 2]", "[1 , 2, 3]")).isFalse();
+    assertThat(areSimilar("[1, 2]", "[1 , false]")).isFalse();
+    assertThat(areSimilar("[1, 2]", "[1 , 3.14]")).isFalse();
+  }
+
+  @Test
+  public void lenient_order_of_arrays_by_default() throws Exception {
+    assertThat(new JsonComparison().isStrictArrayOrder()).isFalse();
+  }
+
+  @Test
+  public void null_value() throws Exception {
+    assertThat(areSimilar("[null]", "[null]")).isTrue();
+    assertThat(areSimilar("[null]", "[]")).isFalse();
+
+    assertThat(areSimilar("{\"foo\": null}", "{\"foo\": null}")).isTrue();
+    assertThat(areSimilar("{\"foo\": null}", "{\"foo\": \"bar\"}")).isFalse();
+    assertThat(areSimilar("{\"foo\": 3}", "{\"foo\": null}")).isFalse();
+    assertThat(areSimilar("{\"foo\": 3.14}", "{\"foo\": null}")).isFalse();
+    assertThat(areSimilar("{\"foo\": false}", "{\"foo\": null}")).isFalse();
+    assertThat(areSimilar("{\"foo\": true}", "{\"foo\": null}")).isFalse();
+    assertThat(areSimilar("{\"foo\": null}", "{\"foo\": 3}")).isFalse();
+    assertThat(areSimilar("{\"foo\": null}", "{\"foo\": 3.14}")).isFalse();
+    assertThat(areSimilar("{\"foo\": null}", "{\"foo\": false}")).isFalse();
+    assertThat(areSimilar("{\"foo\": null}", "{\"foo\": true}")).isFalse();
+  }
+
+  @Test
+  public void maps_and_arrays() throws Exception {
+    assertThat(areSimilar("[]", "{}")).isFalse();
+    assertThat(areSimilar("{}", "[]")).isFalse();
+
+    // map of array
+    assertThat(areSimilar("{\"foo\": []}", "{\"foo\": []}")).isTrue();
+    assertThat(areSimilar("{\"foo\": [1, 3]}", "{\"foo\": [1, 3], \"bar\": [1, 3]}")).isTrue();
+    assertThat(areSimilar("{\"foo\": []}", "{\"foo\": []}")).isTrue();
+    assertThat(areSimilar("{\"foo\": [1, 2]}", "{\"foo\": [1, 3]}")).isFalse();
+
+    // array of maps
+    assertThat(areSimilar("[{}]", "[{}]")).isTrue();
+    assertThat(areSimilar("[{}]", "[{\"foo\": 1}]")).isTrue();
+    // exactly the sames
+    assertThat(areSimilar("[{\"1\": \"3\"}, {\"2\":\"4\"}]", "[{\"1\": \"3\"}, {\"2\":\"4\"}]")).isTrue();
+    // different value
+    assertThat(areSimilar("[{\"1\": \"3\"}, {\"2\":\"4\"}]", "[{\"1\": \"3\"}, {\"2\":\"3\"}]")).isFalse();
+    // missing key
+    assertThat(areSimilar("[{\"1\": \"3\"}, {\"2\":\"4\"}]", "[{\"1\": \"3\"}, {\"5\":\"10\"}]")).isFalse();
+  }
+
+  @Test
+  public void lenient_timezone() throws Exception {
+    // lenient mode by default
+    assertThat(new JsonComparison().isStrictTimezone()).isFalse();
+
+    // same instant, same timezone
+    assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:50:45+0100\"}")).isTrue();
+
+    // same instant, but different timezone
+    assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T18:50:45+0400\"}")).isTrue();
+
+    // different time
+    assertThat(areSimilar("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:51:45+0100\"}")).isFalse();
+  }
+
+  @Test
+  public void strict_timezone() throws Exception {
+    assertThat(new JsonComparison().setStrictTimezone(true).isStrictTimezone()).isTrue();
+
+    // same instant, same timezone
+    assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:50:45+0100\"}")).isTrue();
+    assertThat(isSimilar_strict_timezone("[\"2010-05-18T15:50:45+0100\"]", "[\"2010-05-18T15:50:45+0100\"]")).isTrue();
+
+    // same instant, but different timezone
+    assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T18:50:45+0400\"}")).isFalse();
+
+    // different time
+    assertThat(isSimilar_strict_timezone("{\"foo\": \"2010-05-18T15:50:45+0100\"}", "{\"foo\": \"2010-05-18T15:51:45+0100\"}")).isFalse();
+  }
+
+  @Test
+  public void compare_doubles() throws Exception {
+    assertThat(areSimilar("{\"foo\": true}", "{\"foo\": false}")).isFalse();
+    assertThat(areSimilar("{\"foo\": true}", "{\"foo\": true}")).isTrue();
+    assertThat(areSimilar("{\"foo\": true}", "{\"foo\": \"true\"}")).isFalse();
+    assertThat(areSimilar("{\"foo\": true}", "{\"foo\": 1}")).isFalse();
+  }
+
+  @Test
+  public void compare_booleans() throws Exception {
+    assertThat(areSimilar("{\"foo\": 3.14}", "{\"foo\": 3.14000000}")).isTrue();
+    assertThat(areSimilar("{\"foo\": 3.14}", "{\"foo\": 3.1400001}")).isTrue();
+  }
+
+  private boolean areSimilar(String expected, String actual) {
+    return new JsonComparison().areSimilar(expected, actual);
+  }
+
+  private boolean isSimilar_strict_timezone(String expected, String actual) {
+    return new JsonComparison().setStrictTimezone(true).areSimilar(expected, actual);
+  }
+
+  private boolean isSimilar_strict_array_order(String expected, String actual) {
+    return new JsonComparison().setStrictArrayOrder(true).areSimilar(expected, actual);
+  }
+}
diff --git a/sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample1.json b/sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample1.json
new file mode 100644 (file)
index 0000000..0967ef4
--- /dev/null
@@ -0,0 +1 @@
+{}
diff --git a/sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample2.json b/sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample2.json
new file mode 100644 (file)
index 0000000..fe51488
--- /dev/null
@@ -0,0 +1 @@
+[]