--- /dev/null
+/*
+ * 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")
+ );
+ }
+}
*/
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;
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) {
+++ /dev/null
-/*
- * 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();
-
- }
-
-}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+[
+ {
+ "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
+ }
+]
--- /dev/null
+[
+ {
+ "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
+ }
+]