protected Date oneWeekLater() { // one week from now Date startTime = new Date(); ClockUtil.setCurrentTime(startTime); long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000); return new Date(oneWeekFromStartTime); }
/** * Sets the clock to a date without milliseconds. Older mysql * versions do not support milliseconds. Test which test timestamp * should avoid timestamps with milliseconds. * * @return the new current time */ public static Date setClockToDateWithoutMilliseconds() { ClockUtil.setCurrentTime(new Date(1363608000000L)); return ClockUtil.getCurrentTime(); }
protected void addToCalendar(int field, int month) { Calendar calendar = Calendar.getInstance(); calendar.setTime(ClockUtil.getCurrentTime()); calendar.add(field, month); ClockUtil.setCurrentTime(calendar.getTime()); }
protected void ensureEnoughTimePassedByForTimestampOrdering() { long timeToAddInSeconds = 5 * 1000L; Date nowPlus5Seconds = new Date(ClockUtil.getCurrentTime().getTime() + timeToAddInSeconds); ClockUtil.setCurrentTime(nowPlus5Seconds); }
protected void addToCalendar(int field, int month) { Calendar calendar = Calendar.getInstance(); calendar.setTime(ClockUtil.getCurrentTime()); calendar.add(field, month); ClockUtil.setCurrentTime(calendar.getTime()); }
@Override protected void tearDown() throws Exception { super.tearDown(); ClockUtil.setCurrentTime(new Date()); }
public void shiftTimeByOneMinute() { Long oneMinute = 1000L * 60L; Date shiftedTimeByOneMinute = new Date(ClockUtil.getCurrentTime().getTime() + oneMinute); ClockUtil.setCurrentTime(shiftedTimeByOneMinute); }
@Test public void shouldNotExceedNumber() throws Exception { ClockUtil.setCurrentTime(new Date(0)); DurationHelper dh = new DurationHelper("R2/PT10S"); ClockUtil.setCurrentTime(new Date(15000)); assertEquals(20000, dh.getDateAfter().getTime()); ClockUtil.setCurrentTime(new Date(30000)); assertNull(dh.getDateAfter()); }
/** * Use between two rule evaluations to ensure the expected order by evaluation time. */ protected void waitASignificantAmountOfTime() { DateTime now = new DateTime(ClockUtil.getCurrentTime()); ClockUtil.setCurrentTime(now.plusSeconds(10).toDate()); }
@Test public void setCurrentTimeShouldFreezeTime() { long duration = TWO_DAYS; Date target = new Date(new Date().getTime() + duration); ClockUtil.setCurrentTime(target); assertThat(ClockUtil.now()).isCloseTo(target, ONE_SECOND); }
@Test public void timeShouldFreezeWithSetCurrentTime() throws InterruptedException { Date now = new Date(); long duration = TWO_DAYS; Date target = new Date(now.getTime() + duration); ClockUtil.setCurrentTime(target); Thread.sleep(FIVE_SECONDS); assertThat(ClockUtil.now()).isCloseTo(target, ONE_SECOND); } }
public void testSimpleCron() throws Exception { CycleBusinessCalendar businessCalendar = new CycleBusinessCalendar(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy MM dd - HH:mm"); Date now = simpleDateFormat.parse("2011 03 11 - 17:23"); ClockUtil.setCurrentTime(now); Date duedate = businessCalendar.resolveDuedate("0 0 0 1 * ?"); Date expectedDuedate = simpleDateFormat.parse("2011 04 1 - 00:00"); assertEquals(expectedDuedate, duedate); }
public void testSimpleDuration() throws Exception { CycleBusinessCalendar businessCalendar = new CycleBusinessCalendar(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy MM dd - HH:mm"); Date now = simpleDateFormat.parse("2010 06 11 - 17:23"); ClockUtil.setCurrentTime(now); Date duedate = businessCalendar.resolveDuedate("R/P2DT5H70M"); Date expectedDuedate = simpleDateFormat.parse("2010 06 13 - 23:33"); assertEquals(expectedDuedate, duedate); }
public void testSimpleDuration() throws Exception { DurationBusinessCalendar businessCalendar = new DurationBusinessCalendar(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy MM dd - HH:mm"); Date now = simpleDateFormat.parse("2010 06 11 - 17:23"); ClockUtil.setCurrentTime(now); Date duedate = businessCalendar.resolveDuedate("P2DT5H70M"); Date expectedDuedate = simpleDateFormat.parse("2010 06 13 - 23:33"); assertEquals(expectedDuedate, duedate); }
private void prepareBPMNData(int instanceCount, String businesskey) { Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), DAYS_IN_THE_PAST)); final List<String> ids = prepareHistoricProcesses(businesskey, getVariables(), instanceCount); deleteProcessInstances(ids); ClockUtil.setCurrentTime(oldCurrentTime); }
@Test public void shouldNotExceedNumberPeriods() throws Exception { ClockUtil.setCurrentTime(parse("19700101-00:00:00")); DurationHelper dh = new DurationHelper("R2/1970-01-01T00:00:00/1970-01-01T00:00:10"); ClockUtil.setCurrentTime(parse("19700101-00:00:15")); assertEquals(parse("19700101-00:00:20"), dh.getDateAfter()); ClockUtil.setCurrentTime(parse("19700101-00:00:30")); assertNull(dh.getDateAfter()); }
@Deployment(resources="org/camunda/bpm/engine/test/jobexecutor/processWithTimerStart.bpmn20.xml") public void testTimerStartEvent() { Set<String> registeredDeployments = processEngineConfiguration.getRegisteredDeployments(); Job existingJob = managementService.createJobQuery().singleResult(); ClockUtil.setCurrentTime(new Date(System.currentTimeMillis()+1000)); List<JobEntity> acquirableJobs = findAcquirableJobs(); assertEquals(1, acquirableJobs.size()); assertEquals(existingJob.getId(), acquirableJobs.get(0).getId()); registeredDeployments.clear(); acquirableJobs = findAcquirableJobs(); assertEquals(0, acquirableJobs.size()); }
@Test @Deployment(resources = { "org/camunda/bpm/engine/test/dmn/businessruletask/DmnBusinessRuleTaskTest.testDecisionRef.bpmn20.xml", "org/camunda/bpm/engine/test/api/history/testDmnWithPojo.dmn11.xml", "org/camunda/bpm/engine/test/api/authorization/oneTaskCase.cmmn" }) public void testHistoryCleanupEverythingRemoved() { // given prepareInstances(HISTORY_TIME_TO_LIVE, HISTORY_TIME_TO_LIVE, HISTORY_TIME_TO_LIVE); ClockUtil.setCurrentTime(new Date()); // when runHistoryCleanup(true); // then assertResult(0); }
@Deployment public void testExpressionStartTimerEvent() throws Exception { // ACT-1415: fixed start-date is an expression JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, jobQuery.count()); ClockUtil.setCurrentTime(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("15/11/2036 11:12:30")); executeAllJobs(); List<ProcessInstance> pi = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample").list(); assertEquals(1, pi.size()); assertEquals(0, jobQuery.count()); }
@Test @Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void historyCleanupWithDisabledDmn() { prepareHistoricProcesses("oneTaskProcess"); ClockUtil.setCurrentTime(new Date()); //when String jobId = historyService.cleanUpHistoryAsync(true).getId(); engineRule.getManagementService().executeJob(jobId); //then assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count()); }