Skip to content

Commit

Permalink
SONAR-7191 api/ce/activity max submitted date is inclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
teryk committed Feb 19, 2016
1 parent 2ee64e5 commit cc00abd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Expand Up @@ -142,10 +142,10 @@ public void define(WebService.NewController controller) {
.setExampleValue(CeTaskTypes.REPORT) .setExampleValue(CeTaskTypes.REPORT)
.setPossibleValues(taskTypes); .setPossibleValues(taskTypes);
action.createParam(PARAM_MIN_SUBMITTED_AT) action.createParam(PARAM_MIN_SUBMITTED_AT)
.setDescription("Minimum date of task submission") .setDescription("Minimum date of task submission (inclusive)")
.setExampleValue(DateUtils.formatDateTime(new Date())); .setExampleValue(DateUtils.formatDateTime(new Date()));
action.createParam(PARAM_MAX_EXECUTED_AT) action.createParam(PARAM_MAX_EXECUTED_AT)
.setDescription("Maximum date of end of task processing") .setDescription("Maximum date of end of task processing (inclusive)")
.setExampleValue(DateUtils.formatDateTime(new Date())); .setExampleValue(DateUtils.formatDateTime(new Date()));
action.addPagingParams(100, MAX_PAGE_SIZE); action.addPagingParams(100, MAX_PAGE_SIZE);
} }
Expand Down Expand Up @@ -274,10 +274,10 @@ private static Long parseDateTimeAsLong(@Nullable String dateAsString) {
Date date = parseDateTimeQuietly(dateAsString); Date date = parseDateTimeQuietly(dateAsString);
if (date == null) { if (date == null) {
date = parseDateQuietly(dateAsString); date = parseDateQuietly(dateAsString);
checkRequest(date != null, "Date '%s' cannot be parsed as either a date or date+time", dateAsString);
date = DateUtils.addDays(date, 1);
} }


checkRequest(date != null, "Date '%s' cannot be parsed as either a date or date+time", dateAsString);

return date.getTime(); return date.getTime();
} }


Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
Expand Down Expand Up @@ -58,6 +59,7 @@
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.sonar.api.utils.DateUtils.formatDate;
import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.db.component.ComponentTesting.newProjectDto; import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY; import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY;
Expand Down Expand Up @@ -124,7 +126,7 @@ public void filter_by_status() {
} }


@Test @Test
public void filter_by_max_executed_at() { public void filter_by_max_executed_at_exclude() {
userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS); insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED); insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
Expand All @@ -137,6 +139,19 @@ public void filter_by_max_executed_at() {
assertThat(activityResponse.getTasksCount()).isEqualTo(0); assertThat(activityResponse.getTasksCount()).isEqualTo(0);
} }


@Test
public void filter_by_max_executed_at_include_day_filled() {
userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
String today = formatDate(new Date(EXECUTED_AT));
System.out.println(EXECUTED_AT + " - " + today);

ActivityResponse activityResponse = call(ws.newRequest()
.setParam(CeWsParameters.PARAM_MAX_EXECUTED_AT, today));

assertThat(activityResponse.getTasksCount()).isEqualTo(1);
}

@Test @Test
public void filter_on_current_activities() { public void filter_on_current_activities() {
userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
Expand Down
Expand Up @@ -142,6 +142,14 @@ public static Date parseDateTimeQuietly(@Nullable String s) {
return datetime; return datetime;
} }


/**
* Adds a number of days to a date returning a new object.
* The original date object is unchanged.
*
* @param date the date, not null
* @param numberOfDays the amount to add, may be negative
* @return the new date object with the amount added
*/
public static Date addDays(Date date, int numberOfDays) { public static Date addDays(Date date, int numberOfDays) {
return org.apache.commons.lang.time.DateUtils.addDays(date, numberOfDays); return org.apache.commons.lang.time.DateUtils.addDays(date, numberOfDays);
} }
Expand Down

0 comments on commit cc00abd

Please sign in to comment.