diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2011-12-14 16:45:32 +0100 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2011-12-14 16:45:32 +0100 |
commit | 7979e9dbfe01931c771f9fd8d13bc8a65cbb49d7 (patch) | |
tree | d0a999fb0f3b832f907b73bc305421a0c7db5c0d /sonar-server/src/test | |
parent | 9179fbeead620330cdaa5a8ab6291c893d95c571 (diff) | |
download | sonarqube-7979e9dbfe01931c771f9fd8d13bc8a65cbb49d7.tar.gz sonarqube-7979e9dbfe01931c771f9fd8d13bc8a65cbb49d7.zip |
Sonar Persistence API refactoring
- Class mapped to tables should now be named "MyTableDto"
- DTOs, DAOs and Mappers of a same concern should be packed in a
single package, allowing to use package visibility amongst them.
=> org.sonar.persistence has been reorganized following those rules.
Diffstat (limited to 'sonar-server/src/test')
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/startup/RegisterProvidedDashboardsTest.java | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterProvidedDashboardsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterProvidedDashboardsTest.java index 6973393972b..52919c27447 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterProvidedDashboardsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterProvidedDashboardsTest.java @@ -39,12 +39,12 @@ import org.junit.Test; import org.sonar.api.web.dashboard.Dashboard; import org.sonar.api.web.dashboard.DashboardTemplate; import org.sonar.core.i18n.I18nManager; -import org.sonar.persistence.dao.ActiveDashboardDao; -import org.sonar.persistence.dao.DashboardDao; -import org.sonar.persistence.dao.LoadedTemplateDao; -import org.sonar.persistence.model.ActiveDashboard; -import org.sonar.persistence.model.LoadedTemplate; -import org.sonar.persistence.model.Widget; +import org.sonar.persistence.dashboard.ActiveDashboardDao; +import org.sonar.persistence.dashboard.ActiveDashboardDto; +import org.sonar.persistence.dashboard.DashboardDao; +import org.sonar.persistence.dashboard.WidgetDto; +import org.sonar.persistence.template.LoadedTemplateDto; +import org.sonar.persistence.template.LoadedTemplateDao; import com.google.common.collect.Lists; @@ -75,14 +75,14 @@ public class RegisterProvidedDashboardsTest { @Test public void testStart() throws Exception { registerProvidedDashboards.start(); - verify(dashboardDao).insert(any(org.sonar.persistence.model.Dashboard.class)); - verify(loadedTemplateDao).insert(any(LoadedTemplate.class)); - verify(activeDashboardDao).insert(any(ActiveDashboard.class)); + verify(dashboardDao).insert(any(org.sonar.persistence.dashboard.DashboardDto.class)); + verify(loadedTemplateDao).insert(any(LoadedTemplateDto.class)); + verify(activeDashboardDao).insert(any(ActiveDashboardDto.class)); } @Test public void testShouldNotBeLoaded() throws Exception { - when(loadedTemplateDao.selectByKeyAndType("fake-dashboard", LoadedTemplate.DASHBOARD_TYPE)).thenReturn(new LoadedTemplate()); + when(loadedTemplateDao.selectByKeyAndType("fake-dashboard", LoadedTemplateDto.DASHBOARD_TYPE)).thenReturn(new LoadedTemplateDto()); assertThat(registerProvidedDashboards.shouldBeLoaded(fakeDashboardTemplate.createDashboard()), is(false)); } @@ -93,16 +93,16 @@ public class RegisterProvidedDashboardsTest { @Test public void shouldLoadDasboard() throws Exception { - org.sonar.persistence.model.Dashboard dataModelDashboard = registerProvidedDashboards.loadDashboard(fakeDashboardTemplate + org.sonar.persistence.dashboard.DashboardDto dataModelDashboard = registerProvidedDashboards.loadDashboard(fakeDashboardTemplate .createDashboard()); assertNotNull(dataModelDashboard); verify(dashboardDao).insert(dataModelDashboard); - verify(loadedTemplateDao).insert(eq(new LoadedTemplate("fake-dashboard", LoadedTemplate.DASHBOARD_TYPE))); + verify(loadedTemplateDao).insert(eq(new LoadedTemplateDto("fake-dashboard", LoadedTemplateDto.DASHBOARD_TYPE))); } @Test public void shouldCreateDataModelFromExtension() { - org.sonar.persistence.model.Dashboard dataModelDashboard = registerProvidedDashboards + org.sonar.persistence.dashboard.DashboardDto dataModelDashboard = registerProvidedDashboards .createDataModelFromExtension(fakeDashboardTemplate.createDashboard()); assertThat(dataModelDashboard.getUserId(), is(nullValue())); assertThat(dataModelDashboard.getKey(), is("fake-dashboard")); @@ -113,52 +113,52 @@ public class RegisterProvidedDashboardsTest { assertNotNull(dataModelDashboard.getCreatedAt()); assertNotNull(dataModelDashboard.getUpdatedAt()); - Widget widget = dataModelDashboard.getWidgets().iterator().next(); - assertThat(widget.getKey(), is("fake-widget")); - assertThat(widget.getName(), is("Fake Widget")); - assertThat(widget.getDescription(), is(nullValue())); - assertThat(widget.getColumnIndex(), is(12)); - assertThat(widget.getRowIndex(), is(13)); - assertThat(widget.getConfigured(), is(true)); - assertNotNull(widget.getCreatedAt()); - assertNotNull(widget.getUpdatedAt()); - - org.sonar.persistence.model.WidgetProperty widgetProperty = widget.getWidgetProperties().iterator().next(); - assertThat(widgetProperty.getKey(), is("fake-property")); - assertThat(widgetProperty.getValue(), is("fake_metric")); + WidgetDto widgetDto = dataModelDashboard.getWidgets().iterator().next(); + assertThat(widgetDto.getKey(), is("fake-widget")); + assertThat(widgetDto.getName(), is("Fake Widget")); + assertThat(widgetDto.getDescription(), is(nullValue())); + assertThat(widgetDto.getColumnIndex(), is(12)); + assertThat(widgetDto.getRowIndex(), is(13)); + assertThat(widgetDto.getConfigured(), is(true)); + assertNotNull(widgetDto.getCreatedAt()); + assertNotNull(widgetDto.getUpdatedAt()); + + org.sonar.persistence.dashboard.WidgetPropertyDto widgetPropertyDto = widgetDto.getWidgetProperties().iterator().next(); + assertThat(widgetPropertyDto.getKey(), is("fake-property")); + assertThat(widgetPropertyDto.getValue(), is("fake_metric")); } @Test public void shouldCompareDashboardForSorting() throws Exception { - org.sonar.persistence.model.Dashboard d1 = mock(org.sonar.persistence.model.Dashboard.class); + org.sonar.persistence.dashboard.DashboardDto d1 = mock(org.sonar.persistence.dashboard.DashboardDto.class); when(d1.getName()).thenReturn("Foo"); - org.sonar.persistence.model.Dashboard d2 = mock(org.sonar.persistence.model.Dashboard.class); + org.sonar.persistence.dashboard.DashboardDto d2 = mock(org.sonar.persistence.dashboard.DashboardDto.class); when(d2.getName()).thenReturn("Bar"); - List<org.sonar.persistence.model.Dashboard> dashboards = Lists.newArrayList(d1, d2); - Collections.sort(dashboards, new RegisterProvidedDashboards.DashboardComparator()); + List<org.sonar.persistence.dashboard.DashboardDto> dashboardDtos = Lists.newArrayList(d1, d2); + Collections.sort(dashboardDtos, new RegisterProvidedDashboards.DashboardComparator()); - assertThat(dashboards.get(0).getName(), is("Bar")); + assertThat(dashboardDtos.get(0).getName(), is("Bar")); } @Test public void shouldActivateAllDashboards() throws Exception { - org.sonar.persistence.model.Dashboard d1 = mock(org.sonar.persistence.model.Dashboard.class); + org.sonar.persistence.dashboard.DashboardDto d1 = mock(org.sonar.persistence.dashboard.DashboardDto.class); when(d1.getName()).thenReturn("Foo"); when(d1.getId()).thenReturn(14L); - org.sonar.persistence.model.Dashboard d2 = mock(org.sonar.persistence.model.Dashboard.class); + org.sonar.persistence.dashboard.DashboardDto d2 = mock(org.sonar.persistence.dashboard.DashboardDto.class); when(d2.getName()).thenReturn("Bar"); when(d2.getId()).thenReturn(16L); - ArrayList<org.sonar.persistence.model.Dashboard> loadedDashboards = Lists.newArrayList(d1, d2); + ArrayList<org.sonar.persistence.dashboard.DashboardDto> loadedDashboards = Lists.newArrayList(d1, d2); when(activeDashboardDao.selectMaxOrderIndexForNullUser()).thenReturn(4); registerProvidedDashboards.activateDashboards(loadedDashboards, null); - ActiveDashboard ad1 = new ActiveDashboard(); + ActiveDashboardDto ad1 = new ActiveDashboardDto(); ad1.setDashboardId(16L); ad1.setOrderIndex(5); verify(activeDashboardDao).insert(eq(ad1)); - ActiveDashboard ad2 = new ActiveDashboard(); + ActiveDashboardDto ad2 = new ActiveDashboardDto(); ad2.setDashboardId(14L); ad2.setOrderIndex(6); verify(activeDashboardDao).insert(eq(ad2)); @@ -166,21 +166,21 @@ public class RegisterProvidedDashboardsTest { @Test public void shouldActivateMainDashboard() throws Exception { - org.sonar.persistence.model.Dashboard mainDashboard = mock(org.sonar.persistence.model.Dashboard.class); + org.sonar.persistence.dashboard.DashboardDto mainDashboard = mock(org.sonar.persistence.dashboard.DashboardDto.class); when(mainDashboard.getName()).thenReturn("Main"); when(mainDashboard.getId()).thenReturn(1L); - org.sonar.persistence.model.Dashboard d1 = mock(org.sonar.persistence.model.Dashboard.class); + org.sonar.persistence.dashboard.DashboardDto d1 = mock(org.sonar.persistence.dashboard.DashboardDto.class); when(d1.getName()).thenReturn("Bar"); when(d1.getId()).thenReturn(16L); - ArrayList<org.sonar.persistence.model.Dashboard> loadedDashboards = Lists.newArrayList(d1); + ArrayList<org.sonar.persistence.dashboard.DashboardDto> loadedDashboards = Lists.newArrayList(d1); registerProvidedDashboards.activateDashboards(loadedDashboards, mainDashboard); - ActiveDashboard ad1 = new ActiveDashboard(); + ActiveDashboardDto ad1 = new ActiveDashboardDto(); ad1.setDashboardId(1L); ad1.setOrderIndex(1); verify(activeDashboardDao).insert(eq(ad1)); - ActiveDashboard ad2 = new ActiveDashboard(); + ActiveDashboardDto ad2 = new ActiveDashboardDto(); ad2.setDashboardId(16L); ad2.setOrderIndex(2); verify(activeDashboardDao).insert(eq(ad2)); |