aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-05-07 16:23:01 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-05-07 16:23:11 +0200
commitf4073f2ccd796ca138e6ca19fe3e6d4c33cf6cc4 (patch)
tree32523a20f10d5e2edd91f18e963e74c49e7a34d6 /sonar-core/src/test
parent083d4a7e47a7f7cd958e69782b16c02d3c1d6c34 (diff)
downloadsonarqube-f4073f2ccd796ca138e6ca19fe3e6d4c33cf6cc4.tar.gz
sonarqube-f4073f2ccd796ca138e6ca19fe3e6d4c33cf6cc4.zip
SONAR-3755 Manage action plan management console with Java instead of Ruby
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/ActionPlanManagerTest.java (renamed from sonar-core/src/test/java/org/sonar/core/issue/ActionPlanFinderTest.java)52
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/ActionPlanDaoTest.java30
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_delete_action_plan-result.xml6
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_delete_action_plan.xml9
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_insert_new_action_plan-result.xml6
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_update_action_plan-result.xml6
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_update_action_plan.xml6
7 files changed, 101 insertions, 14 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/ActionPlanFinderTest.java b/sonar-core/src/test/java/org/sonar/core/issue/ActionPlanManagerTest.java
index 7ae39c5bf9d..59915d39df5 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/ActionPlanFinderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/ActionPlanManagerTest.java
@@ -36,25 +36,49 @@ import java.util.Collection;
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
-public class ActionPlanFinderTest {
+public class ActionPlanManagerTest {
private ActionPlanDao actionPlanDao = mock(ActionPlanDao.class);
private ActionPlanStatsDao actionPlanStatsDao = mock(ActionPlanStatsDao.class);
private ResourceDao resourceDao = mock(ResourceDao.class);
- private ActionPlanFinder actionPlanFinder;
+ private ActionPlanManager actionPlanManager;
@Before
public void before() {
- actionPlanFinder = new ActionPlanFinder(actionPlanDao, actionPlanStatsDao, resourceDao);
+ actionPlanManager = new ActionPlanManager(actionPlanDao, actionPlanStatsDao, resourceDao);
+ }
+
+ @Test
+ public void should_create() {
+ ActionPlan actionPlan = DefaultActionPlan.create("Long term");
+
+ actionPlanManager.create(actionPlan, 1);
+ verify(actionPlanDao).save(any(ActionPlanDto.class));
+ }
+
+ @Test
+ public void should_set_status() {
+ when(actionPlanDao.findByKey("ABCD")).thenReturn(new ActionPlanDto().setKey("ABCD"));
+
+ ActionPlan result = actionPlanManager.setStatus("ABCD", "CLOSED");
+ verify(actionPlanDao).update(any(ActionPlanDto.class));
+
+ assertThat(result).isNotNull();
+ assertThat(result.status()).isEqualTo("CLOSED");
+ }
+
+ @Test
+ public void should_delete() {
+ actionPlanManager.delete("ABCD");
+ verify(actionPlanDao).delete("ABCD");
}
@Test
public void should_find_by_key() {
when(actionPlanDao.findByKey("ABCD")).thenReturn(new ActionPlanDto().setKey("ABCD"));
- ActionPlan result = actionPlanFinder.findByKey("ABCD");
+ ActionPlan result = actionPlanManager.findByKey("ABCD");
assertThat(result).isNotNull();
assertThat(result.key()).isEqualTo("ABCD");
}
@@ -62,13 +86,13 @@ public class ActionPlanFinderTest {
@Test
public void should_return_null_if_no_action_plan_when_find_by_key() {
when(actionPlanDao.findByKey("ABCD")).thenReturn(null);
- assertThat(actionPlanFinder.findByKey("ABCD")).isNull();
+ assertThat(actionPlanManager.findByKey("ABCD")).isNull();
}
@Test
public void should_find_by_keys() {
when(actionPlanDao.findByKeys(newArrayList("ABCD"))).thenReturn(newArrayList(new ActionPlanDto().setKey("ABCD")));
- Collection<ActionPlan> results = actionPlanFinder.findByKeys(newArrayList("ABCD"));
+ Collection<ActionPlan> results = actionPlanManager.findByKeys(newArrayList("ABCD"));
assertThat(results).hasSize(1);
assertThat(results.iterator().next().key()).isEqualTo("ABCD");
}
@@ -77,7 +101,7 @@ public class ActionPlanFinderTest {
public void should_find_open_by_project_key() {
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
when(actionPlanDao.findOpenByProjectId(1l)).thenReturn(newArrayList(new ActionPlanDto().setKey("ABCD")));
- Collection<ActionPlan> results = actionPlanFinder.findOpenByProjectKey("org.sonar.Sample");
+ Collection<ActionPlan> results = actionPlanManager.findOpenByProjectKey("org.sonar.Sample");
assertThat(results).hasSize(1);
assertThat(results.iterator().next().key()).isEqualTo("ABCD");
}
@@ -85,7 +109,7 @@ public class ActionPlanFinderTest {
@Test(expected = IllegalArgumentException.class)
public void should_throw_exception_if_project_not_found_when_find_open_by_project_key() {
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(null);
- actionPlanFinder.findOpenByProjectKey("<Unkown>");
+ actionPlanManager.findOpenByProjectKey("<Unkown>");
}
@Test
@@ -93,7 +117,7 @@ public class ActionPlanFinderTest {
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setId(1L).setKey("org.sonar.Sample"));
when(actionPlanStatsDao.findOpenByProjectId(1L)).thenReturn(newArrayList(new ActionPlanStatsDto()));
- Collection<ActionPlanStats> results = actionPlanFinder.findOpenActionPlanStats("org.sonar.Sample");
+ Collection<ActionPlanStats> results = actionPlanManager.findOpenActionPlanStats("org.sonar.Sample");
assertThat(results).hasSize(1);
}
@@ -101,7 +125,7 @@ public class ActionPlanFinderTest {
public void should_throw_exception_if_project_not_found_when_find_open_action_plan_stats(){
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(null);
- actionPlanFinder.findOpenActionPlanStats("org.sonar.Sample");
+ actionPlanManager.findOpenActionPlanStats("org.sonar.Sample");
}
@Test
@@ -109,7 +133,7 @@ public class ActionPlanFinderTest {
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setId(1L).setKey("org.sonar.Sample"));
when(actionPlanStatsDao.findClosedByProjectId(1L)).thenReturn(newArrayList(new ActionPlanStatsDto()));
- Collection<ActionPlanStats> results = actionPlanFinder.findClosedActionPlanStats("org.sonar.Sample");
+ Collection<ActionPlanStats> results = actionPlanManager.findClosedActionPlanStats("org.sonar.Sample");
assertThat(results).hasSize(1);
}
@@ -117,7 +141,7 @@ public class ActionPlanFinderTest {
public void should_throw_exception_if_project_not_found_when_find_closed_action_plan_stats(){
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(null);
- actionPlanFinder.findClosedActionPlanStats("org.sonar.Sample");
+ actionPlanManager.findClosedActionPlanStats("org.sonar.Sample");
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/ActionPlanDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/ActionPlanDaoTest.java
index 53e2d0684ba..b21ebcbe4a5 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/ActionPlanDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/ActionPlanDaoTest.java
@@ -39,6 +39,36 @@ public class ActionPlanDaoTest extends AbstractDaoTestCase {
}
@Test
+ public void should_insert_new_action_plan() {
+ ActionPlanDto actionPlanDto = new ActionPlanDto().setKey("ABC").setName("Long term").setDescription("Long term action plan").setStatus("OPEN")
+ .setProjectId(1).setUserLogin("arthur");
+
+ dao.save(actionPlanDto);
+
+ checkTables("should_insert_new_action_plan", new String[]{"id", "created_at", "updated_at"}, "action_plans");
+ }
+
+ @Test
+ public void should_update_action_plan() {
+ setupData("should_update_action_plan");
+
+ ActionPlanDto actionPlanDto = new ActionPlanDto().setKey("ABC").setName("Long term").setDescription("Long term action plan").setStatus("OPEN")
+ .setProjectId(1).setUserLogin("arthur");
+ dao.update(actionPlanDto);
+
+ checkTables("should_update_action_plan", new String[]{"id", "created_at", "updated_at"}, "action_plans");
+ }
+
+ @Test
+ public void should_delete_action_plan() {
+ setupData("should_delete_action_plan");
+
+ dao.delete("BCD");
+
+ checkTables("should_delete_action_plan", new String[]{"id", "created_at", "updated_at"}, "action_plans");
+ }
+
+ @Test
public void should_find_by_key() {
setupData("should_find_by_key");
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_delete_action_plan-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_delete_action_plan-result.xml
new file mode 100644
index 00000000000..2e330ef5fe1
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_delete_action_plan-result.xml
@@ -0,0 +1,6 @@
+<dataset>
+
+ <action_plans id="1" kee="ABC" project_id="1" name="Long term" description="Long term action plan" deadline="[null]"
+ user_login="arthur" status="OPEN" created_at="[null]" updated_at="[null]" />
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_delete_action_plan.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_delete_action_plan.xml
new file mode 100644
index 00000000000..eeb2dfd24c7
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_delete_action_plan.xml
@@ -0,0 +1,9 @@
+<dataset>
+
+ <action_plans id="1" kee="ABC" project_id="1" name="Long term" description="Long term action plan" deadline="[null]"
+ user_login="arthur" status="OPEN" created_at="[null]" updated_at="[null]" />
+
+ <action_plans id="2" kee="BCD" project_id="1" name="Short term" description="Short term action plan" deadline="[null]"
+ user_login="arthur" status="CLOSED" created_at="[null]" updated_at="[null]" />
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_insert_new_action_plan-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_insert_new_action_plan-result.xml
new file mode 100644
index 00000000000..2e330ef5fe1
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_insert_new_action_plan-result.xml
@@ -0,0 +1,6 @@
+<dataset>
+
+ <action_plans id="1" kee="ABC" project_id="1" name="Long term" description="Long term action plan" deadline="[null]"
+ user_login="arthur" status="OPEN" created_at="[null]" updated_at="[null]" />
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_update_action_plan-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_update_action_plan-result.xml
new file mode 100644
index 00000000000..2e330ef5fe1
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_update_action_plan-result.xml
@@ -0,0 +1,6 @@
+<dataset>
+
+ <action_plans id="1" kee="ABC" project_id="1" name="Long term" description="Long term action plan" deadline="[null]"
+ user_login="arthur" status="OPEN" created_at="[null]" updated_at="[null]" />
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_update_action_plan.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_update_action_plan.xml
new file mode 100644
index 00000000000..983893dbc03
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/ActionPlanDaoTest/should_update_action_plan.xml
@@ -0,0 +1,6 @@
+<dataset>
+
+ <action_plans id="1" kee="ABC" project_id="1" name="Old name" description="Old desc" deadline="[null]"
+ user_login="[null]" status="CLOSED" created_at="[null]" updated_at="[null]" />
+
+</dataset>