Search in sources :

Example 1 with CloudBPMNTimerScheduledEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent in project activiti-cloud by Activiti.

the class AuditServiceIT method shouldGetTimerScheduledEvent.

@Test
public void shouldGetTimerScheduledEvent() {
    // given
    List<CloudRuntimeEvent> coveredEvents = new ArrayList<>();
    BPMNTimerImpl timer1 = new BPMNTimerImpl("timerId1");
    timer1.setProcessDefinitionId("processDefinitionId");
    timer1.setProcessInstanceId("processInstanceId");
    timer1.setTimerPayload(createTimerPayload());
    CloudBPMNTimerFiredEventImpl cloudTimerFiredEvent = new CloudBPMNTimerFiredEventImpl("eventId1", System.currentTimeMillis(), timer1, timer1.getProcessDefinitionId(), timer1.getProcessInstanceId());
    coveredEvents.add(cloudTimerFiredEvent);
    BPMNTimerImpl timer2 = new BPMNTimerImpl("timerId2");
    timer2.setProcessDefinitionId("processDefinitionId");
    timer2.setProcessInstanceId("processInstanceId");
    timer2.setTimerPayload(createTimerPayload());
    CloudBPMNTimerScheduledEventImpl cloudTimerScheduledEvent = new CloudBPMNTimerScheduledEventImpl("eventId2", System.currentTimeMillis(), timer2, timer2.getProcessDefinitionId(), timer2.getProcessInstanceId());
    coveredEvents.add(cloudTimerScheduledEvent);
    producer.send(coveredEvents.toArray(new CloudRuntimeEvent[coveredEvents.size()]));
    await().untilAsserted(() -> {
        // when
        Map<String, Object> filters = new HashMap<>();
        filters.put("eventType", BPMNTimerEvent.TimerEvents.TIMER_SCHEDULED.name());
        ResponseEntity<PagedResources<CloudRuntimeEvent>> eventsPagedResources = eventsRestTemplate.executeFind(filters);
        // then
        Collection<CloudRuntimeEvent> retrievedEvents = eventsPagedResources.getBody().getContent();
        assertThat(retrievedEvents).hasSize(1);
        assertThat(retrievedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getServiceName, CloudRuntimeEvent::getServiceVersion, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getEntityId, event -> ((CloudBPMNTimerScheduledEvent) event).getEntity().getElementId(), event -> ((CloudBPMNTimerScheduledEvent) event).getEntity().getProcessInstanceId(), event -> ((CloudBPMNTimerScheduledEvent) event).getEntity().getProcessDefinitionId(), event -> ((CloudBPMNTimerScheduledEvent) event).getEntity().getTimerPayload().getId(), event -> ((CloudBPMNTimerScheduledEvent) event).getEntity().getTimerPayload().getMaxIterations(), event -> ((CloudBPMNTimerScheduledEvent) event).getEntity().getTimerPayload().getRepeat(), event -> ((CloudBPMNTimerScheduledEvent) event).getEntity().getTimerPayload().getRetries()).contains(tuple(cloudTimerScheduledEvent.getEventType(), cloudTimerScheduledEvent.getServiceName(), cloudTimerScheduledEvent.getServiceVersion(), cloudTimerScheduledEvent.getProcessInstanceId(), cloudTimerScheduledEvent.getProcessDefinitionId(), cloudTimerScheduledEvent.getEntityId(), cloudTimerScheduledEvent.getEntity().getElementId(), cloudTimerScheduledEvent.getEntity().getProcessInstanceId(), cloudTimerScheduledEvent.getEntity().getProcessDefinitionId(), cloudTimerScheduledEvent.getEntity().getTimerPayload().getId(), cloudTimerScheduledEvent.getEntity().getTimerPayload().getMaxIterations(), cloudTimerScheduledEvent.getEntity().getTimerPayload().getRepeat(), cloudTimerScheduledEvent.getEntity().getTimerPayload().getRetries()));
    });
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) CloudMessageSubscriptionCancelledEvent(org.activiti.cloud.api.process.model.events.CloudMessageSubscriptionCancelledEvent) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CloudTaskCreatedEventImpl(org.activiti.cloud.api.task.model.impl.events.CloudTaskCreatedEventImpl) IgnoredRuntimeEvent(org.activiti.cloud.api.model.shared.impl.conf.IgnoredRuntimeEvent) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) CloudProcessStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl) CloudProcessCompletedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessCompletedEventImpl) CloudTaskCandidateUserAddedEventImpl(org.activiti.cloud.api.task.model.impl.events.CloudTaskCandidateUserAddedEventImpl) Autowired(org.springframework.beans.factory.annotation.Autowired) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) PagedResources(org.springframework.hateoas.PagedResources) Map(java.util.Map) BPMNErrorReceivedEvent(org.activiti.api.process.model.events.BPMNErrorReceivedEvent) CloudIntegrationErrorReceivedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudIntegrationErrorReceivedEventImpl) Awaitility.await(org.awaitility.Awaitility.await) CloudIntegrationResultReceivedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudIntegrationResultReceivedEventImpl) IntegrationContextImpl(org.activiti.api.runtime.model.impl.IntegrationContextImpl) BPMNTimerImpl(org.activiti.api.runtime.model.impl.BPMNTimerImpl) Collection(java.util.Collection) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) CloudBPMNSignalReceivedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNSignalReceivedEventImpl) CloudTaskAssignedEventImpl(org.activiti.cloud.api.task.model.impl.events.CloudTaskAssignedEventImpl) BPMNActivityEvent(org.activiti.api.process.model.events.BPMNActivityEvent) CloudProcessCancelledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessCancelledEventImpl) TestPropertySource(org.springframework.test.context.TestPropertySource) UUID(java.util.UUID) MessageSubscriptionCancelledEvent(org.activiti.api.process.model.events.MessageSubscriptionCancelledEvent) Test(org.junit.jupiter.api.Test) List(java.util.List) CloudRuntimeEventImpl(org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl) CloudProcessSuspendedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessSuspendedEventImpl) CloudTaskCompletedEventImpl(org.activiti.cloud.api.task.model.impl.events.CloudTaskCompletedEventImpl) CloudBPMNErrorReceivedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNErrorReceivedEvent) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessDefinitionImpl(org.activiti.api.runtime.model.impl.ProcessDefinitionImpl) ProcessInstanceImpl(org.activiti.api.runtime.model.impl.ProcessInstanceImpl) CloudBPMNActivityEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityEvent) CloudBPMNActivityCompletedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityCompletedEventImpl) TaskCandidateUserEvent(org.activiti.api.task.model.events.TaskCandidateUserEvent) EventsRepository(org.activiti.cloud.services.audit.jpa.repository.EventsRepository) BPMNSignalImpl(org.activiti.api.runtime.model.impl.BPMNSignalImpl) CloudProcessDeployedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessDeployedEventImpl) TaskCandidateUserImpl(org.activiti.api.task.model.impl.TaskCandidateUserImpl) CloudTaskCancelledEvent(org.activiti.cloud.api.task.model.events.CloudTaskCancelledEvent) HashMap(java.util.HashMap) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) CloudTaskCancelledEventImpl(org.activiti.cloud.api.task.model.impl.events.CloudTaskCancelledEventImpl) ArrayList(java.util.ArrayList) SignalPayload(org.activiti.api.process.model.payloads.SignalPayload) CloudTaskCreatedEvent(org.activiti.cloud.api.task.model.events.CloudTaskCreatedEvent) CloudIntegrationRequestedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudIntegrationRequestedEventImpl) CloudTaskCandidateUserRemovedEventImpl(org.activiti.cloud.api.task.model.impl.events.CloudTaskCandidateUserRemovedEventImpl) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) CloudBPMNTimerScheduledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent) CloudBPMNSignalReceivedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNSignalReceivedEvent) CloudProcessUpdatedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessUpdatedEventImpl) MyProducer(org.activiti.cloud.starters.test.MyProducer) Assertions.tuple(org.assertj.core.api.Assertions.tuple) CloudBPMNActivityStartedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent) Import(org.springframework.context.annotation.Import) BPMNActivityImpl(org.activiti.api.runtime.model.impl.BPMNActivityImpl) CloudBPMNActivityCancelledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityCancelledEventImpl) TimerPayload(org.activiti.api.process.model.payloads.TimerPayload) BPMNErrorImpl(org.activiti.api.runtime.model.impl.BPMNErrorImpl) CloudTaskAssignedEvent(org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent) CloudTaskUpdatedEventImpl(org.activiti.cloud.api.task.model.impl.events.CloudTaskUpdatedEventImpl) CloudBPMNActivityStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNActivityStartedEventImpl) CloudBPMNTimerScheduledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerScheduledEventImpl) CloudBPMNErrorReceivedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNErrorReceivedEventImpl) CloudBPMNTimerFiredEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerFiredEventImpl) ResponseEntity(org.springframework.http.ResponseEntity) MessageSubscriptionImpl(org.activiti.api.runtime.model.impl.MessageSubscriptionImpl) Collections(java.util.Collections) CloudMessageSubscriptionCancelledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudMessageSubscriptionCancelledEventImpl) HashMap(java.util.HashMap) PagedResources(org.springframework.hateoas.PagedResources) ArrayList(java.util.ArrayList) CloudBPMNTimerScheduledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerScheduledEventImpl) CloudBPMNTimerFiredEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerFiredEventImpl) BPMNTimerImpl(org.activiti.api.runtime.model.impl.BPMNTimerImpl) CloudBPMNTimerScheduledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with CloudBPMNTimerScheduledEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent in project activiti-cloud by Activiti.

the class MapBuilder method testGraphqlSubscriptionCloudBPMNTimerEvents.

@Test
public void testGraphqlSubscriptionCloudBPMNTimerEvents() throws JsonProcessingException {
    ReplayProcessor<String> data = ReplayProcessor.create();
    keycloakTokenProducer.setKeycloakTestUser(TESTADMIN);
    final String auth = keycloakTokenProducer.authorizationHeaders().getFirst(AUTHORIZATION);
    Map<String, Object> variables = new StringObjectMapBuilder().put("appName", "default-app").put("eventTypes", Arrays.array("TIMER_SCHEDULED", "TIMER_FIRED", "TIMER_EXECUTED", "TIMER_CANCELLED", "TIMER_FAILED", "TIMER_RETRIES_DECREMENTED")).get();
    Map<String, Object> payload = new StringObjectMapBuilder().put("query", "subscription($appName: String!, $eventTypes: [EngineEventType!]) { " + "  engineEvents(appName: [$appName], eventType: $eventTypes) { " + "    processInstanceId " + "    processDefinitionId " + "    entity " + "    eventType " + "  } " + "}").put("variables", variables).get();
    GraphQLMessage start = GraphQLMessage.builder().type(GraphQLMessageType.START).id("1").payload(payload).build();
    String startMessage = objectMapper.writeValueAsString(start);
    // given
    CloudBPMNTimerScheduledEvent event1 = new CloudBPMNTimerScheduledEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerFiredEvent event2 = new CloudBPMNTimerFiredEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerExecutedEvent event3 = new CloudBPMNTimerExecutedEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerCancelledEvent event4 = new CloudBPMNTimerCancelledEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerFailedEvent event5 = new CloudBPMNTimerFailedEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    // given
    CloudBPMNTimerRetriesDecrementedEvent event6 = new CloudBPMNTimerRetriesDecrementedEventImpl("id", new Date().getTime(), new BPMNTimerImpl("timerId"), "processDefinitionId", "processInstanceId") {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    WebsocketSender client = HttpClient.create().baseUrl("ws://localhost:" + port).wiretap(true).headers(h -> h.add(AUTHORIZATION, auth)).websocket(GRAPHQL_WS).uri(WS_GRAPHQL_URI);
    // start subscription
    client.handle((i, o) -> {
        o.options(NettyPipeline.SendOptions::flushOnEach).sendString(Mono.just(startMessage)).then().log("start").subscribe();
        return i.receive().asString().log("data").take(1).doOnSubscribe(s -> producerChannel.output().send(MessageBuilder.withPayload(Arrays.array(event1, event2, event3, event4, event5, event6)).setHeader("routingKey", "eventProducer").build())).delaySubscription(Duration.ofSeconds(1)).subscribeWith(data);
    }).collectList().subscribe();
    // then
    Map<String, Object> message = Maps.of("data", Maps.of("engineEvents", Arrays.array(mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_SCHEDULED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_FIRED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_EXECUTED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_CANCELLED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_FAILED").get(), mapBuilder().put("processInstanceId", "processInstanceId").put("processDefinitionId", "processDefinitionId").put("entity", new BPMNTimerImpl("timerId")).put("eventType", "TIMER_RETRIES_DECREMENTED").get())));
    String dataMessage = objectMapper.writeValueAsString(GraphQLMessage.builder().type(GraphQLMessageType.DATA).id("1").payload(message).build());
    StepVerifier.create(data).expectNext(dataMessage).expectComplete().verify(TIMEOUT);
}
Also used : CloudBPMNTimerExecutedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerExecutedEvent) CloudBPMNTimerCancelledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerCancelledEventImpl) CloudBPMNTimerScheduledEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerScheduledEventImpl) CloudBPMNTimerRetriesDecrementedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerRetriesDecrementedEventImpl) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Date(java.util.Date) CloudBPMNTimerRetriesDecrementedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerRetriesDecrementedEvent) CloudBPMNTimerFailedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerFailedEventImpl) CloudBPMNTimerFiredEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerFiredEventImpl) CloudBPMNTimerFailedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerFailedEvent) CloudBPMNTimerExecutedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerExecutedEventImpl) CloudBPMNTimerScheduledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent) BPMNTimerImpl(org.activiti.api.runtime.model.impl.BPMNTimerImpl) CloudBPMNTimerFiredEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerFiredEvent) CloudBPMNTimerCancelledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerCancelledEvent) WebsocketSender(reactor.netty.http.client.HttpClient.WebsocketSender) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with CloudBPMNTimerScheduledEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent in project activiti-cloud by Activiti.

the class ToCloudProcessRuntimeTimerEventsConverterTest method shouldConvertBPMNTimerScheduledEventToCloudBPMNTimerScheduledEvent.

@Test
public void shouldConvertBPMNTimerScheduledEventToCloudBPMNTimerScheduledEvent() {
    // given
    BPMNTimerImpl timer = new BPMNTimerImpl("entityId");
    timer.setProcessInstanceId("procInstId");
    timer.setProcessDefinitionId("procDefId");
    TimerPayload timerPayload = new TimerPayload();
    timer.setTimerPayload(timerPayload);
    BPMNTimerScheduledEventImpl timerFiredEvent = new BPMNTimerScheduledEventImpl(timer);
    // when
    CloudBPMNTimerScheduledEvent cloudEvent = converter.from(timerFiredEvent);
    assertThat(cloudEvent.getEntity()).isEqualTo(timer);
    assertThat(cloudEvent.getProcessDefinitionId()).isEqualTo("procDefId");
    assertThat(cloudEvent.getProcessInstanceId()).isEqualTo("procInstId");
    // then
    verify(runtimeBundleInfoAppender).appendRuntimeBundleInfoTo(any(CloudRuntimeEventImpl.class));
}
Also used : CloudRuntimeEventImpl(org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl) BPMNTimerImpl(org.activiti.api.runtime.model.impl.BPMNTimerImpl) CloudBPMNTimerScheduledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent) BPMNTimerScheduledEventImpl(org.activiti.api.runtime.event.impl.BPMNTimerScheduledEventImpl) TimerPayload(org.activiti.api.process.model.payloads.TimerPayload) Test(org.junit.jupiter.api.Test)

Example 4 with CloudBPMNTimerScheduledEvent

use of org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent in project activiti-cloud by Activiti.

the class TimerAuditProducerIT method shouldProduceEventsForIntermediateTimerEvent.

@Test
public void shouldProduceEventsForIntermediateTimerEvent() {
    logger.info("Async config: " + asyncExecutor.getDefaultTimerJobAcquireWaitTimeInMillis());
    // given
    Date startTime = new Date();
    ResponseEntity<CloudProcessInstance> startProcessEntity = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(PROCESS_INTERMEDIATE_TIMER_EVENT).withName("processInstanceName").withBusinessKey("businessKey").build());
    // when
    await().untilAsserted(() -> {
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(RUNTIME_BUNDLE_INFO_HEADERS);
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
        List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getLatestReceivedEvents();
        assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getEntityId).contains(tuple(ACTIVITY_STARTED, "timer"), tuple(BPMNTimerEvent.TimerEvents.TIMER_SCHEDULED, "timer"));
        List<CloudBPMNTimerScheduledEvent> timerEvents = receivedEvents.stream().filter(CloudBPMNTimerScheduledEvent.class::isInstance).map(CloudBPMNTimerScheduledEvent.class::cast).collect(Collectors.toList());
        assertThat(timerEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getBusinessKey, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getProcessDefinitionVersion, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntityId()).contains(tuple(BPMNTimerEvent.TimerEvents.TIMER_SCHEDULED, "businessKey", startProcessEntity.getBody().getProcessDefinitionId(), startProcessEntity.getBody().getId(), startProcessEntity.getBody().getProcessDefinitionKey(), startProcessEntity.getBody().getProcessDefinitionVersion(), startProcessEntity.getBody().getProcessDefinitionId(), startProcessEntity.getBody().getId(), "timer"));
    });
    // when
    long waitTime = 5 * 60 * 1000;
    Date dueDate = new Date(startTime.getTime() + waitTime);
    // After setting the clock to time '5minutes and 5 seconds', the second timer should fire
    processEngineConfiguration.getClock().setCurrentTime(new Date(dueDate.getTime() + 5000));
    // when
    await().untilAsserted(() -> {
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(RUNTIME_BUNDLE_INFO_HEADERS);
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
        List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getLatestReceivedEvents();
        assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getEntityId).contains(tuple(BPMNTimerEvent.TimerEvents.TIMER_FIRED, "timer"), tuple(BPMNTimerEvent.TimerEvents.TIMER_EXECUTED, "timer"), tuple(ACTIVITY_COMPLETED, "timer"));
        List<CloudBPMNTimerEvent> timerEvents = receivedEvents.stream().filter(event -> (CloudBPMNTimerFiredEvent.class.isInstance(event) || CloudBPMNTimerExecutedEvent.class.isInstance(event))).map(CloudBPMNTimerEvent.class::cast).collect(Collectors.toList());
        assertThat(timerEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getBusinessKey, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getProcessDefinitionVersion, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntityId()).containsOnly(tuple(BPMNTimerEvent.TimerEvents.TIMER_FIRED, "businessKey", startProcessEntity.getBody().getProcessDefinitionId(), startProcessEntity.getBody().getId(), startProcessEntity.getBody().getProcessDefinitionKey(), startProcessEntity.getBody().getProcessDefinitionVersion(), startProcessEntity.getBody().getProcessDefinitionId(), startProcessEntity.getBody().getId(), "timer"), tuple(BPMNTimerEvent.TimerEvents.TIMER_EXECUTED, "businessKey", startProcessEntity.getBody().getProcessDefinitionId(), startProcessEntity.getBody().getId(), startProcessEntity.getBody().getProcessDefinitionKey(), startProcessEntity.getBody().getProcessDefinitionVersion(), startProcessEntity.getBody().getProcessDefinitionId(), startProcessEntity.getBody().getId(), "timer"));
    });
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) DirtiesContext(org.springframework.test.annotation.DirtiesContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ALL_REQUIRED_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) ArrayList(java.util.ArrayList) TestConfiguration(org.springframework.boot.test.context.TestConfiguration) JavaDelegate(org.activiti.engine.delegate.JavaDelegate) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) CloudBPMNTimerCancelledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerCancelledEvent) CloudBPMNTimerScheduledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent) Awaitility.await(org.awaitility.Awaitility.await) Logger(org.slf4j.Logger) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TestPropertySource(org.springframework.test.context.TestPropertySource) Profile(org.springframework.context.annotation.Profile) Collectors(java.util.stream.Collectors) CloudBPMNTimerExecutedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerExecutedEvent) Test(org.junit.jupiter.api.Test) CloudBPMNTimerEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerEvent) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) ProcessEngineConfigurationConfigurer(org.activiti.spring.boot.ProcessEngineConfigurationConfigurer) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ResponseEntity(org.springframework.http.ResponseEntity) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudBPMNTimerFiredEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerFiredEvent) RUNTIME_BUNDLE_INFO_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS) CloudBPMNTimerExecutedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerExecutedEvent) CloudBPMNTimerEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerEvent) Date(java.util.Date) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudBPMNTimerScheduledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent) CloudBPMNTimerFiredEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerFiredEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CloudBPMNTimerScheduledEvent (org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent)4 Test (org.junit.jupiter.api.Test)4 BPMNTimerImpl (org.activiti.api.runtime.model.impl.BPMNTimerImpl)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 BPMNTimerEvent (org.activiti.api.process.model.events.BPMNTimerEvent)2 TimerPayload (org.activiti.api.process.model.payloads.TimerPayload)2 CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)2 CloudRuntimeEventImpl (org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl)2 CloudBPMNTimerFiredEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerFiredEventImpl)2 CloudBPMNTimerScheduledEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudBPMNTimerScheduledEventImpl)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1