]> source.dussan.org Git - sonarqube.git/commitdiff
Removed slug from WS
authorStephane Gamard <stephane.gamard@searchbox.com>
Wed, 14 May 2014 09:10:32 +0000 (11:10 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Wed, 14 May 2014 09:10:39 +0000 (11:10 +0200)
sonar-server/src/main/java/org/sonar/server/rule2/ws/SearchAction.java
sonar-server/src/main/resources/org/sonar/server/rule2/ws/example-search.json [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/rule2/ws/RulesWebServiceTest.java
sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_2_rules.json [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_active_rules.json [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_active_rules_params.json

index 0af4d76ae6940438eb9ba67ad44ea4b26963bcce..c6655a66f89381faffc6e8b2bea5f2d657cdbf2c 100644 (file)
@@ -210,7 +210,6 @@ public class SearchAction implements RequestHandler {
       json
         .prop("key", rule.key().toString())
         .prop("repo", rule.key().repository())
-        .prop("slug", rule.key().rule())
         .prop("lang", rule.language())
         .prop("name", rule.name())
         .prop("htmlDesc", rule.htmlDescription())
diff --git a/sonar-server/src/main/resources/org/sonar/server/rule2/ws/example-search.json b/sonar-server/src/main/resources/org/sonar/server/rule2/ws/example-search.json
new file mode 100644 (file)
index 0000000..a94500f
--- /dev/null
@@ -0,0 +1,496 @@
+{"total": 5, "rules": [
+    {
+        "key": "squid:S1067",
+        "repo": "squid",
+        "lang": "java",
+        "name": "Expressions should not be too complex",
+        "htmlDesc": "<p>\nThe complexity of an expression is defined by the number of <code>&&</code>, <code>||</code> and <code>condition ? ifTrue : ifFalse</code> operators it contains.\nA single expression's complexity should not become too high to keep the code readable.\n</p>\n\n<p>The following code, with a maximum complexity of 3:</p>\n\n<pre>\nif (condition1 && condition2 && condition3 && condition4) { /* ... */ }  // Non-Compliant\n</pre>\n\n<p>could be refactored into something like:</p>\n\n<pre>\nif (relevantMethodName1() && relevantMethodName2()) { /* ... */ }        // Compliant\n\n/* ... */\n\nprivate boolean relevantMethodName1() {\n  return condition1 && condition2;\n}\n\nprivate boolean relevantMethodName2() {\n  return condition3 && condition4;\n}\n</pre>",
+        "status": "READY",
+        "template": false,
+        "internalKey": "S1067",
+        "severity": "MAJOR",
+        "tags": [],
+        "sysTags": ["brain-overload"],
+        "params": [
+            {
+                "key": "max",
+                "desc": "Maximum number of allowed conditional operators in an expression",
+                "defaultValue": "3"
+            }
+        ],
+        "actives": [
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            },
+            {
+                "key": "Sonar way:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            }
+        ]
+    },
+    {
+        "key": "squid:MethodCyclomaticComplexity",
+        "repo": "squid",
+        "lang": "java",
+        "name": "Methods should not be too complex",
+        "htmlDesc": "<p>The Cyclomatic Complexity is measured by the number of\n\t(&amp;&amp;, ||) operators and (if, while, do, for, ?:, catch, switch,\n\tcase, return, throw) statements in the body of a class plus one for\n\teach constructor, method (but not getter/setter), static initializer,\n\tor instance initializer in the class. The last return stament in\n\tmethod, if exists, is not taken into account.</p>\n<p>\n\tEven when the Cyclomatic Complexity of a class is very high, this\n\tcomplexity might be well distributed among all methods. Nevertheless,\n\tmost of the time, a very complex class is a class which breaks the <a\n\t\thref=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\">Single\n\t\tResponsibility Principle</a> and which should be re-factored to be split\n\tin several classes.\n</p>",
+        "status": "READY",
+        "template": false,
+        "internalKey": "MethodCyclomaticComplexity",
+        "severity": "MAJOR",
+        "tags": [],
+        "sysTags": ["brain-overload"],
+        "params": [
+            {
+                "key": "max",
+                "desc": "Maximum complexity allowed.",
+                "defaultValue": "10"
+            }
+        ],
+        "actives": [
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            },
+            {
+                "key": "Sonar way:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            }
+        ]
+    },
+    {
+        "key": "squid:ClassCyclomaticComplexity",
+        "repo": "squid",
+        "lang": "java",
+        "name": "Avoid too complex class",
+        "htmlDesc": "<p>The Cyclomatic Complexity is measured by the number of (&&, ||)\n\toperators and (if, while, do, for, ?:, catch, switch, case, return,\n\tthrow) statements in the body of a class plus one for each constructor,\n\tmethod (but not getter/setter), static initializer, or instance\n\tinitializer in the class. The last return stament in method, if exists,\n\tis not taken into account.</p>\n<p>\n\tEven when the Cyclomatic Complexity of a class is very high, this\n\tcomplexity might be well distributed among all methods. Nevertheless,\n\tmost of the time, a very complex class is a class which breaks the <a\n\t\thref='http://en.wikipedia.org/wiki/Single_responsibility_principle'>Single\n\t\tResponsibility Principle</a> and which should be re-factored to be split\n\tin several classes.\n</p>",
+        "status": "READY",
+        "template": false,
+        "internalKey": "ClassCyclomaticComplexity",
+        "severity": "MAJOR",
+        "tags": [],
+        "sysTags": ["brain-overload"],
+        "params": [
+            {
+                "key": "max",
+                "desc": "Maximum complexity allowed.",
+                "defaultValue": "200"
+            }
+        ],
+        "actives": [
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            },
+            {
+                "key": "Sonar way:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            }
+        ]
+    },
+    {
+        "key": "squid:S1160",
+        "repo": "squid",
+        "lang": "java",
+        "name": "Public methods should throw at most one checked exception",
+        "htmlDesc": "<p>\nUsing checked exceptions forces method callers to deal with errors, either by propagating them or by handling them.\nThis makes those exceptions fully part of the API of the method.\n</p>\n\n<p>\nTo keep the complexity for callers reasonable, methods should not throw more than one kind of checked exception.\n</p>\n\n<p>The following code:</p>\n\n<pre>\npublic void delete() throws IOException, SQLException {      // Non-Compliant\n  /* ... */\n}\n</pre>\n\n<p>should be refactored into:</p>\n\n<pre>\npublic void delete() throws SomeApplicationLevelException {  // Compliant\n  /* ... */\n}\n</pre>\n\nOverriding methods are not checked by this rule and are allowed to throw several checked exceptions.",
+        "status": "READY",
+        "template": false,
+        "internalKey": "S1160",
+        "severity": "MAJOR",
+        "tags": [],
+        "sysTags": ["error-handling"],
+        "params": [],
+        "actives": [
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            },
+            {
+                "key": "Sonar way:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            }
+        ]
+    },
+    {
+        "key": "squid:S1142",
+        "repo": "squid",
+        "lang": "java",
+        "name": "Methods should not contain too many return statements",
+        "htmlDesc": "<p>\nHaving too many return statements in a method increases the method's essential complexity because the flow of execution is broken each time a return statement is encountered.\nThis makes it harder to read and understand the logic of the method.\n</p>\n\n<p>\nThe following code snippet illustrates this rule with the default threshold of 3:\n</p>\n\n<pre>\npublic boolean myMethod() { // Non-Compliant as there are 4 return statements\n  if (condition1) {\n    return true;\n  } else {\n    if (condition2) {\n      return false;\n    } else {\n      return true;\n    }\n  }\n  return false;\n}\n</pre>",
+        "status": "READY",
+        "template": false,
+        "internalKey": "S1142",
+        "severity": "MAJOR",
+        "tags": [],
+        "sysTags": ["brain-overload"],
+        "params": [
+            {
+                "key": "max",
+                "desc": "Maximum allowed return statements per method",
+                "defaultValue": "3"
+            }
+        ],
+        "actives": [
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:S1067",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "3"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:MethodCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "10"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way:java:squid:ClassCyclomaticComplexity",
+                "override": false,
+                "severity": "MAJOR",
+                "params": [
+                    {
+                        "key": "max",
+                        "value": "200"
+                    }
+                ]
+            },
+            {
+                "key": "Sonar way with Findbugs:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            },
+            {
+                "key": "Sonar way:java:squid:S1160",
+                "override": false,
+                "severity": "MAJOR",
+                "params": []
+            }
+        ]
+    }
+]}
\ No newline at end of file
index d44d4019b34a4012007429ff9ebb8acda9beb481..7b648d506ff14f03d832d54715415a139d3b3c38 100644 (file)
@@ -111,7 +111,7 @@ public class RulesWebServiceTest {
     WsTester.TestRequest request = wsTester.newGetRequest("api/rules2", "search");
     WsTester.Result result = request.execute();
 
-    //TODO make JSON assertions here.
+    result.assertJson(this.getClass(),"search_2_rules.json");
   }
 
   @Test
@@ -135,8 +135,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.json");
   }
 
   @Test
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_2_rules.json b/sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_2_rules.json
new file mode 100644 (file)
index 0000000..fb18830
--- /dev/null
@@ -0,0 +1,32 @@
+{"total": 2, "rules": [
+    {
+        "key": "javascript:S002",
+        "repo": "javascript",
+        "lang": "js",
+        "name": "Rule S002",
+        "htmlDesc": "Description S002",
+        "status": "READY",
+        "template": false,
+        "internalKey": "InternalKeyS002",
+        "severity": "INFO",
+        "tags": [],
+        "sysTags": [],
+        "params": [],
+        "actives": []
+    },
+    {
+        "key": "javascript:S001",
+        "repo": "javascript",
+        "lang": "js",
+        "name": "Rule S001",
+        "htmlDesc": "Description S001",
+        "status": "READY",
+        "template": false,
+        "internalKey": "InternalKeyS001",
+        "severity": "INFO",
+        "tags": [],
+        "sysTags": [],
+        "params": [],
+        "actives": []
+    }
+]}
diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_active_rules.json b/sonar-server/src/test/resources/org/sonar/server/rule2/ws/RulesWebServiceTest/search_active_rules.json
new file mode 100644 (file)
index 0000000..77fa4bb
--- /dev/null
@@ -0,0 +1,25 @@
+{"total": 1, "rules": [
+    {
+        "key": "java:S001",
+        "repo": "java",
+        "lang": "js",
+        "name": "Rule S001",
+        "htmlDesc": "Description S001",
+        "status": "READY",
+        "template": false,
+        "internalKey": "InternalKeyS001",
+        "severity": "INFO",
+        "tags": [],
+        "sysTags": [],
+        "params": [],
+        "actives": [
+            {
+                "key": "My Profile:java:java:S001",
+                "inherit": "none",
+                "override": false,
+                "severity": "BLOCKER",
+                "params": []
+            }
+        ]
+    }
+]}
index 0127dd68e0dfd384593b2739b59af3d477b5590c..2fd13e2419173c033edcc97797423e88bb06728a 100644 (file)
@@ -2,7 +2,6 @@
     {
         "key": "java:S001",
         "repo": "java",
-        "slug": "S001",
         "lang": "js",
         "name": "Rule S001",
         "htmlDesc": "Description S001",