]> source.dussan.org Git - sonarqube.git/blob
8719db821f80bf7fa3323e83f304e8957a75b088
[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.Arrays;
29 import java.util.Iterator;
30
31 import static org.assertj.core.api.Assertions.assertThat;
32
33 public class PreviousIssueHelperTest {
34
35   @Test
36   public void writeIssues() throws JSONException {
37     PreviousIssueHelper helper = PreviousIssueHelper.create();
38     StringWriter out = new StringWriter();
39
40     PreviousIssue issue1 = new PreviousIssue();
41     issue1.setKey("key1");
42     issue1.setComponentPath("path");
43     issue1.setRuleKey("repokey", "rulekey");
44     issue1.setLine(2);
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");
54
55     helper.streamIssues(out, Arrays.asList(issue1, issue2), new PreviousIssueHelper.Function<PreviousIssue, PreviousIssue>() {
56       @Override
57       public PreviousIssue apply(PreviousIssue from) {
58         return from;
59       }
60     });
61
62     JSONAssert
63       .assertEquals(
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\"},"
65           +
66           "{\"key\": \"key2\"}]",
67         out.getBuffer().toString(), true);
68   }
69
70   @Test
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\"},"
75         +
76         "{\"key\": \"key2\"}]");
77
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();
83
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");
96
97     assertThat(issue2.key()).isEqualTo("key2");
98   }
99
100 }