diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-19 11:05:59 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-02-19 11:27:34 +0100 |
commit | cc00abdb06af7466b4aedbaa7159d0844f465e96 (patch) | |
tree | e2b21a93f9186e12c22d7616019ef2e5f7e29842 | |
parent | 2ee64e504b6921fd2d2f2d183e425904bc492c9d (diff) | |
download | sonarqube-cc00abdb06af7466b4aedbaa7159d0844f465e96.tar.gz sonarqube-cc00abdb06af7466b4aedbaa7159d0844f465e96.zip |
SONAR-7191 api/ce/activity max submitted date is inclusive
3 files changed, 28 insertions, 5 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/ActivityAction.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/ActivityAction.java index 19c1aee5b18..a318964313d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/ActivityAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/ActivityAction.java @@ -142,10 +142,10 @@ public class ActivityAction implements CeWsAction { .setExampleValue(CeTaskTypes.REPORT) .setPossibleValues(taskTypes); action.createParam(PARAM_MIN_SUBMITTED_AT) - .setDescription("Minimum date of task submission") + .setDescription("Minimum date of task submission (inclusive)") .setExampleValue(DateUtils.formatDateTime(new Date())); 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())); action.addPagingParams(100, MAX_PAGE_SIZE); } @@ -274,10 +274,10 @@ public class ActivityAction implements CeWsAction { Date date = parseDateTimeQuietly(dateAsString); if (date == null) { 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(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/ActivityActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/ActivityActionTest.java index f51761372e5..049725d1836 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/ActivityActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/ActivityActionTest.java @@ -25,6 +25,7 @@ import com.google.common.base.Throwables; import java.io.File; import java.io.IOException; import java.util.Collections; +import java.util.Date; import java.util.List; import org.junit.Before; import org.junit.Rule; @@ -58,6 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; 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.db.component.ComponentTesting.newProjectDto; import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_QUERY; @@ -124,7 +126,7 @@ public class ActivityActionTest { } @Test - public void filter_by_max_executed_at() { + public void filter_by_max_executed_at_exclude() { userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS); insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED); @@ -138,6 +140,19 @@ public class ActivityActionTest { } @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 public void filter_on_current_activities() { userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); // T2 is the current activity (the most recent one) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java index 277ce1add12..2f31b3f506b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java @@ -142,6 +142,14 @@ public final class DateUtils { 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) { return org.apache.commons.lang.time.DateUtils.addDays(date, numberOfDays); } |