]> source.dussan.org Git - sonarqube.git/blob
1e5264b4ad29193a0f4928994ff7acba3879d79f
[sonarqube.git] /
1 /*
2  * SonarQube, open source software quality management tool.
3  * Copyright (C) 2008-2014 SonarSource
4  * mailto:contact AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.batch.protocol.input.issues;
21
22 import org.json.JSONException;
23 import org.junit.Test;
24 import org.skyscreamer.jsonassert.JSONAssert;
25
26 import java.io.StringReader;
27 import java.io.StringWriter;
28 import java.util.Iterator;
29
30 import static org.assertj.core.api.Assertions.assertThat;
31
32 public class PreviousIssueHelperTest {
33
34   @Test
35   public void writeIssues() throws JSONException {
36     StringWriter out = new StringWriter();
37     PreviousIssueHelper helper = PreviousIssueHelper.create(out);
38
39     PreviousIssue issue1 = new PreviousIssue();
40     issue1.setKey("key1");
41     issue1.setComponentPath("path");
42     issue1.setRuleKey("repokey", "rulekey");
43     issue1.setLine(2);
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");
53
54     PreviousIssueFunction previousIssueFunction = new PreviousIssueFunction();
55     helper.addIssue(issue1, previousIssueFunction);
56     helper.addIssue(issue2, previousIssueFunction);
57     helper.close();
58
59     JSONAssert
60       .assertEquals(
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\"},"
62           +
63           "{\"key\": \"key2\"}]",
64         out.getBuffer().toString(), true);
65
66   }
67
68   private static class PreviousIssueFunction implements PreviousIssueHelper.Function<PreviousIssue, PreviousIssue> {
69     @Override
70     public PreviousIssue apply(PreviousIssue from) {
71       return from;
72     }
73   }
74
75   @Test
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\"},"
81         +
82         "{\"key\": \"key2\"}]");
83
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();
89
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");
102
103     assertThat(issue2.key()).isEqualTo("key2");
104     helper.close();
105   }
106
107 }