import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.ComponentTesting.newView;
+import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_STATUS;
+import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_TYPE;
public class ActivityActionTest {
@Test
public void get_all_past_activity() {
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
@Test
public void filter_by_status() {
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
insertQueue("T3", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
@Test
public void filter_by_max_executed_at_exclude() {
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
insertQueue("T3", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
@Test
public void filter_by_max_executed_at_include_day_filled() {
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
String today = formatDate(new Date(EXECUTED_AT));
System.out.println(EXECUTED_AT + " - " + today);
@Test
public void filter_on_current_activities() {
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
// T2 is the current activity (the most recent one)
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_1", CeActivityDto.Status.FAILED);
@Test
public void limit_results() {
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
insertQueue("T3", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
componentDb.insertProjectAndSnapshot(eclipse);
dbTester.commit();
componentDb.indexComponents(struts.getId(), zookeeper.getId(), eclipse.getId());
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
insertActivity("T1", "P1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "P2", CeActivityDto.Status.SUCCESS);
insertActivity("T3", "P3", CeActivityDto.Status.SUCCESS);
componentDb.insertDeveloperAndSnapshot(developer);
componentDb.insertViewAndSnapshot(apacheView);
componentDb.indexComponents(developer.getId(), apacheView.getId());
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
insertActivity("T1", "D1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "V1", CeActivityDto.Status.SUCCESS);
@Test
public void search_task_id_in_queue_ignoring_other_parameters() throws IOException {
+ globalAdmin();
insertQueue("T1", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
ActivityResponse result = call(
@Test
public void search_task_id_in_activity() {
+ globalAdmin();
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
ActivityResponse result = call(ws.newRequest().setParam(Param.TEXT_QUERY, "T1"));
assertThat(result.getTasks(0).getId()).isEqualTo("T1");
}
+ @Test
+ public void search_task_id_as_project_admin() {
+ insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
+ userSession.login().addProjectUuidPermissions(UserRole.ADMIN, "PROJECT_1");
+
+ ActivityResponse result = call(ws.newRequest().setParam(Param.TEXT_QUERY, "T1"));
+
+ assertThat(result.getTasksCount()).isEqualTo(1);
+ assertThat(result.getTasks(0).getId()).isEqualTo("T1");
+ }
+
+ @Test
+ public void search_task_by_component_uuid() {
+ insertQueue("T1", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
+ insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
+ globalAdmin();
+
+ ActivityResponse result = call(ws.newRequest()
+ .setParam(PARAM_COMPONENT_ID, "PROJECT_1")
+ .setParam(PARAM_TYPE, CeTaskTypes.REPORT)
+ .setParam(PARAM_STATUS, "SUCCESS,FAILED,CANCELED,IN_PROGRESS,PENDING"));
+
+ assertThat(result.getTasksCount()).isEqualTo(2);
+ }
+
@Test
public void fail_if_both_filters_on_component_id_and_name() {
expectedException.expect(BadRequestException.class);
@Test
public void support_json_response() {
- userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ globalAdmin();
TestResponse wsResponse = ws.newRequest()
.setMediaType(MediaTypes.JSON)
.execute();
JsonAssert.assertJson(wsResponse.getInput()).isSimilarTo("{\"tasks\":[]}");
}
+ private void globalAdmin() {
+ userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ }
+
private CeQueueDto insertQueue(String taskUuid, String componentUuid, CeQueueDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);