aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test/java/org/sonar/server/issue/DefaultJRubyIssuesTest.java
blob: e8446364eb96818482867a9b1a77245771e961e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Sonar, open source software quality management tool.
 * Copyright (C) 2008-2012 SonarSource
 * mailto:contact AT sonarsource DOT com
 *
 * Sonar is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * Sonar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sonar; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 */
package org.sonar.server.issue;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.sonar.api.issue.IssueFinder;
import org.sonar.api.issue.IssueQuery;
import org.sonar.api.utils.DateUtils;

import java.util.Map;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;

public class DefaultJRubyIssuesTest {

  IssueFinder finder = mock(IssueFinder.class);
  DefaultJRubyIssues facade = new DefaultJRubyIssues(finder);

  @Test
  public void test_find() throws Exception {
    facade.find(ImmutableMap.<String, Object>of("keys", Lists.newArrayList("ABCDE")), 123);
    verify(finder).find(argThat(new ArgumentMatcher<IssueQuery>() {
      @Override
      public boolean matches(Object o) {
        return ((IssueQuery) o).keys().contains("ABCDE");
      }
    }), eq(123));
  }

  @Test
  public void should_create_query_from_parameters() {
    Map<String, Object> map = newHashMap();
    map.put("keys", newArrayList("ABCDE1234"));
    map.put("severities", newArrayList("MAJOR", "MINOR"));
    map.put("statuses", newArrayList("CLOSED"));
    map.put("resolutions", newArrayList("FALSE-POSITIVE"));
    map.put("components", newArrayList("org.apache"));
    map.put("userLogins", newArrayList("marilyn"));
    map.put("assigneeLogins", newArrayList("joanna"));
    map.put("createdAfter", "2013-04-16T09:08:24+0200");
    map.put("createdBefore", "2013-04-17T09:08:24+0200");
    map.put("rule", "rule");
    map.put("ruleRepository", "ruleRepository");
    map.put("limit", 10);
    map.put("offset", 50);

    IssueQuery query = new DefaultJRubyIssues(finder).newQuery(map);
    assertThat(query.keys()).containsOnly("ABCDE1234");
    assertThat(query.severities()).containsExactly("MAJOR", "MINOR");
    assertThat(query.statuses()).containsOnly("CLOSED");
    assertThat(query.resolutions()).containsOnly("FALSE-POSITIVE");
    assertThat(query.userLogins()).containsOnly("marilyn");
    assertThat(query.assigneeLogins()).containsOnly("joanna");
    assertThat(query.rule()).isEqualTo("rule");
    assertThat(query.ruleRepository()).isEqualTo("ruleRepository");
    assertThat(query.createdAfter()).isEqualTo(DateUtils.parseDateTime("2013-04-16T09:08:24+0200"));
    assertThat(query.createdBefore()).isEqualTo(DateUtils.parseDateTime("2013-04-17T09:08:24+0200"));
    assertThat(query.limit()).isEqualTo(10);
    assertThat(query.offset()).isEqualTo(50);
  }

  @Test
  public void should_start() throws Exception {
    facade.start();
    // nothing is done
    verifyZeroInteractions(finder);
  }
}