From 4b8e398f903d3daa69b35c1e10c0c67a5852c2f0 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 26 Jul 2016 16:03:49 +0200 Subject: [PATCH] SONAR-7917 Fix WidgetDao --- .../org/sonar/db/dashboard/WidgetMapper.xml | 4 +-- .../org/sonar/db/dashboard/WidgetDaoTest.java | 28 ++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/sonar-db/src/main/resources/org/sonar/db/dashboard/WidgetMapper.xml b/sonar-db/src/main/resources/org/sonar/db/dashboard/WidgetMapper.xml index d77042a1d07..a631f84b6a7 100644 --- a/sonar-db/src/main/resources/org/sonar/db/dashboard/WidgetMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/dashboard/WidgetMapper.xml @@ -17,13 +17,13 @@ w.resource_id as "resourceId" - select from widgets w where w.id=#{id} - select from widgets w where w.dashboard_id=#{id} diff --git a/sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java b/sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java index 569235c609f..813e3272353 100644 --- a/sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/dashboard/WidgetDaoTest.java @@ -23,6 +23,7 @@ import java.util.Collection; import org.junit.Rule; import org.junit.Test; import org.sonar.api.utils.System2; +import org.sonar.db.DbSession; import org.sonar.db.DbTester; import static org.assertj.core.api.Assertions.assertThat; @@ -30,15 +31,16 @@ import static org.assertj.core.api.Assertions.assertThat; public class WidgetDaoTest { @Rule - public DbTester dbTester = DbTester.create(System2.INSTANCE); + public DbTester db = DbTester.create(System2.INSTANCE); + DbSession dbSession = db.getSession(); - WidgetDao dao = dbTester.getDbClient().widgetDao(); + WidgetDao underTest = db.getDbClient().widgetDao(); @Test public void should_select_all() { - dbTester.prepareDbUnit(this.getClass(), "before.xml"); + db.prepareDbUnit(this.getClass(), "before.xml"); - Collection widgets = dao.findAll(dbTester.getSession()); + Collection widgets = underTest.findAll(db.getSession()); assertThat(widgets).hasSize(5); for (WidgetDto widget : widgets) { assertThat(widget.getId()).isNotNull(); @@ -46,4 +48,22 @@ public class WidgetDaoTest { assertThat(widget.getDescription()).isNotNull(); } } + + @Test + public void select_by_dashboard_key() { + db.prepareDbUnit(this.getClass(), "before.xml"); + + Collection result = underTest.findByDashboard(dbSession, 1L); + + assertThat(result).hasSize(5); + } + + @Test + public void select_by_key() { + db.prepareDbUnit(this.getClass(), "before.xml"); + + WidgetDto result = underTest.selectByKey(dbSession, 1L); + + assertThat(result).isNotNull(); + } } -- 2.39.5