2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.batch.protocol.input.issues;
22 import org.json.JSONException;
23 import org.junit.Test;
24 import org.skyscreamer.jsonassert.JSONAssert;
26 import java.io.StringReader;
27 import java.io.StringWriter;
28 import java.util.Iterator;
30 import static org.assertj.core.api.Assertions.assertThat;
32 public class PreviousIssueHelperTest {
35 public void writeIssues() throws JSONException {
36 StringWriter out = new StringWriter();
37 PreviousIssueHelper helper = PreviousIssueHelper.create(out);
39 PreviousIssue issue1 = new PreviousIssue();
40 issue1.setKey("key1");
41 issue1.setComponentPath("path");
42 issue1.setRuleKey("repokey", "rulekey");
44 issue1.setMessage("message");
45 issue1.setSeverity("severity");
46 issue1.setResolution("resolution");
47 issue1.setStatus("status");
48 issue1.setChecksum("checksum");
49 issue1.setAssigneeLogin("login");
50 issue1.setAssigneeFullname("fullname");
51 PreviousIssue issue2 = new PreviousIssue();
52 issue2.setKey("key2");
54 PreviousIssueFunction previousIssueFunction = new PreviousIssueFunction();
55 helper.addIssue(issue1, previousIssueFunction);
56 helper.addIssue(issue2, previousIssueFunction);
61 "[{\"key\": \"key1\", \"componentPath\": \"path\", \"ruleKey\": \"rulekey\", \"ruleRepo\": \"repokey\", \"line\": 2,\"message\": \"message\", \"severity\": \"severity\", \"resolution\": \"resolution\", \"status\": \"status\", \"checksum\": \"checksum\",\"assigneeLogin\": \"login\", \"assigneeFullname\": \"fullname\"},"
63 "{\"key\": \"key2\"}]",
64 out.getBuffer().toString(), true);
68 private static class PreviousIssueFunction implements PreviousIssueHelper.Function<PreviousIssue, PreviousIssue> {
70 public PreviousIssue apply(PreviousIssue from) {
76 public void readIssues() {
77 StringWriter out = new StringWriter();
78 PreviousIssueHelper helper = PreviousIssueHelper.create(out);
79 StringReader reader = new StringReader(
80 "[{\"key\": \"key1\", \"componentPath\": \"path\", \"ruleKey\": \"rulekey\", \"ruleRepo\": \"repokey\", \"line\": 2,\"message\": \"message\", \"severity\": \"severity\", \"resolution\": \"resolution\", \"status\": \"status\", \"checksum\": \"checksum\",\"assigneeLogin\": \"login\", \"assigneeFullname\": \"fullname\"},"
82 "{\"key\": \"key2\"}]");
84 Iterator<PreviousIssue> iterator = helper.getIssues(reader).iterator();
85 PreviousIssue issue1 = iterator.next();
86 assertThat(iterator.hasNext()).isTrue();
87 PreviousIssue issue2 = iterator.next();
88 assertThat(iterator.hasNext()).isFalse();
90 assertThat(issue1.key()).isEqualTo("key1");
91 assertThat(issue1.componentPath()).isEqualTo("path");
92 assertThat(issue1.ruleRepo()).isEqualTo("repokey");
93 assertThat(issue1.ruleKey()).isEqualTo("rulekey");
94 assertThat(issue1.line()).isEqualTo(2);
95 assertThat(issue1.message()).isEqualTo("message");
96 assertThat(issue1.severity()).isEqualTo("severity");
97 assertThat(issue1.resolution()).isEqualTo("resolution");
98 assertThat(issue1.status()).isEqualTo("status");
99 assertThat(issue1.checksum()).isEqualTo("checksum");
100 assertThat(issue1.assigneeLogin()).isEqualTo("login");
101 assertThat(issue1.assigneeFullname()).isEqualTo("fullname");
103 assertThat(issue2.key()).isEqualTo("key2");