aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-03-19 14:46:58 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-03-20 11:07:24 +0100
commit88219ea163c159be7d16203be32d8f0b3d7e7d0a (patch)
treeef96d6c0860ebac6b53ff6f39d521a733c14c25b
parent1af9a73913f04992e8a9033b29980dd74c6f0a22 (diff)
downloadsonarqube-88219ea163c159be7d16203be32d8f0b3d7e7d0a.tar.gz
sonarqube-88219ea163c159be7d16203be32d8f0b3d7e7d0a.zip
Replace lib org.skyscreamer.jsonassert by org.sonar.test.JsonAssert.
This class supports lenient comparison of datetime values.
-rw-r--r--pom.xml5
-rw-r--r--server/sonar-server/pom.xml5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/HistoryWsActionMediumTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueWsActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsJsonWriterTest.java29
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/es/SearchOptionsTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueActionsWriterTest.java11
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueTagsActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java66
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java46
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/ws/L10nWsTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java38
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java44
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java16
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmWriterTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java14
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/ws/ComponentTagsActionTest/component-tags.json14
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/get_tags.json9
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules.json27
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_debt_rules_sticky.json87
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_profile_active_rules_inheritance.json6
-rw-r--r--sonar-batch-protocol/pom.xml5
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java14
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectRepositoriesTest.java33
-rw-r--r--sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/GlobalRepositoriesTest/expected.json21
-rw-r--r--sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/ProjectRepositoriesTest/testToJson.json49
-rw-r--r--sonar-batch/pom.xml5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java18
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json44
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json113
-rw-r--r--sonar-testing-harness/pom.xml8
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java100
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java198
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java97
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/JsonComparisonTest.java178
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample1.json1
-rw-r--r--sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample2.json1
45 files changed, 1002 insertions, 371 deletions
diff --git a/pom.xml b/pom.xml
index aff4f463020..47fd2355e8d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1034,11 +1034,6 @@
<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>
<version>1.3</version>
diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml
index da5049e8286..bc6768f29a9 100644
--- a/server/sonar-server/pom.xml
+++ b/server/sonar-server/pom.xml
@@ -216,11 +216,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.skyscreamer</groupId>
- <artifactId>jsonassert</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<scope>test</scope>
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
index 36f91833e9f..8c8e4670c71 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/HistoryWsActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/HistoryWsActionMediumTest.java
index 26fe86462b3..d04c2c21cf7 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/HistoryWsActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/HistoryWsActionMediumTest.java
@@ -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)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueWsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueWsActionTest.java
index 846f8d095b3..ebf3bf043f4 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueWsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueWsActionTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsJsonWriterTest.java b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsJsonWriterTest.java
index 73df3a7c827..18fd62b7fec 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsJsonWriterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsJsonWriterTest.java
@@ -20,18 +20,17 @@
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);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/SearchOptionsTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/SearchOptionsTest.java
index 8eea2257555..6c1db01f582 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/es/SearchOptionsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/es/SearchOptionsTest.java
@@ -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}}");
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java
index 8ab06092016..35bce350817 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/FavoritesActionTest.java
@@ -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}]}");
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java
index d9e71d91800..a468eeb70ad 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/filter/IssueFilterWriterTest.java
@@ -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);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java
index fe6472b390c..4dd53d9bf0f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/ComponentTagsActionTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueActionsWriterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueActionsWriterTest.java
index 73f0d301ff3..d4f10786a6a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueActionsWriterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueActionsWriterTest.java
@@ -20,13 +20,11 @@
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);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueTagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueTagsActionTest.java
index 9519396292b..3bdf5a1c37b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueTagsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueTagsActionTest.java
@@ -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);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
index b8d6c393b92..6d6759b1575 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
@@ -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() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
index 1132c428782..174005a2ccf 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
@@ -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() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/L10nWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/L10nWsTest.java
index 810f325b827..1c5dd04158f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/L10nWsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/L10nWsTest.java
@@ -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\"}");
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java
index d36da7bfd60..6e531cac71c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/QGatesWsTest.java
@@ -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());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
index 8ba84ec7e23..3e432a78d2f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java
@@ -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);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java
index 4a97bf50e68..9a45b332a79 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java
@@ -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);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
index cc4819a9a58..779487d4e4b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java
@@ -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");
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java
index 68b64822c2e..7ce82055083 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java
index d4bcee11a82..e69e22ee157 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
index acfc1527b63..bcd67c877c1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
@@ -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
diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmWriterTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmWriterTest.java
index bec891ff22c..cf05251cf34 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmWriterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmWriterTest.java
@@ -19,10 +19,9 @@
*/
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);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java b/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
index b0e4e7264dd..1be9064a188 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
@@ -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;
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/ComponentTagsActionTest/component-tags.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/ComponentTagsActionTest/component-tags.json
index 38e018c645b..e3afc9a2dc4 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/ComponentTagsActionTest/component-tags.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/ComponentTagsActionTest/component-tags.json
@@ -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
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/get_tags.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/get_tags.json
index 14764b48180..c9a14f30cd0 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/get_tags.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/get_tags.json
@@ -1 +1,8 @@
-{"tags": ["hello", "sys1", "java", "world"]} \ No newline at end of file
+{
+ "tags": [
+ "sys1",
+ "java",
+ "world",
+ "hello"
+ ]
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules.json
index bd84f45871e..a3da4d33ff2 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_2_rules.json
@@ -1,5 +1,7 @@
{
- "total": 2, "p": 1, "ps": 100,
+ "total": 2,
+ "p": 1,
+ "ps": 100,
"rules": [
{
"key": "xoo:x2",
@@ -10,8 +12,14 @@
"status": "READY",
"internalKey": "InternalKeyx2",
"isTemplate": false,
- "tags": ["tag1", "tag2"],
- "sysTags": ["systag1", "systag2"],
+ "tags": [
+ "tag1",
+ "tag2"
+ ],
+ "sysTags": [
+ "systag1",
+ "systag2"
+ ],
"debtRemFnType": "LINEAR",
"debtRemFnCoeff": "1h",
"debtRemFnOffset": "5min",
@@ -27,12 +35,19 @@
"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": []
}
- ]}
+ ]
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_debt_rules_sticky.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_debt_rules_sticky.json
index a7cba30b88e..59441d3015d 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_debt_rules_sticky.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_debt_rules_sticky.json
@@ -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
+ }
+ ]
+ }
+ ]
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_profile_active_rules_inheritance.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_profile_active_rules_inheritance.json
index 80d049d4442..adc48218f3e 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_profile_active_rules_inheritance.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWebServiceMediumTest/search_profile_active_rules_inheritance.json
@@ -1,7 +1,7 @@
{
- "total":1,
- "p":1,
- "ps":100,
+ "total": 1,
+ "p": 1,
+ "ps": 100,
"rules": [
{
"key": "xoo:x1"
diff --git a/sonar-batch-protocol/pom.xml b/sonar-batch-protocol/pom.xml
index 6dc19b488e3..28e8f7dfacd 100644
--- a/sonar-batch-protocol/pom.xml
+++ b/sonar-batch-protocol/pom.xml
@@ -41,11 +41,6 @@
<artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.skyscreamer</groupId>
- <artifactId>jsonassert</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java
index 2f4652d3ded..fb7c5d46fb0 100644
--- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java
@@ -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,"
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectRepositoriesTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectRepositoriesTest.java
index cfb584f97e7..b86b2938f15 100644
--- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectRepositoriesTest.java
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectRepositoriesTest.java
@@ -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
index 00000000000..de38ae0cb18
--- /dev/null
+++ b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/GlobalRepositoriesTest/expected.json
@@ -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
index 00000000000..7b5e29c3695
--- /dev/null
+++ b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/input/ProjectRepositoriesTest/testToJson.json
@@ -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"
+}
diff --git a/sonar-batch/pom.xml b/sonar-batch/pom.xml
index f199b70343a..c2f0eaf47fd 100644
--- a/sonar-batch/pom.xml
+++ b/sonar-batch/pom.xml
@@ -192,11 +192,6 @@
<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>
<scope>test</scope>
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
index 1e61491a8c1..e1afdb05fcf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
@@ -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
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json b/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json
index d699073ee83..b5af45efe6c 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json
+++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json
@@ -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": []
}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json b/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json
index 2e34d745924..91c1e3a3eac 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json
+++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/report/JsonReportTest/report.json
@@ -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"
+ }
+ ]
+}
diff --git a/sonar-testing-harness/pom.xml b/sonar-testing-harness/pom.xml
index a0af4198337..11126f3cbe4 100644
--- a/sonar-testing-harness/pom.xml
+++ b/sonar-testing-harness/pom.xml
@@ -16,8 +16,12 @@
<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
index 00000000000..ac9f2470da6
--- /dev/null
+++ b/sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java
@@ -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
index 00000000000..1a437f5daad
--- /dev/null
+++ b/sonar-testing-harness/src/main/java/org/sonar/test/JsonComparison.java
@@ -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
index 00000000000..59a05d6506f
--- /dev/null
+++ b/sonar-testing-harness/src/test/java/org/sonar/test/JsonAssertTest.java
@@ -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
index 00000000000..6dc57199a7c
--- /dev/null
+++ b/sonar-testing-harness/src/test/java/org/sonar/test/JsonComparisonTest.java
@@ -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
index 00000000000..0967ef424bc
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample1.json
@@ -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
index 00000000000..fe51488c706
--- /dev/null
+++ b/sonar-testing-harness/src/test/resources/org/sonar/test/JsonAssertTest/sample2.json
@@ -0,0 +1 @@
+[]