diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-12-15 14:22:10 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-12-17 13:14:49 +0100 |
commit | 789df9c9ba0ccdf72e5e5ab24de04b47798e4f72 (patch) | |
tree | 224d9625710131d51bc0f23cfbfbb2109b604112 /sonar-batch-protocol | |
parent | 597cf003728da27dac4a51a624358263ff8e88f7 (diff) | |
download | sonarqube-789df9c9ba0ccdf72e5e5ab24de04b47798e4f72.tar.gz sonarqube-789df9c9ba0ccdf72e5e5ab24de04b47798e4f72.zip |
SONAR-5945 Upload issues in analysis report
Diffstat (limited to 'sonar-batch-protocol')
12 files changed, 753 insertions, 10 deletions
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/GsonHelper.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/GsonHelper.java new file mode 100644 index 00000000000..b5ea008a538 --- /dev/null +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/GsonHelper.java @@ -0,0 +1,35 @@ +/* + * 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.batch.protocol; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class GsonHelper { + + private GsonHelper() { + // Utility class + } + + public static Gson create() { + return new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").setPrettyPrinting().create(); + } + +} diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java index 4fa32d5d68b..e7501e4d1de 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java @@ -19,7 +19,7 @@ */ package org.sonar.batch.protocol.input; -import com.google.gson.Gson; +import org.sonar.batch.protocol.GsonHelper; import java.util.ArrayList; import java.util.Collection; @@ -63,11 +63,11 @@ public class GlobalReferentials { } public String toJson() { - return new Gson().toJson(this); + return GsonHelper.create().toJson(this); } public static GlobalReferentials fromJson(String json) { - return new Gson().fromJson(json, GlobalReferentials.class); + return GsonHelper.create().fromJson(json, GlobalReferentials.class); } } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java index 68d06e73b48..b945da6f7b8 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java @@ -19,8 +19,7 @@ */ package org.sonar.batch.protocol.input; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import org.sonar.batch.protocol.GsonHelper; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -114,13 +113,11 @@ public class ProjectReferentials { } public String toJson() { - Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create(); - return gson.toJson(this); + return GsonHelper.create().toJson(this); } public static ProjectReferentials fromJson(String json) { - Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create(); - return gson.fromJson(json, ProjectReferentials.class); + return GsonHelper.create().fromJson(json, ProjectReferentials.class); } } diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/issue/ReportIssue.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/issue/ReportIssue.java new file mode 100644 index 00000000000..3917d54d2a2 --- /dev/null +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/issue/ReportIssue.java @@ -0,0 +1,275 @@ +/* + * 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.batch.protocol.output.issue; + +import javax.annotation.Nullable; + +import java.util.Date; + +public class ReportIssue { + + private long resourceBatchId; + private boolean isNew; + private String ruleKey; + private String ruleRepo; + private String key; + private Integer line; + private String message; + private Double effortToFix; + private Long debtInMinutes; + private String resolution; + private String status; + private String severity; + private String checksum; + private boolean manualSeverity; + private String reporter; + private String assignee; + private String actionPlanKey; + private String attributes; + private String authorLogin; + private Date creationDate; + private Date closeDate; + private Date updateDate; + private Long selectedAt; + private String diffFields; + private boolean isChanged; + + public ReportIssue setKey(String key) { + this.key = key; + return this; + } + + public String key() { + return key; + } + + public ReportIssue setResourceBatchId(long resourceBatchId) { + this.resourceBatchId = resourceBatchId; + return this; + } + + public long resourceBatchId() { + return resourceBatchId; + } + + public ReportIssue setNew(boolean isNew) { + this.isNew = isNew; + return this; + } + + public boolean isNew() { + return isNew; + } + + public ReportIssue setLine(Integer line) { + this.line = line; + return this; + } + + public Integer line() { + return line; + } + + public ReportIssue setMessage(String message) { + this.message = message; + return this; + } + + public String message() { + return message; + } + + public ReportIssue setEffortToFix(Double effortToFix) { + this.effortToFix = effortToFix; + return this; + } + + public Double effortToFix() { + return effortToFix; + } + + public ReportIssue setDebt(Long debtInMinutes) { + this.debtInMinutes = debtInMinutes; + return this; + } + + public Long debt() { + return debtInMinutes; + } + + public ReportIssue setResolution(String resolution) { + this.resolution = resolution; + return this; + } + + public String resolution() { + return resolution; + } + + public ReportIssue setStatus(String status) { + this.status = status; + return this; + } + + public String status() { + return status; + } + + public ReportIssue setSeverity(String severity) { + this.severity = severity; + return this; + } + + public String severity() { + return severity; + } + + public ReportIssue setChecksum(String checksum) { + this.checksum = checksum; + return this; + } + + public String checksum() { + return checksum; + } + + public ReportIssue setManualSeverity(boolean manualSeverity) { + this.manualSeverity = manualSeverity; + return this; + } + + public boolean isManualSeverity() { + return manualSeverity; + } + + public ReportIssue setReporter(String reporter) { + this.reporter = reporter; + return this; + } + + public String reporter() { + return reporter; + } + + public ReportIssue setAssignee(String assignee) { + this.assignee = assignee; + return this; + } + + public String assignee() { + return assignee; + } + + public ReportIssue setRuleKey(String ruleRepo, String ruleKey) { + this.ruleRepo = ruleRepo; + this.ruleKey = ruleKey; + return this; + } + + public String ruleRepo() { + return ruleRepo; + } + + public String ruleKey() { + return ruleKey; + } + + public ReportIssue setActionPlanKey(String actionPlanKey) { + this.actionPlanKey = actionPlanKey; + return this; + } + + public String actionPlanKey() { + return actionPlanKey; + } + + public ReportIssue setAttributes(String attributes) { + this.attributes = attributes; + return this; + } + + public String issueAttributes() { + return attributes; + } + + public ReportIssue setAuthorLogin(String authorLogin) { + this.authorLogin = authorLogin; + return this; + } + + public String authorLogin() { + return authorLogin; + } + + public ReportIssue setCreationDate(Date creationDate) { + this.creationDate = creationDate; + return this; + } + + public Date creationDate() { + return creationDate; + } + + public ReportIssue setCloseDate(Date closeDate) { + this.closeDate = closeDate; + return this; + } + + public Date closeDate() { + return closeDate; + } + + public ReportIssue setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + return this; + } + + public Date updateDate() { + return updateDate; + } + + public ReportIssue setSelectedAt(Long selectedAt) { + this.selectedAt = selectedAt; + return this; + } + + public Long selectedAt() { + return selectedAt; + } + + public ReportIssue setDiffFields(@Nullable String diffFields) { + this.diffFields = diffFields; + return this; + } + + public String diffFields() { + return diffFields; + } + + public ReportIssue setChanged(boolean isChanged) { + this.isChanged = isChanged; + return this; + } + + public boolean isChanged() { + return isChanged; + } + +} diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/issue/package-info.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/issue/package-info.java new file mode 100644 index 00000000000..444216d69f1 --- /dev/null +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/issue/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.batch.protocol.output.issue; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/ReportResource.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/ReportResource.java new file mode 100644 index 00000000000..44ceb7386ce --- /dev/null +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/ReportResource.java @@ -0,0 +1,106 @@ +/* + * 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.batch.protocol.output.resource; + +import java.util.ArrayList; +import java.util.Collection; + +public class ReportResource { + + public enum Type { + PRJ, + MOD, + DIR, + FIL + } + + private long batchId; + private int id; + private int snapshotId; + private String path; + private String name; + private Type type; + + private Collection<ReportResource> children = new ArrayList<ReportResource>(); + + public ReportResource setBatchId(long batchId) { + this.batchId = batchId; + return this; + } + + public long batchId() { + return batchId; + } + + public ReportResource setId(int id) { + this.id = id; + return this; + } + + public int id() { + return id; + } + + public ReportResource setSnapshotId(int snapshotId) { + this.snapshotId = snapshotId; + return this; + } + + public int snapshotId() { + return snapshotId; + } + + public ReportResource setPath(String path) { + this.path = path; + return this; + } + + public String path() { + return path; + } + + public ReportResource setName(String name) { + this.name = name; + return this; + } + + public String name() { + return name; + } + + public ReportResource setType(Type type) { + this.type = type; + return this; + } + + public Type type() { + return type; + } + + public ReportResource addChild(ReportResource child) { + this.children.add(child); + return this; + } + + public Collection<ReportResource> children() { + return children; + } + +} diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/ReportResources.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/ReportResources.java new file mode 100644 index 00000000000..e78e41c14d8 --- /dev/null +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/ReportResources.java @@ -0,0 +1,57 @@ +/* + * 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.batch.protocol.output.resource; + +import org.sonar.batch.protocol.GsonHelper; + +import java.util.Date; + +public class ReportResources { + + private Date analysisDate; + + private ReportResource root; + + public void setAnalysisDate(Date analysisDate) { + this.analysisDate = analysisDate; + } + + public Date analysisDate() { + return analysisDate; + } + + public ReportResources setRoot(ReportResource r) { + this.root = r; + return this; + } + + public ReportResource root() { + return root; + } + + public String toJson() { + return GsonHelper.create().toJson(this); + } + + public static ReportResources fromJson(String json) { + return GsonHelper.create().fromJson(json, ReportResources.class); + } + +} diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/package-info.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/package-info.java new file mode 100644 index 00000000000..5e45e2dee7a --- /dev/null +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/output/resource/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.batch.protocol.output.resource; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java index 8d55f4054dc..316d59acc31 100644 --- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java @@ -51,6 +51,7 @@ public class ProjectReferentialsTest { ref.setLastAnalysisDate(new SimpleDateFormat("dd/MM/yyyy").parse("31/10/2014")); ref.setTimestamp(10); ref.addFileData("foo", "src/main/java/Foo.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin")); + ref.addFileData("foo", "src/main/java/Foo2.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin")); System.out.println(ref.toJson()); JSONAssert @@ -59,7 +60,8 @@ public class ProjectReferentialsTest { + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"1984-03-14T00:00:00+0100\"}}," + "activeRules:[{repositoryKey:repo,ruleKey:rule,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,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}," + + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}," + + "\"src/main/java/Foo2.java\":{hash:xyz,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); } @@ -91,6 +93,8 @@ public class ProjectReferentialsTest { assertThat(qProfile.rulesUpdatedAt()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984")); assertThat(ref.settings("foo")).includes(MapAssert.entry("prop", "value")); + assertThat(ref.fileData("foo2", "src/main/java/Foo3.java")).isNull(); + assertThat(ref.fileData("foo", "src/main/java/Foo.java").hash()).isEqualTo("xyz"); assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmAuthorsByLine()).isEqualTo("1=henryju,2=gaudin"); assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmLastCommitDatetimesByLine()).isEqualTo("1=12345,2=3456"); diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/issue/ReportIssueTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/issue/ReportIssueTest.java new file mode 100644 index 00000000000..06edbf1ab8d --- /dev/null +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/issue/ReportIssueTest.java @@ -0,0 +1,86 @@ +/* + * 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.batch.protocol.output.issue; + +import org.junit.Test; + +import java.text.SimpleDateFormat; + +import static org.fest.assertions.Assertions.assertThat; + +public class ReportIssueTest { + + @Test + public void testGetterSetter() throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + ReportIssue issue = new ReportIssue() + .setActionPlanKey("plan") + .setAssignee("assignee") + .setAuthorLogin("author") + .setChanged(true) + .setChecksum("checksum") + .setDebt(3L) + .setDiffFields("diff") + .setEffortToFix(2.0) + .setAttributes("attributes") + .setCloseDate(sdf.parse("11/12/2012")) + .setCreationDate(sdf.parse("12/12/2012")) + .setUpdateDate(sdf.parse("13/12/2012")) + .setKey("key") + .setLine(3) + .setManualSeverity(true) + .setMessage("message") + .setNew(true) + .setReporter("reporter") + .setResolution("resolution") + .setResourceBatchId(4L) + .setRuleKey("repo", "rule") + .setSelectedAt(234L) + .setSeverity("severity") + .setStatus("status"); + + assertThat(issue.actionPlanKey()).isEqualTo("plan"); + assertThat(issue.assignee()).isEqualTo("assignee"); + assertThat(issue.authorLogin()).isEqualTo("author"); + assertThat(issue.isChanged()).isTrue(); + assertThat(issue.checksum()).isEqualTo("checksum"); + assertThat(issue.debt()).isEqualTo(3L); + assertThat(issue.diffFields()).isEqualTo("diff"); + assertThat(issue.effortToFix()).isEqualTo(2.0); + assertThat(issue.issueAttributes()).isEqualTo("attributes"); + assertThat(issue.closeDate()).isEqualTo(sdf.parse("11/12/2012")); + assertThat(issue.creationDate()).isEqualTo(sdf.parse("12/12/2012")); + assertThat(issue.updateDate()).isEqualTo(sdf.parse("13/12/2012")); + assertThat(issue.key()).isEqualTo("key"); + assertThat(issue.line()).isEqualTo(3); + assertThat(issue.isManualSeverity()).isTrue(); + assertThat(issue.message()).isEqualTo("message"); + assertThat(issue.isNew()).isTrue(); + assertThat(issue.reporter()).isEqualTo("reporter"); + assertThat(issue.resolution()).isEqualTo("resolution"); + assertThat(issue.resourceBatchId()).isEqualTo(4L); + assertThat(issue.ruleRepo()).isEqualTo("repo"); + assertThat(issue.ruleKey()).isEqualTo("rule"); + assertThat(issue.selectedAt()).isEqualTo(234L); + assertThat(issue.severity()).isEqualTo("severity"); + assertThat(issue.status()).isEqualTo("status"); + } + +} diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/resource/ReportResourcesTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/resource/ReportResourcesTest.java new file mode 100644 index 00000000000..d48d3ccc76d --- /dev/null +++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/output/resource/ReportResourcesTest.java @@ -0,0 +1,94 @@ +/* + * 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.batch.protocol.output.resource; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.sonar.batch.protocol.output.resource.ReportResource.Type; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import static org.fest.assertions.Assertions.assertThat; + +public class ReportResourcesTest { + + @Test + public void to_json() throws Exception { + ReportResources res = new ReportResources(); + Date d = new SimpleDateFormat("dd/MM/yyyy").parse("12/12/2012"); + res.setAnalysisDate(d); + ReportResource root = new ReportResource() + .setBatchId(1) + .setId(11) + .setName("Root project") + .setSnapshotId(111) + .setType(Type.PRJ); + ReportResource module = new ReportResource() + .setBatchId(2) + .setId(22) + .setName("Module") + .setSnapshotId(222) + .setPath("module1") + .setType(Type.MOD); + root.addChild(module); + ReportResource dir = new ReportResource() + .setBatchId(3) + .setId(33) + .setName("src") + .setSnapshotId(333) + .setPath("src") + .setType(Type.DIR); + module.addChild(dir); + ReportResource file = new ReportResource() + .setBatchId(4) + .setId(44) + .setName("Foo.java") + .setSnapshotId(444) + .setPath("Foo.java") + .setType(Type.FIL); + dir.addChild(file); + res.setRoot(root); + + JSONAssert + .assertEquals( + IOUtils.toString(this.getClass().getResourceAsStream("ReportResourceTest/expected.json"), "UTF-8"), + res.toJson(), true); + } + + @Test + public void from_json() throws Exception { + ReportResources res = ReportResources + .fromJson( + IOUtils.toString(this.getClass().getResourceAsStream("ReportResourceTest/expected.json"), "UTF-8")); + + assertThat(res.analysisDate()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("12/12/2012")); + ReportResource root = res.root(); + assertThat(root.batchId()).isEqualTo(1); + assertThat(root.id()).isEqualTo(11); + assertThat(root.name()).isEqualTo("Root project"); + assertThat(root.snapshotId()).isEqualTo(111); + assertThat(root.path()).isNull(); + assertThat(root.type()).isEqualTo(Type.PRJ); + assertThat(root.children()).hasSize(1); + + } +} diff --git a/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/output/resource/ReportResourceTest/expected.json b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/output/resource/ReportResourceTest/expected.json new file mode 100644 index 00000000000..4c642a06ba0 --- /dev/null +++ b/sonar-batch-protocol/src/test/resources/org/sonar/batch/protocol/output/resource/ReportResourceTest/expected.json @@ -0,0 +1,41 @@ +{ + "analysisDate": "2012-12-12T00:00:00+0100", + "root": { + "batchId": 1, + "id": 11, + "snapshotId": 111, + "name": "Root project", + "type": "PRJ", + "children": [ + { + "batchId": 2, + "id": 22, + "snapshotId": 222, + "path": "module1", + "name": "Module", + "type": "MOD", + "children": [ + { + "batchId": 3, + "id": 33, + "snapshotId": 333, + "path": "src", + "name": "src", + "type": "DIR", + "children": [ + { + "batchId": 4, + "id": 44, + "snapshotId": 444, + "path": "Foo.java", + "name": "Foo.java", + "type": "FIL", + "children": [] + } + ] + } + ] + } + ] + } +}
\ No newline at end of file |