]> source.dussan.org Git - sonarqube.git/blob
2081d92c49986a994da5304152605263489c7d20
[sonarqube.git] /
1 /*
2  * Sonar, open source software quality management tool.
3  * Copyright (C) 2008-2012 SonarSource
4  * mailto:contact AT sonarsource DOT com
5  *
6  * Sonar 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  * Sonar 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
17  * License along with Sonar; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
19  */
20 package org.sonar.plugins.core.dashboards;
21
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.sonar.api.web.Dashboard;
25 import org.sonar.api.web.Dashboard.Widget;
26 import org.sonar.core.measure.MeasureFilterDao;
27 import org.sonar.core.measure.MeasureFilterDto;
28 import org.sonar.plugins.core.CorePlugin;
29 import org.sonar.plugins.core.filters.MyFavouritesFilter;
30 import org.sonar.plugins.core.filters.ProjectFilter;
31 import org.sonar.plugins.core.widgets.MeasureFilterListWidget;
32 import org.sonar.plugins.core.widgets.MeasureFilterTreemapWidget;
33 import org.sonar.plugins.core.widgets.WelcomeWidget;
34
35 import java.util.List;
36
37 import static org.fest.assertions.Assertions.assertThat;
38 import static org.mockito.Mockito.mock;
39 import static org.mockito.Mockito.when;
40
41 public class GlobalDefaultDashboardTest {
42   GlobalDefaultDashboard template;
43   MeasureFilterDao dao;
44
45   @Before
46   public void init() {
47     dao = mock(MeasureFilterDao.class);
48     template = new GlobalDefaultDashboard(dao);
49   }
50
51   @Test
52   public void should_have_a_name() {
53     assertThat(template.getName()).isEqualTo("Home");
54   }
55
56   @Test
57   public void should_be_registered_as_an_extension() {
58     assertThat(new CorePlugin().getExtensions()).contains(template.getClass());
59   }
60
61   @Test
62   public void should_create_global_dashboard_with_four_widgets() {
63     when(dao.findSystemFilterByName(MyFavouritesFilter.NAME)).thenReturn(
64         new MeasureFilterDto().setId(100L)
65         );
66     when(dao.findSystemFilterByName(ProjectFilter.NAME)).thenReturn(
67         new MeasureFilterDto().setId(101L)
68         );
69     Dashboard dashboard = template.createDashboard();
70     List<Widget> firstColumn = dashboard.getWidgetsOfColumn(1);
71     assertThat(firstColumn).hasSize(2);
72     assertThat(firstColumn.get(0).getId()).isEqualTo(WelcomeWidget.ID);
73     assertThat(firstColumn.get(1).getId()).isEqualTo(MeasureFilterListWidget.ID);
74     assertThat(firstColumn.get(1).getProperty("filter")).isEqualTo("100");
75
76     List<Widget> secondColumn = dashboard.getWidgetsOfColumn(2);
77     assertThat(secondColumn).hasSize(2);
78     assertThat(secondColumn.get(0).getId()).isEqualTo(MeasureFilterListWidget.ID);
79     assertThat(secondColumn.get(0).getProperty("filter")).isEqualTo("101");
80     assertThat(secondColumn.get(1).getId()).isEqualTo(MeasureFilterTreemapWidget.ID);
81     assertThat(secondColumn.get(1).getProperty("filter")).isEqualTo("101");
82   }
83 }