|
|
@@ -28,10 +28,13 @@ import javax.annotation.Nonnull; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Test; |
|
|
|
import org.sonar.api.utils.internal.TestSystem2; |
|
|
|
import org.sonar.db.DbSession; |
|
|
|
import org.sonar.db.DbTester; |
|
|
|
|
|
|
|
import static java.util.Collections.singletonList; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.sonar.db.ce.CeActivityDto.Status.FAILED; |
|
|
|
import static org.sonar.db.ce.CeActivityDto.Status.SUCCESS; |
|
|
|
import static org.sonar.db.ce.CeTaskTypes.REPORT; |
|
|
|
|
|
|
|
public class CeActivityDaoTest { |
|
|
@@ -40,6 +43,7 @@ public class CeActivityDaoTest { |
|
|
|
|
|
|
|
@Rule |
|
|
|
public DbTester db = DbTester.create(system2); |
|
|
|
DbSession dbSession = db.getSession(); |
|
|
|
|
|
|
|
CeActivityDao underTest = new CeActivityDao(system2); |
|
|
|
|
|
|
@@ -75,7 +79,7 @@ public class CeActivityDaoTest { |
|
|
|
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue(); |
|
|
|
|
|
|
|
// two tasks on PROJECT_1, the most recent one is TASK_3 |
|
|
|
insert("TASK_3", REPORT, "PROJECT_1", CeActivityDto.Status.FAILED); |
|
|
|
insert("TASK_3", REPORT, "PROJECT_1", FAILED); |
|
|
|
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse(); |
|
|
|
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue(); |
|
|
|
assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue(); |
|
|
@@ -91,7 +95,7 @@ public class CeActivityDaoTest { |
|
|
|
@Test |
|
|
|
public void test_selectByQuery() { |
|
|
|
insert("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.SUCCESS); |
|
|
|
insert("TASK_2", REPORT, "PROJECT_1", CeActivityDto.Status.FAILED); |
|
|
|
insert("TASK_2", REPORT, "PROJECT_1", FAILED); |
|
|
|
insert("TASK_3", REPORT, "PROJECT_2", CeActivityDto.Status.SUCCESS); |
|
|
|
insert("TASK_4", "views", null, CeActivityDto.Status.SUCCESS); |
|
|
|
|
|
|
@@ -211,6 +215,22 @@ public class CeActivityDaoTest { |
|
|
|
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").isPresent()).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void count_last_by_status_and_component_uuid() { |
|
|
|
insert("TASK_1", CeTaskTypes.REPORT, "COMPONENT1", CeActivityDto.Status.SUCCESS); |
|
|
|
// component 2 |
|
|
|
insert("TASK_2", CeTaskTypes.REPORT, "COMPONENT2", CeActivityDto.Status.SUCCESS); |
|
|
|
// status failed |
|
|
|
insert("TASK_3", CeTaskTypes.REPORT, "COMPONENT1", CeActivityDto.Status.FAILED); |
|
|
|
// status canceled |
|
|
|
insert("TASK_4", CeTaskTypes.REPORT, "COMPONENT1", CeActivityDto.Status.CANCELED); |
|
|
|
insert("TASK_5", CeTaskTypes.REPORT, "COMPONENT1", CeActivityDto.Status.SUCCESS); |
|
|
|
db.commit(); |
|
|
|
|
|
|
|
assertThat(underTest.countLastByStatusAndComponentUuid(dbSession, SUCCESS, "COMPONENT1")).isEqualTo(1); |
|
|
|
assertThat(underTest.countLastByStatusAndComponentUuid(dbSession, SUCCESS, null)).isEqualTo(2); |
|
|
|
} |
|
|
|
|
|
|
|
private void insert(String uuid, String type, String componentUuid, CeActivityDto.Status status) { |
|
|
|
CeQueueDto queueDto = new CeQueueDto(); |
|
|
|
queueDto.setUuid(uuid); |