]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Add Issue Web Service Client Unmarshaller
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 10 Apr 2013 16:36:22 +0000 (18:36 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 10 Apr 2013 16:36:22 +0000 (18:36 +0200)
sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/IssueUnmarshaller.java [new file with mode: 0644]
sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueTest.java [deleted file]
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/IssueUnmarshallerTest.java [new file with mode: 0644]
sonar-ws-client/src/test/resources/issues/all_issues.json [new file with mode: 0644]
sonar-ws-client/src/test/resources/issues/single_issue.json [new file with mode: 0644]

diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/IssueUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/IssueUnmarshaller.java
new file mode 100644 (file)
index 0000000..ca6a07e
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.sonar.wsclient.services.Issue;
+import org.sonar.wsclient.services.WSUtils;
+
+public class IssueUnmarshaller extends AbstractUnmarshaller<Issue> {
+
+  @Override
+  protected Issue parse(Object json) {
+    WSUtils utils = WSUtils.getINSTANCE();
+    return new Issue()
+        .setKey(utils.getString(json, "key"))
+        .setComponentKey(utils.getString(json, "component"))
+        .setRuleKey(utils.getString(json, "ruleKey"))
+        .setRuleRepositoryKey(utils.getString(json, "ruleRepositoryKey"))
+        .setSeverity(utils.getString(json, "severity"))
+        .setTitle(utils.getString(json, "title"))
+        .setMessage(utils.getString(json, "message"))
+        .setLine(utils.getInteger(json, "line"))
+        .setCost(utils.getDouble(json, "cost"))
+        .setStatus(utils.getString(json, "status"))
+        .setResolution(utils.getString(json, "resolution"))
+        .setUserLogin(utils.getString(json, "userLogin"))
+        .setAssigneeLogin(utils.getString(json, "assigneeLogin"))
+        .setCreatedAt(utils.getDateTime(json, "createdAt"))
+        .setUpdatedAt(utils.getDateTime(json, "updatedAt"))
+        .setClosedAt(utils.getDateTime(json, "closedAt")
+        );
+  }
+}
index 0e5d299f2f35c99315ba7e1f5662d2fa29ff8517..f4f565c7104d42e6b8a8de7cf5fb35d62a1b900a 100644 (file)
  */
 package org.sonar.wsclient.unmarshallers;
 
-import org.sonar.wsclient.services.Authentication;
-import org.sonar.wsclient.services.Dependency;
-import org.sonar.wsclient.services.DependencyTree;
-import org.sonar.wsclient.services.Event;
-import org.sonar.wsclient.services.Favourite;
-import org.sonar.wsclient.services.ManualMeasure;
-import org.sonar.wsclient.services.Metric;
-import org.sonar.wsclient.services.Model;
-import org.sonar.wsclient.services.Plugin;
-import org.sonar.wsclient.services.Profile;
-import org.sonar.wsclient.services.Property;
-import org.sonar.wsclient.services.Resource;
-import org.sonar.wsclient.services.ResourceSearchResult;
-import org.sonar.wsclient.services.Review;
-import org.sonar.wsclient.services.Rule;
-import org.sonar.wsclient.services.Server;
-import org.sonar.wsclient.services.ServerSetup;
-import org.sonar.wsclient.services.Source;
-import org.sonar.wsclient.services.TimeMachine;
-import org.sonar.wsclient.services.Violation;
+import org.sonar.wsclient.services.*;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -70,6 +51,7 @@ public final class Unmarshallers {
     unmarshallers.put(ManualMeasure.class, new ManualMeasureUnmarshaller());
     unmarshallers.put(Authentication.class, new AuthenticationUnmarshaller());
     unmarshallers.put(ResourceSearchResult.class, new ResourceSearchUnmarshaller());
+    unmarshallers.put(Issue.class, new IssueUnmarshaller());
   }
 
   public static <M extends Model> Unmarshaller<M> forModel(Class<M> modelClass) {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/IssueTest.java
deleted file mode 100644 (file)
index 33fc868..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-
-package org.sonar.wsclient.services;
-
-import org.junit.Test;
-
-import java.util.Date;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class IssueTest {
-
-  @Test
-  public void test_getter_and_setter() {
-    Issue issue = new Issue()
-        .setKey("key")
-        .setComponentKey("componentKey")
-        .setRuleKey("ruleKey")
-        .setRuleRepositoryKey("ruleRepositoryKey")
-        .setSeverity("severity")
-        .setTitle("title")
-        .setMessage("message")
-        .setLine(1)
-        .setCost(1.0)
-        .setStatus("status")
-        .setResolution("resolution")
-        .setUserLogin("userLogin")
-        .setAssigneeLogin("assigneeLogin")
-        .setCreatedAt(new Date())
-        .setUpdatedAt(new Date())
-        .setClosedAt(new Date());
-
-    assertThat(issue.getKey()).isNotNull();
-    assertThat(issue.getComponentKey()).isNotNull();
-    assertThat(issue.getRuleKey()).isNotNull();
-    assertThat(issue.getRuleRepositoryKey()).isNotNull();
-    assertThat(issue.getSeverity()).isNotNull();
-    assertThat(issue.getTitle()).isNotNull();
-    assertThat(issue.getMessage()).isNotNull();
-    assertThat(issue.getLine()).isNotNull();
-    assertThat(issue.getCost()).isNotNull();
-    assertThat(issue.getStatus()).isNotNull();
-    assertThat(issue.getResolution()).isNotNull();
-    assertThat(issue.getUserLogin()).isNotNull();
-    assertThat(issue.getAssigneeLogin()).isNotNull();
-    assertThat(issue.getCreatedAt()).isNotNull();
-    assertThat(issue.getUpdatedAt()).isNotNull();
-    assertThat(issue.getClosedAt()).isNotNull();
-
-  }
-
-}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/IssueUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/IssueUnmarshallerTest.java
new file mode 100644 (file)
index 0000000..336393b
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+
+package org.sonar.wsclient.unmarshallers;
+
+import org.junit.Test;
+import org.sonar.wsclient.services.Issue;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueUnmarshallerTest extends UnmarshallerTestCase {
+
+  @Test
+  public void should_return_nothing() {
+    Issue issue = new IssueUnmarshaller().toModel("[]");
+    assertThat(issue).isNull();
+  }
+
+  @Test
+  public void should_return_one_issue() {
+    Issue issue = new IssueUnmarshaller().toModel(loadFile("/issues/single_issue.json"));
+    assertThat(issue.getKey()).isEqualTo("029d283a-072b-4ef8-bdda-e4b212aa39e3");
+    assertThat(issue.getComponentKey()).isEqualTo("com.sonarsource.it.samples:simple-sample:sample");
+    assertThat(issue.getRuleKey()).isEqualTo("NM_FIELD_NAMING_CONVENTION");
+    assertThat(issue.getRuleRepositoryKey()).isEqualTo("findbugs");
+    assertThat(issue.getSeverity()).isEqualTo("MAJOR");
+    assertThat(issue.getTitle()).isEqualTo("title");
+    assertThat(issue.getMessage()).isEqualTo("message");
+    assertThat(issue.getLine()).isEqualTo(1);
+    assertThat(issue.getCost()).isEqualTo(1.2);
+    assertThat(issue.getStatus()).isEqualTo("OPEN");
+    assertThat(issue.getResolution()).isEqualTo("FIXED");
+    assertThat(issue.getUserLogin()).isEqualTo("admin");
+    assertThat(issue.getAssigneeLogin()).isEqualTo("admin");
+    assertThat(issue.getCreatedAt()).isNotNull();
+    assertThat(issue.getUpdatedAt()).isNotNull();
+    assertThat(issue.getClosedAt()).isNull();
+  }
+
+  @Test
+  public void should_return_all_issues() {
+    List<Issue> issues = new IssueUnmarshaller().toModels(loadFile("/issues/all_issues.json"));
+    assertThat(issues).hasSize(2);
+  }
+
+}
diff --git a/sonar-ws-client/src/test/resources/issues/all_issues.json b/sonar-ws-client/src/test/resources/issues/all_issues.json
new file mode 100644 (file)
index 0000000..05ff7ac
--- /dev/null
@@ -0,0 +1,38 @@
+[
+  {
+    "key": "029d283a-072b-4ef8-bdda-e4b212aa39e3",
+    "component": "com.sonarsource.it.samples:simple-sample:sample",
+    "ruleKey": "NM_FIELD_NAMING_CONVENTION",
+    "ruleRepositoryKey": "findbugs",
+    "severity": "MAJOR",
+    "title": "title",
+    "message": "message",
+    "line": 1,
+    "cost": 1.2,
+    "status": "OPEN",
+    "resolution": "FIXED",
+    "userLogin": "admin",
+    "assigneeLogin": "admin",
+    "createdAt": "2013-04-10T18:21:15+0200",
+    "updatedAt": "2013-04-10T18:21:15+0200",
+    "closedAt": null
+  },
+  {
+    "key": "029d283a-072b-4ef8-bdda-e4b212aa39e4",
+    "component": "com.sonarsource.it.samples:simple-sample:sample",
+    "ruleKey": "RULE_KEY",
+    "ruleRepositoryKey": "pmd",
+    "severity": "MAJOR",
+    "title": "title",
+    "message": "message",
+    "line": 1,
+    "cost": 1.2,
+    "status": "OPEN",
+    "resolution": null,
+    "userLogin": null,
+    "assigneeLogin": null,
+    "createdAt": "2013-04-10T18:21:15+0200",
+    "updatedAt": "2013-04-10T18:21:15+0200",
+    "closedAt": null
+  }
+]
diff --git a/sonar-ws-client/src/test/resources/issues/single_issue.json b/sonar-ws-client/src/test/resources/issues/single_issue.json
new file mode 100644 (file)
index 0000000..5d5f274
--- /dev/null
@@ -0,0 +1,20 @@
+[
+  {
+    "key": "029d283a-072b-4ef8-bdda-e4b212aa39e3",
+    "component": "com.sonarsource.it.samples:simple-sample:sample",
+    "ruleKey": "NM_FIELD_NAMING_CONVENTION",
+    "ruleRepositoryKey": "findbugs",
+    "severity": "MAJOR",
+    "title": "title",
+    "message": "message",
+    "line": 1,
+    "cost": 1.2,
+    "status": "OPEN",
+    "resolution": "FIXED",
+    "userLogin": "admin",
+    "assigneeLogin": "admin",
+    "createdAt": "2013-04-10T18:21:15+0200",
+    "updatedAt": "2013-04-10T18:21:15+0200",
+    "closedAt": null
+  }
+]