2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 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.
21 package org.sonar.plugins.core.issue;
23 import java.util.Collections;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.ClassRule;
27 import org.junit.Test;
28 import org.junit.rules.TemporaryFolder;
29 import org.sonar.api.CoreProperties;
30 import org.sonar.batch.bootstrap.BootstrapProperties;
31 import org.sonar.batch.bootstrap.BootstrapSettings;
32 import org.sonar.batch.bootstrap.TempFolderProvider;
33 import org.sonar.batch.index.Caches;
34 import org.sonar.core.issue.db.IssueChangeDto;
35 import org.sonar.core.issue.db.IssueDto;
37 import java.io.IOException;
38 import java.util.List;
40 import static org.fest.assertions.Assertions.assertThat;
42 public class InitialOpenIssuesStackTest {
45 public static TemporaryFolder temp = new TemporaryFolder();
47 public static Caches createCacheOnTemp(TemporaryFolder temp) {
48 BootstrapSettings bootstrapSettings = new BootstrapSettings(
49 new BootstrapProperties(Collections.<String,String>emptyMap())
52 bootstrapSettings.properties().put(CoreProperties.WORKING_DIRECTORY, temp.newFolder().getAbsolutePath());
53 } catch (IOException e) {
54 throw new RuntimeException(e);
56 return new Caches(new TempFolderProvider().provide(bootstrapSettings));
59 InitialOpenIssuesStack stack;
63 public void setUp() throws Exception {
64 caches = createCacheOnTemp(temp);
66 stack = new InitialOpenIssuesStack(caches);
70 public void tearDown() {
75 public void get_and_remove_issues() {
76 IssueDto issueDto = new IssueDto().setComponentKey_unit_test_only("org.struts.Action").setKee("ISSUE-1");
77 stack.addIssue(issueDto);
79 List<IssueDto> issueDtos = stack.selectAndRemoveIssues("org.struts.Action");
80 assertThat(issueDtos).hasSize(1);
81 assertThat(issueDtos.get(0).getKee()).isEqualTo("ISSUE-1");
83 assertThat(stack.selectAllIssues()).isEmpty();
87 public void get_and_remove_with_many_issues_on_same_resource() {
88 stack.addIssue(new IssueDto().setComponentKey_unit_test_only("org.struts.Action").setKee("ISSUE-1"));
89 stack.addIssue(new IssueDto().setComponentKey_unit_test_only("org.struts.Action").setKee("ISSUE-2"));
91 List<IssueDto> issueDtos = stack.selectAndRemoveIssues("org.struts.Action");
92 assertThat(issueDtos).hasSize(2);
94 assertThat(stack.selectAllIssues()).isEmpty();
98 public void get_and_remove_do_nothing_if_resource_not_found() {
99 stack.addIssue(new IssueDto().setComponentKey_unit_test_only("org.struts.Action").setKee("ISSUE-1"));
101 List<IssueDto> issueDtos = stack.selectAndRemoveIssues("Other");
102 assertThat(issueDtos).hasSize(0);
104 assertThat(stack.selectAllIssues()).hasSize(1);
108 public void select_changelog() {
109 stack.addChangelog(new IssueChangeDto().setKey("CHANGE-1").setIssueKey("ISSUE-1"));
110 stack.addChangelog(new IssueChangeDto().setKey("CHANGE-2").setIssueKey("ISSUE-1"));
112 List<IssueChangeDto> issueChangeDtos = stack.selectChangelog("ISSUE-1");
113 assertThat(issueChangeDtos).hasSize(2);
114 assertThat(issueChangeDtos.get(0).getKey()).isEqualTo("CHANGE-1");
115 assertThat(issueChangeDtos.get(1).getKey()).isEqualTo("CHANGE-2");
119 public void return_empty_changelog() {
120 assertThat(stack.selectChangelog("ISSUE-1")).isEmpty();
124 public void clear_issues() {
125 stack.addIssue(new IssueDto().setComponentKey_unit_test_only("org.struts.Action").setKee("ISSUE-1"));
127 assertThat(stack.selectAllIssues()).hasSize(1);
129 // issues are not removed
130 assertThat(stack.selectAllIssues()).hasSize(1);
133 assertThat(stack.selectAllIssues()).isEmpty();
137 public void clear_issues_changelog() {
138 stack.addChangelog(new IssueChangeDto().setKey("CHANGE-1").setIssueKey("ISSUE-1"));
140 assertThat(stack.selectChangelog("ISSUE-1")).hasSize(1);
143 assertThat(stack.selectChangelog("ISSUE-1")).isEmpty();