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.Arrays;
29 import java.util.Iterator;
31 import static org.assertj.core.api.Assertions.assertThat;
33 public class PreviousIssueHelperTest {
36 public void writeIssues() throws JSONException {
37 PreviousIssueHelper helper = PreviousIssueHelper.create();
38 StringWriter out = new StringWriter();
40 PreviousIssue issue1 = new PreviousIssue();
41 issue1.setKey("key1");
42 issue1.setComponentPath("path");
43 issue1.setRuleKey("repokey", "rulekey");
45 issue1.setMessage("message");
46 issue1.setSeverity("severity");
47 issue1.setResolution("resolution");
48 issue1.setStatus("status");
49 issue1.setChecksum("checksum");
50 issue1.setAssigneeLogin("login");
51 issue1.setAssigneeFullname("fullname");
52 PreviousIssue issue2 = new PreviousIssue();
53 issue2.setKey("key2");
55 helper.streamIssues(out, Arrays.asList(issue1, issue2), new PreviousIssueHelper.Function<PreviousIssue, PreviousIssue>() {
57 public PreviousIssue apply(PreviousIssue from) {
64 "[{\"key\": \"key1\", \"componentPath\": \"path\", \"ruleKey\": \"rulekey\", \"ruleRepo\": \"repokey\", \"line\": 2,\"message\": \"message\", \"severity\": \"severity\", \"resolution\": \"resolution\", \"status\": \"status\", \"checksum\": \"checksum\",\"assigneeLogin\": \"login\", \"assigneeFullname\": \"fullname\"},"
66 "{\"key\": \"key2\"}]",
67 out.getBuffer().toString(), true);
71 public void readIssues() {
72 PreviousIssueHelper helper = PreviousIssueHelper.create();
73 StringReader reader = new StringReader(
74 "[{\"key\": \"key1\", \"componentPath\": \"path\", \"ruleKey\": \"rulekey\", \"ruleRepo\": \"repokey\", \"line\": 2,\"message\": \"message\", \"severity\": \"severity\", \"resolution\": \"resolution\", \"status\": \"status\", \"checksum\": \"checksum\",\"assigneeLogin\": \"login\", \"assigneeFullname\": \"fullname\"},"
76 "{\"key\": \"key2\"}]");
78 Iterator<PreviousIssue> iterator = helper.getIssues(reader).iterator();
79 PreviousIssue issue1 = iterator.next();
80 assertThat(iterator.hasNext()).isTrue();
81 PreviousIssue issue2 = iterator.next();
82 assertThat(iterator.hasNext()).isFalse();
84 assertThat(issue1.key()).isEqualTo("key1");
85 assertThat(issue1.componentPath()).isEqualTo("path");
86 assertThat(issue1.ruleRepo()).isEqualTo("repokey");
87 assertThat(issue1.ruleKey()).isEqualTo("rulekey");
88 assertThat(issue1.line()).isEqualTo(2);
89 assertThat(issue1.message()).isEqualTo("message");
90 assertThat(issue1.severity()).isEqualTo("severity");
91 assertThat(issue1.resolution()).isEqualTo("resolution");
92 assertThat(issue1.status()).isEqualTo("status");
93 assertThat(issue1.checksum()).isEqualTo("checksum");
94 assertThat(issue1.assigneeLogin()).isEqualTo("login");
95 assertThat(issue1.assigneeFullname()).isEqualTo("fullname");
97 assertThat(issue2.key()).isEqualTo("key2");