diff --git a/qa/integration/src/test/resources/features/job/JobExecutionServiceI9n.feature b/qa/integration/src/test/resources/features/job/JobExecutionServiceI9n.feature index 038a08979ed..c9d95a11b99 100644 --- a/qa/integration/src/test/resources/features/job/JobExecutionServiceI9n.feature +++ b/qa/integration/src/test/resources/features/job/JobExecutionServiceI9n.feature @@ -128,6 +128,26 @@ Scenario: Query for executions of a specific job When I query for the execution items for the current job Then I count 3 + +Scenario: Query for executions of a specific job using start date + + Given I login as user with name "kapua-sys" and password "kapua-password" + * I configure the job service + | type | name | value | + | boolean | infiniteChildEntities | true | + | integer | maxNumberChildEntities | 5 | + * I create a job with the name "TestJob" + * A regular job execution item + * A regular job execution item + * A regular job execution item + * A regular job execution item + + When I query for the execution items for the current job starting from date in the future + Then I count 0 + + When I query for the execution items for the current job starting from date in the past + Then I count 4 + Scenario: Job execution factory sanity checks And I test the sanity of the job execution factory diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobExecutions.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobExecutions.java index a4bc2b689b7..e5e64b897c4 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobExecutions.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/JobExecutions.java @@ -12,6 +12,17 @@ *******************************************************************************/ package org.eclipse.kapua.app.api.resources.v1.resources; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + import com.google.common.base.Strings; import org.eclipse.kapua.KapuaEntityNotFoundException; import org.eclipse.kapua.KapuaException; @@ -37,17 +48,6 @@ import org.eclipse.kapua.service.job.targets.JobTargetQuery; import org.eclipse.kapua.service.job.targets.JobTargetService; -import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - @Path("{scopeId}/jobs/{jobId}/executions") public class JobExecutions extends AbstractKapuaResource { @@ -128,7 +128,11 @@ public JobExecutionListResult query( @PathParam("jobId") EntityId jobId, JobExecutionQuery query) throws KapuaException { query.setScopeId(scopeId); - query.setPredicate(query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId)); + final AndPredicate andPredicate = query.andPredicate( + query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId), + query.getPredicate() + ); + query.setPredicate(andPredicate); return jobExecutionService.query(query); } diff --git a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobExecutionServiceSteps.java b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobExecutionServiceSteps.java index 2c6df9230dc..38536c18f22 100644 --- a/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobExecutionServiceSteps.java +++ b/service/job/test-steps/src/main/java/org/eclipse/kapua/service/job/steps/JobExecutionServiceSteps.java @@ -12,6 +12,10 @@ *******************************************************************************/ package org.eclipse.kapua.service.job.steps; +import java.util.Calendar; +import java.util.Date; +import javax.inject.Inject; + import com.google.inject.Singleton; import io.cucumber.java.After; import io.cucumber.java.Before; @@ -23,6 +27,7 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.model.query.predicate.AndPredicate; import org.eclipse.kapua.model.query.predicate.AttributePredicate; import org.eclipse.kapua.qa.common.StepData; import org.eclipse.kapua.service.job.Job; @@ -42,8 +47,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; - @Singleton public class JobExecutionServiceSteps extends JobServiceTestBase { @@ -165,22 +168,51 @@ public void queryExecutionsForJobWithPackages() throws Exception { } } -// @And("I query for the execution items for the current job and I count {int} or more") -// public void iQueryForTheExecutionItemsForTheCurrentJobAndICountOrMore(int numberOfExecutions) throws Exception { -// Job job = (Job) stepData.get("Job"); -// JobExecutionQuery tmpQuery = jobExecutionFactory.newQuery(getCurrentScopeId()); -// tmpQuery.setPredicate(tmpQuery.attributePredicate(JobExecutionAttributes.JOB_ID, job.getId(), AttributePredicate.Operator.EQUAL)); -// primeException(); -// try { -// stepData.remove(JOB_EXECUTION_LIST); -// JobExecutionListResult resultList = jobExecutionService.query(tmpQuery); -// stepData.put(JOB_EXECUTION_LIST, resultList); -// stepData.updateCount(resultList.getSize()); -// Assert.assertTrue(resultList.getSize() >= numberOfExecutions); -// } catch (KapuaException ex) { -// verifyException(ex); -// } -// } + + @Then("I query for the execution items for the current job starting from date in the future") + public void queryExecutionsForJobWithStartDateInFuture() throws Exception { + final Date startDate = createDateInFuture(); + queryExecutionsForJobWithStartDate(startDate); + } + + + @Then("I query for the execution items for the current job starting from date in the past") + public void queryExecutionsForJobWithStartDateInPast() throws Exception { + final Date startDate = createDateInPast(); + queryExecutionsForJobWithStartDate(startDate); + } + + + private void queryExecutionsForJobWithStartDate(Date startDate) throws Exception { + final Job job = (Job) stepData.get("Job"); + final JobExecutionQuery tmpQuery = jobExecutionFactory.newQuery(getCurrentScopeId()); + final AndPredicate andPredicate = tmpQuery.andPredicate(tmpQuery.attributePredicate(JobExecutionAttributes.JOB_ID, job.getId())); + andPredicate.and(tmpQuery.attributePredicate(JobExecutionAttributes.STARTED_ON, startDate, AttributePredicate.Operator.GREATER_THAN_OR_EQUAL)); + tmpQuery.setPredicate(andPredicate); + primeException(); + try { + stepData.remove(JOB_EXECUTION_LIST); + JobExecutionListResult resultList = jobExecutionService.query(tmpQuery); + stepData.put(JOB_EXECUTION_LIST, resultList); + stepData.updateCount(resultList.getSize()); + } catch (KapuaException ex) { + verifyException(ex); + } + } + + + private Date createDateInFuture() { + final Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, 7); + return calendar.getTime(); + } + + + private Date createDateInPast() { + final Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, -7); + return calendar.getTime(); + } @Then("I query for the execution items for the current job and I count {int} finished within {int} second(s)") public void queryExecutionsForJob(int numberOfExecutions, int timeout) throws Exception {