diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-15 15:11:57 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-15 15:12:05 +0100 |
commit | 06427d40a40a040c482836953845d45d4689579b (patch) | |
tree | bbab9d081c469c4853d36682a1bf0f45c03e9ca2 | |
parent | f5382639add031e079f476800930e450a984b7d0 (diff) | |
download | sonarqube-06427d40a40a040c482836953845d45d4689579b.tar.gz sonarqube-06427d40a40a040c482836953845d45d4689579b.zip |
SONAR-7187 Improve code coverage of CeQueueDao
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java index 943fbc14e52..f051fef6284 100644 --- a/sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java @@ -20,6 +20,7 @@ package org.sonar.db.ce; import com.google.common.base.Optional; +import java.util.Collections; import java.util.List; import org.junit.Rule; import org.junit.Test; @@ -211,6 +212,7 @@ public class CeQueueDaoTest { .setTaskType(CeTaskTypes.REPORT) .setCreatedAt(120_000L)); + // select by component uuid, status, task type and minimum submitted at CeActivityQuery query = new CeActivityQuery() .setComponentUuids(newArrayList("PROJECT_1", "PROJECT_2")) .setStatuses(singletonList(CeQueueDto.Status.PENDING.name())) @@ -224,6 +226,57 @@ public class CeQueueDaoTest { assertThat(total).isEqualTo(2); } + @Test + public void select_by_query_returns_empty_list_when_only_current() { + insert(newCeQueueDto("TASK_1") + .setComponentUuid("PROJECT_1") + .setStatus(CeQueueDto.Status.IN_PROGRESS) + .setTaskType(CeTaskTypes.REPORT) + .setCreatedAt(100_000L)); + + CeActivityQuery query = new CeActivityQuery().setOnlyCurrents(true); + + List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, Paging.forPageIndex(1).withPageSize(1_000).andTotal(1_000)); + int total = underTest.countByQuery(db.getSession(), query); + + assertThat(result).isEmpty(); + assertThat(total).isEqualTo(0); + } + + @Test + public void select_by_query_returns_empty_list_when_max_submitted_at() { + insert(newCeQueueDto("TASK_1") + .setComponentUuid("PROJECT_1") + .setStatus(CeQueueDto.Status.IN_PROGRESS) + .setTaskType(CeTaskTypes.REPORT) + .setCreatedAt(100_000L)); + + CeActivityQuery query = new CeActivityQuery().setMaxExecutedAt(1_000_000_000_000L); + + List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, Paging.forPageIndex(1).withPageSize(1_000).andTotal(1_000)); + int total = underTest.countByQuery(db.getSession(), query); + + assertThat(result).isEmpty(); + assertThat(total).isEqualTo(0); + } + + @Test + public void select_by_query_returns_empty_list_when_empty_list_of_component_uuid() { + insert(newCeQueueDto("TASK_1") + .setComponentUuid("PROJECT_1") + .setStatus(CeQueueDto.Status.IN_PROGRESS) + .setTaskType(CeTaskTypes.REPORT) + .setCreatedAt(100_000L)); + + CeActivityQuery query = new CeActivityQuery().setComponentUuids(Collections.<String>emptyList()); + + List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, Paging.forPageIndex(1).withPageSize(1_000).andTotal(1_000)); + int total = underTest.countByQuery(db.getSession(), query); + + assertThat(result).isEmpty(); + assertThat(total).isEqualTo(0); + } + private void insert(CeQueueDto dto) { underTest.insert(db.getSession(), dto); db.commit(); |