Java Code Examples for org.camunda.bpm.engine.impl.util.ClockUtil#getCurrentTime()
The following examples show how to use
org.camunda.bpm.engine.impl.util.ClockUtil#getCurrentTime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CleanableHistoricCaseInstanceReportTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private void prepareCaseInstances(String key, int daysInThePast, Integer historyTimeToLive, int instanceCount) { // update time to live List<CaseDefinition> caseDefinitions = repositoryService.createCaseDefinitionQuery().caseDefinitionKey(key).list(); assertEquals(1, caseDefinitions.size()); repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinitions.get(0).getId(), historyTimeToLive); Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysInThePast)); for (int i = 0; i < instanceCount; i++) { CaseInstance caseInstance = caseService.createCaseInstanceByKey(key); caseService.terminateCaseExecution(caseInstance.getId()); caseService.closeCaseInstance(caseInstance.getId()); } ClockUtil.setCurrentTime(oldCurrentTime); }
Example 2
Source File: HistoricBatchQueryAuthorizationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private void prepareBatch(String migrationOperationsTTL) { engineRule.getProcessEngineConfiguration().setAuthorizationEnabled(false); Map<String, String> map = new HashMap<>(); map.put("instance-migration", migrationOperationsTTL); engineRule.getProcessEngineConfiguration().setBatchOperationsForHistoryCleanup(map); engineRule.getProcessEngineConfiguration().initHistoryCleanup(); Date startDate = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -11)); String batchId = createBatch(); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, -7)); engineRule.getManagementService().deleteBatch(batchId, false); engineRule.getProcessEngineConfiguration().setAuthorizationEnabled(true); }
Example 3
Source File: HistoricBatchManagerBatchesForCleanupTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private String prepareHistoricBatches(int batchesCount) { Date startDate = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, daysInThePast)); List<Batch> list = new ArrayList<Batch>(); for (int i = 0; i < batchesCount; i++) { list.add(helper.migrateProcessInstancesAsync(1)); } Batch batch1 = list.get(0); String batchType = batch1.getType(); helper.completeSeedJobs(batch1); helper.executeJobs(batch1); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, batch1EndTime)); helper.executeMonitorJob(batch1); Batch batch2 = list.get(1); helper.completeSeedJobs(batch2); helper.executeJobs(batch2); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, batch2EndTime)); helper.executeMonitorJob(batch2); ClockUtil.setCurrentTime(new Date()); return batchType; }
Example 4
Source File: IdentityServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @WatchLogger(loggerNames = {INDENTITY_LOGGER}, level = "INFO") public void testUnsuccessfulLoginAfterFailureWithoutDelay() { // given User user = identityService.newUser("johndoe"); user.setPassword("xxx"); identityService.saveUser(user); Date now = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(now); assertFalse(identityService.checkPassword("johndoe", "invalid pwd")); ClockUtil.setCurrentTime(DateUtils.addSeconds(now, 1)); Date expectedLockExpitation = DateUtils.addSeconds(now, 3); // when try again before exprTime assertFalse(identityService.checkPassword("johndoe", "invalid pwd")); // then assertThat(loggingRule.getFilteredLog(INDENTITY_LOGGER, "The lock will expire at " + expectedLockExpitation).size()).isEqualTo(1); }
Example 5
Source File: CleanableHistoricProcessInstanceReportTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void prepareProcessInstances(String key, int daysInThePast, Integer historyTimeToLive, int instanceCount) { List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().processDefinitionKey(key).list(); assertEquals(1, processDefinitions.size()); repositoryService.updateProcessDefinitionHistoryTimeToLive(processDefinitions.get(0).getId(), historyTimeToLive); Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysInThePast)); List<String> processInstanceIds = new ArrayList<String>(); for (int i = 0; i < instanceCount; i++) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key); processInstanceIds.add(processInstance.getId()); } runtimeService.deleteProcessInstances(processInstanceIds, null, true, true); ClockUtil.setCurrentTime(oldCurrentTime); }
Example 6
Source File: HistoryCleanupHistoricBatchTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private void prepareHistoricBatches(int batchesCount, int daysInThePast) { Date startDate = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(startDate, daysInThePast)); List<Batch> list = new ArrayList<>(); for (int i = 0; i < batchesCount; i++) { list.add(migrationHelper.migrateProcessInstancesAsync(1)); } for (Batch batch : list) { migrationHelper.completeSeedJobs(batch); migrationHelper.executeJobs(batch); ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.addDays(startDate, ++daysInThePast), random.nextInt(60))); migrationHelper.executeMonitorJob(batch); } ClockUtil.setCurrentTime(new Date()); }
Example 7
Source File: HistoricDecisionInstanceAuthorizationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
protected void prepareDecisionInstances(String key, int daysInThePast, Integer historyTimeToLive, int instanceCount) { DecisionDefinition decisionDefinition = selectDecisionDefinitionByKey(key); disableAuthorization(); repositoryService.updateDecisionDefinitionHistoryTimeToLive(decisionDefinition.getId(), historyTimeToLive); enableAuthorization(); Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysInThePast)); Map<String, Object> variables = Variables.createVariables().putValue("input1", null); for (int i = 0; i < instanceCount; i++) { disableAuthorization(); decisionService.evaluateDecisionByKey(key).variables(variables).evaluate(); enableAuthorization(); } ClockUtil.setCurrentTime(oldCurrentTime); }
Example 8
Source File: CdiEventListener.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected BusinessProcessEvent createEvent(DelegateTask task) { ExecutionContext executionContext = Context.getExecutionContext(); ProcessDefinitionEntity processDefinition = null; if (executionContext != null) { processDefinition = executionContext.getProcessDefinition(); } // map type String eventName = task.getEventName(); BusinessProcessEventType type = null; if (TaskListener.EVENTNAME_CREATE.equals(eventName)) { type = BusinessProcessEventType.CREATE_TASK; } else if (TaskListener.EVENTNAME_ASSIGNMENT.equals(eventName)) { type = BusinessProcessEventType.ASSIGN_TASK; } else if (TaskListener.EVENTNAME_COMPLETE.equals(eventName)) { type = BusinessProcessEventType.COMPLETE_TASK; } else if (TaskListener.EVENTNAME_UPDATE.equals(eventName)) { type = BusinessProcessEventType.UPDATE_TASK; } else if (TaskListener.EVENTNAME_DELETE.equals(eventName)) { type = BusinessProcessEventType.DELETE_TASK; } return new CdiBusinessProcessEvent(task, processDefinition, type, ClockUtil.getCurrentTime()); }
Example 9
Source File: DurationHelper.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public DurationHelper(String expressions, Date startDate) throws Exception { List<String> expression = new ArrayList<String>(); if(expressions != null) { expression = Arrays.asList(expressions.split("/")); } datatypeFactory = DatatypeFactory.newInstance(); if (expression.size() > 3 || expression.isEmpty()) { throw LOG.cannotParseDuration(expressions); } if (expression.get(0).startsWith("R")) { isRepeat = true; times = expression.get(0).length() == 1 ? Integer.MAX_VALUE : Integer.parseInt(expression.get(0).substring(1)); expression = expression.subList(1, expression.size()); } if (isDuration(expression.get(0))) { period = parsePeriod(expression.get(0)); end = expression.size() == 1 ? null : DateTimeUtil.parseDate(expression.get(1)); } else { start = DateTimeUtil.parseDate(expression.get(0)); if (isDuration(expression.get(1))) { period = parsePeriod(expression.get(1)); } else { end = DateTimeUtil.parseDate(expression.get(1)); period = datatypeFactory.newDuration(end.getTime()-start.getTime()); } } if (start == null && end == null) { start = startDate == null ? ClockUtil.getCurrentTime() : startDate; } }
Example 10
Source File: DefaultBusinessCalendar.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public Date resolveDuedate(String duedate, Date startDate) { Date resolvedDuedate = startDate == null ? ClockUtil.getCurrentTime() : startDate; String[] tokens = duedate.split(" and "); for (String token : tokens) { resolvedDuedate = addSingleUnitQuantity(resolvedDuedate, token); } return resolvedDuedate; }
Example 11
Source File: HistoryCleanupTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
private void prepareCMMNData(int instanceCount) { Date oldCurrentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), DAYS_IN_THE_PAST)); for (int i = 0; i < instanceCount; i++) { CaseInstance caseInstance = caseService.createCaseInstanceByKey(ONE_TASK_CASE); //spread end_time between different "minutes" ClockUtil.setCurrentTime(DateUtils.setMinutes(ClockUtil.getCurrentTime(), random.nextInt(60))); caseService.terminateCaseExecution(caseInstance.getId()); caseService.closeCaseInstance(caseInstance.getId()); } ClockUtil.setCurrentTime(oldCurrentTime); }
Example 12
Source File: UserOperationLogTaskServiceAndBeanTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public void testSetDateProperty() { // given: a single task task = taskService.newTask(); Date now = ClockUtil.getCurrentTime(); task.setDueDate(now); taskService.saveTask(task); UserOperationLogEntry logEntry = historyService.createUserOperationLogQuery().singleResult(); assertEquals(String.valueOf(now.getTime()), logEntry.getNewValue()); }
Example 13
Source File: StartTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment public void testRecalculateExpressionStartTimerEvent() throws Exception { // given JobQuery jobQuery = managementService.createJobQuery(); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample"); assertEquals(1, jobQuery.count()); assertEquals(0, processInstanceQuery.count()); Job job = jobQuery.singleResult(); Date oldDate = job.getDuedate(); // when moveByMinutes(2); Date currentTime = ClockUtil.getCurrentTime(); managementService.recalculateJobDuedate(job.getId(), false); // then assertEquals(1, jobQuery.count()); assertEquals(0, processInstanceQuery.count()); Date newDate = jobQuery.singleResult().getDuedate(); assertNotEquals(oldDate, newDate); assertTrue(oldDate.before(newDate)); Date expectedDate = LocalDateTime.fromDateFields(currentTime).plusHours(2).toDate(); assertThat(newDate).isCloseTo(expectedDate, 1000l); // move the clock forward 2 hours and 2 min moveByMinutes(122); executeAllJobs(); List<ProcessInstance> pi = processInstanceQuery.list(); assertEquals(1, pi.size()); assertEquals(0, jobQuery.count()); }
Example 14
Source File: DbIdentityServiceProvider.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
protected boolean isUserLocked(UserEntity user) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); int maxAttempts = processEngineConfiguration.getLoginMaxAttempts(); int attempts = user.getAttempts(); if (attempts >= maxAttempts) { return true; } Date lockExpirationTime = user.getLockExpirationTime(); Date currentTime = ClockUtil.getCurrentTime(); return lockExpirationTime != null && lockExpirationTime.after(currentTime); }
Example 15
Source File: DecisionDefinitionQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test public void testQueryByDeploymentTimeAt() throws ParseException { // given //get rid of the milliseconds because of MySQL datetime precision SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy - HH:mm:ss"); Date startTest = formatter.parse(formatter.format(DateUtils.addSeconds(ClockUtil.now(), 5))); ClockUtil.setCurrentTime(startTest); Date timeAtDeploymentOne = ClockUtil.getCurrentTime(); Deployment tempDeploymentOne = repositoryService.createDeployment() .addClasspathResource(DMN_ONE_RESOURCE).addClasspathResource(DMN_TWO_RESOURCE).deploy(); engineRule.manageDeployment(tempDeploymentOne); Date timeAtDeploymentTwo = DateUtils.addSeconds(timeAtDeploymentOne, 5); ClockUtil.setCurrentTime(timeAtDeploymentTwo); Deployment tempDeploymentTwo = repositoryService.createDeployment() .addClasspathResource(DMN_ONE_RESOURCE).deploy(); engineRule.manageDeployment(tempDeploymentTwo); Date timeAtDeploymentThree = DateUtils.addSeconds(timeAtDeploymentTwo, 5); ClockUtil.setCurrentTime(timeAtDeploymentThree); Deployment tempDeploymentThree = repositoryService.createDeployment() .addClasspathResource(DMN_THREE_RESOURCE).deploy(); engineRule.manageDeployment(tempDeploymentThree); // then List<DecisionDefinition> processDefinitions = repositoryService.createDecisionDefinitionQuery().deployedAt(timeAtDeploymentOne).list(); assertThat(processDefinitions).hasSize(2); assertThatDecisionDefinitionsWereDeployedAt(processDefinitions, timeAtDeploymentOne); processDefinitions = repositoryService.createDecisionDefinitionQuery().deployedAt(timeAtDeploymentTwo).list(); assertThat(processDefinitions).hasSize(1); assertThatDecisionDefinitionsWereDeployedAt(processDefinitions, timeAtDeploymentTwo); processDefinitions = repositoryService.createDecisionDefinitionQuery().deployedAt(timeAtDeploymentThree).list(); assertThat(processDefinitions).hasSize(1); assertThatDecisionDefinitionsWereDeployedAt(processDefinitions, timeAtDeploymentThree); processDefinitions = repositoryService.createDecisionDefinitionQuery().deployedAt(DateUtils.addSeconds(ClockUtil.getCurrentTime(), 5)).list(); assertThat(processDefinitions).hasSize(0); }
Example 16
Source File: DateTimeFunctionMapper.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public static Date now() { return ClockUtil.getCurrentTime(); }
Example 17
Source File: ProcessDefinitionQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test public void testQueryByDeploymentTimeAt() throws ParseException { // given //get rid of the milliseconds because of MySQL datetime precision SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy - HH:mm:ss"); Date startTest = formatter.parse(formatter.format(DateUtils.addSeconds(ClockUtil.now(), 5))); ClockUtil.setCurrentTime(startTest); Date timeAtDeploymentOne = ClockUtil.getCurrentTime(); Deployment tempDeploymentOne = repositoryService.createDeployment() .addClasspathResource(getResourceOnePath()).addClasspathResource(getResourceTwoPath()).deploy(); engineRule.manageDeployment(tempDeploymentOne); Date timeAtDeploymentTwo = DateUtils.addSeconds(timeAtDeploymentOne, 5); ClockUtil.setCurrentTime(timeAtDeploymentTwo); Deployment tempDeploymentTwo = repositoryService.createDeployment() .addClasspathResource(getResourceOnePath()).deploy(); engineRule.manageDeployment(tempDeploymentTwo); Date timeAtDeploymentThree = DateUtils.addSeconds(timeAtDeploymentTwo, 5); ClockUtil.setCurrentTime(timeAtDeploymentThree); Deployment tempDeploymentThree = repositoryService.createDeployment() .addClasspathResource(getResourceThreePath()).deploy(); engineRule.manageDeployment(tempDeploymentThree); // then List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().deployedAt(timeAtDeploymentOne).list(); assertThat(processDefinitions).hasSize(2); assertThatProcessDefinitionsWereDeployedAt(processDefinitions, timeAtDeploymentOne); processDefinitions = repositoryService.createProcessDefinitionQuery().deployedAt(timeAtDeploymentTwo).list(); assertThat(processDefinitions).hasSize(1); assertThatProcessDefinitionsWereDeployedAt(processDefinitions, timeAtDeploymentTwo); processDefinitions = repositoryService.createProcessDefinitionQuery().deployedAt(timeAtDeploymentThree).list(); assertThat(processDefinitions).hasSize(1); assertThatProcessDefinitionsWereDeployedAt(processDefinitions, timeAtDeploymentThree); processDefinitions = repositoryService.createProcessDefinitionQuery().deployedAt(DateUtils.addSeconds(ClockUtil.getCurrentTime(), 5)).list(); assertThat(processDefinitions).hasSize(0); }
Example 18
Source File: Time.java From camunda-bpm-assert-scenario with Apache License 2.0 | 4 votes |
public static void set(Date time) { Date currentTime = ClockUtil.getCurrentTime(); ClockUtil.setCurrentTime(time); if (!time.equals(currentTime)) Action.FastForward.log(null, null, null, null, null, null, null); }
Example 19
Source File: EventSubscriptionEntity.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
public EventSubscriptionEntity(EventType eventType) { this.created = ClockUtil.getCurrentTime(); this.eventType = eventType.name(); }
Example 20
Source File: Time.java From camunda-bpm-assert-scenario with Apache License 2.0 | 4 votes |
public static Date get() { return ClockUtil.getCurrentTime(); }