]> source.dussan.org Git - sonarqube.git/commitdiff
Added test with JSON assertion in RuleWS
authorStephane Gamard <stephane.gamard@searchbox.com>
Wed, 14 May 2014 08:38:54 +0000 (10:38 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Wed, 14 May 2014 08:38:54 +0000 (10:38 +0200)
run.sh [new file with mode: 0755]
sonar-server/src/main/java/org/sonar/server/rule2/ws/ShowAction.java
sonar-server/src/test/java/org/sonar/server/rule2/ws/RulesWebServiceTest.java
sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_active_rules_params.json [new file with mode: 0644]

diff --git a/run.sh b/run.sh
new file mode 100755 (executable)
index 0000000..096e1ea
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+if [[ "$OSTYPE" == "darwin"* ]]; then
+  OS='macosx-universal-64'
+else
+  OS='linux-x86-64'
+fi
+
+if ! ls sonar-application/target/sonarqube-*.zip &> /dev/null; then
+  echo 'Sources are not built'
+  ./build.sh
+fi
+
+cd sonar-application/target/
+if ! ls sonarqube-*/bin/$OS/sonar.sh &> /dev/null; then
+  unzip sonarqube-*.zip
+fi
+cd sonarqube-*
+bin/$OS/sonar.sh restart
+echo "sonar.es.http.port=9200" >>  conf/sonar.properties
+sleep 1
+tail -100f logs/sonar.log
index 83d0428901f1230d930f5474ed1b077729ce1b16..8b304fee28996d3b60e62bc0320b3e266ce6bf24 100644 (file)
@@ -28,13 +28,10 @@ import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.rule2.Rule;
 import org.sonar.server.rule2.RuleParam;
 import org.sonar.server.rule2.RuleService;
 
-import java.util.Map;
-
 /**
  * @since 4.4
  */
@@ -85,9 +82,8 @@ public class ShowAction implements RequestHandler {
 
   private void writeRule(Rule rule, JsonWriter json) {
     json
-      .prop("key", rule.key().toString())
       .prop("repo", rule.key().repository())
-      .prop("slug", rule.key().rule())
+      .prop("key", rule.key().rule())
       .prop("lang", rule.language())
       .prop("name", rule.name())
       .prop("htmlDesc", rule.htmlDescription())
@@ -107,24 +103,5 @@ public class ShowAction implements RequestHandler {
         .endObject();
     }
     json.endArray();
-    json.name("actives").beginArray();
-
-    for (ActiveRule activeRule : result.getActiveRules()) {
-      json
-        .beginObject()
-        .prop("key", activeRule.key().toString())
-        .prop("inherit", activeRule.inherit())
-        .prop("override", activeRule.override())
-        .prop("severity", activeRule.severity())
-        .prop("parent", activeRule.parent())
-        .name("params").beginArray();
-      for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
-        json.beginObject()
-          .prop("key", param.getKey())
-          .prop("value", param.getValue())
-          .endObject();
-      }
-      json.endArray();
-    }
   }
 }
index 714e5ae1dccb15aaf1af86ac147f659540385a53..22c1185b2106d96cbbca82029e04e63e0c9e69a2 100644 (file)
@@ -170,7 +170,7 @@ public class RulesWebServiceTest {
     request.setParam("q","S001");
     WsTester.Result result = request.execute();
 
-    //TODO make JSON assertions here.
+    result.assertJson(this.getClass(),"search_active_rules_params.json");
   }
 
 
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_active_rules_params.json b/sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_active_rules_params.json
new file mode 100644 (file)
index 0000000..0127dd6
--- /dev/null
@@ -0,0 +1,37 @@
+{"total": 1, "rules": [
+    {
+        "key": "java:S001",
+        "repo": "java",
+        "slug": "S001",
+        "lang": "js",
+        "name": "Rule S001",
+        "htmlDesc": "Description S001",
+        "status": "READY",
+        "template": false,
+        "internalKey": "InternalKeyS001",
+        "severity": "INFO",
+        "tags": [],
+        "sysTags": [],
+        "params": [
+            {
+                "key": "my_var",
+                "desc": "My small description",
+                "defaultValue": "some value"
+            }
+        ],
+        "actives": [
+            {
+                "key": "My Profile:java:java:S001",
+                "inherit": "none",
+                "override": false,
+                "severity": "BLOCKER",
+                "params": [
+                    {
+                        "key": "my_var",
+                        "value": "The VALUE"
+                    }
+                ]
+            }
+        ]
+    }
+]}