Ejemplo n.º 1
0
        public async Task <ProcessStartResponsePayload> StartProcessInstance <TInputValues>(
            IIdentity identity,
            string processModelId,
            string startEventId,
            ProcessStartRequestPayload <TInputValues> processStartRequestPayload,
            StartCallbackType callbackType = StartCallbackType.CallbackOnProcessInstanceCreated,
            string endEventId = "")
            where TInputValues : new()
        {
            if (identity == null)
            {
                throw new UnauthorizedAccessException(nameof(identity));
            }

            var noEndEventIdProvided = callbackType == StartCallbackType.CallbackOnEndEventReached &&
                                       String.IsNullOrEmpty(endEventId);

            if (noEndEventIdProvided)
            {
                throw new ArgumentNullException(nameof(endEventId));
            }

            var endpoint = RestSettings.Paths.StartProcessInstance
                           .Replace(RestSettings.Params.ProcessModelId, processModelId);

            var urlWithEndpoint = this.ApplyBaseUrl(endpoint);

            var urlWithParams = $"{RestSettings.Endpoints.ConsumerAPI}{endpoint}?start_callback_type={(int)callbackType}";

            var startEventIdProvided = !String.IsNullOrEmpty(startEventId);

            if (startEventIdProvided)
            {
                urlWithParams = $"{urlWithParams}&start_event_id={startEventId}";
            }

            var attachEndEventId = callbackType == StartCallbackType.CallbackOnEndEventReached;

            if (attachEndEventId)
            {
                urlWithParams = $"{urlWithParams}&end_event_id={endEventId}";
            }

            var jsonResult = "";

            var jsonPayload    = SerializeForProcessEngine(processStartRequestPayload);
            var requestContent = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
            var request        = this.CreateRequestMessage(identity, HttpMethod.Post, urlWithParams, requestContent);
            var result         = await this.httpClient.SendAsync(request);

            if (result.IsSuccessStatusCode)
            {
                jsonResult = await result.Content.ReadAsStringAsync();

                var parsedResult = JsonConvert.DeserializeObject <ProcessStartResponsePayload>(jsonResult);
                return(parsedResult);
            }

            throw new Exception("Process could not be started.");
        }
        public async Task BPMN_GetEventsForCorrelationTests_ShouldFetchEventsOfRunningProcess()
        {
            var processModelId = "test_consumer_api_message_event";
            var messageName    = "test_message_event";

            var requestPayload = new ProcessStartRequestPayload <object>();

            ProcessStartResponsePayload processStartResponsePayload = await this
                                                                      .fixture
                                                                      .ConsumerAPIClient
                                                                      .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", requestPayload);

            await Task.Delay(1000);

            var events = await this
                         .fixture
                         .ConsumerAPIClient
                         .GetEventsForCorrelation(this.fixture.DefaultIdentity, processStartResponsePayload.CorrelationId);

            Assert.NotEmpty(events.Events);

            var fetchedEvent = events.Events.ElementAt(0);

            Assert.Equal(fetchedEvent.EventName, messageName);
        }
        public async Task BPMN_TriggerSignalEvent_ShouldContinueProcessWithSignalIntermediateCatchEvent()
        {
            string processModelId = "test_consumer_api_signal_event";
            string signalName     = "test_signal_event";

            var requestPayload = new ProcessStartRequestPayload <object>();

            ProcessStartResponsePayload processStartResponsePayload = await this
                                                                      .fixture
                                                                      .ConsumerAPIClient
                                                                      .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", requestPayload);

            await Task.Delay(5000);

            await this.fixture.ConsumerAPIClient.TriggerSignalEvent(this.fixture.DefaultIdentity, signalName);

            await Task.Delay(5000);

            var processResult = await this
                                .fixture
                                .ConsumerAPIClient
                                .GetProcessResultForCorrelation <object>(this.fixture.DefaultIdentity, processStartResponsePayload.CorrelationId, processModelId);

            Assert.NotEmpty(processResult.CorrelationResults);
        }
Ejemplo n.º 4
0
        public async Task BPMN_GetProcessResultForCorrelation_ShouldGetResultOfStaticProcess()
        {
            var processModelId = "test_consumer_api_correlation_result";
            var endEventId     = "EndEvent_Success";
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnEndEventReached;

            ProcessStartResponsePayload processInstance = await this
                                                          .fixture
                                                          .ConsumerAPIClient
                                                          .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload, callbackType, endEventId);

            var correlationResults = await this
                                     .fixture
                                     .ConsumerAPIClient
                                     .GetProcessResultForCorrelation <TestResult>(this.fixture.DefaultIdentity, processInstance.CorrelationId, processModelId);

            var expectedCorrelationResult = new CorrelationResult <TestResult>
            {
                TokenPayload = new TestResult()
                {
                    scriptOutput = "hello world"
                },
                CorrelationId = processInstance.CorrelationId,
                EndEventId    = endEventId
            };

            var actualCorrelationResult = new List <CorrelationResult <TestResult> >(correlationResults.CorrelationResults).FirstOrDefault();

            Assert.NotNull(actualCorrelationResult);

            Assert.Equal(expectedCorrelationResult.CorrelationId, actualCorrelationResult.CorrelationId);
            Assert.Equal(expectedCorrelationResult.EndEventId, actualCorrelationResult.EndEventId);
            Assert.Equal(expectedCorrelationResult.TokenPayload.scriptOutput, actualCorrelationResult.TokenPayload.scriptOutput);
        }
Ejemplo n.º 5
0
        public async Task BPMN_FinishEmptyActivity_ShouldFinishEmptyActivity()
        {
            var processModelId = "test_consumer_api_emptyactivity";
            var identity       = this.fixture.DefaultIdentity;
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnProcessInstanceCreated;

            var processInstance = await this
                                  .fixture
                                  .ConsumerAPIClient
                                  .StartProcessInstance(identity, processModelId, "StartEvent_1", payload, callbackType);

            // Give the ProcessEngine time to reach the EmptyActivity
            await Task.Delay(1000);

            var emptyActivities = await this
                                  .fixture
                                  .ConsumerAPIClient
                                  .GetEmptyActivitiesForCorrelation(identity, processInstance.CorrelationId);

            Assert.NotEmpty(emptyActivities.EmptyActivities);

            var emptyActivityToBeFinished = emptyActivities.EmptyActivities.ElementAt(0);

            await this
            .fixture
            .ConsumerAPIClient
            .FinishEmptyActivity(
                identity,
                processInstance.ProcessInstanceId,
                processInstance.CorrelationId,
                emptyActivityToBeFinished.FlowNodeInstanceId
                );
        }
Ejemplo n.º 6
0
        public async Task BPMN_FinishManualTask_ShouldFinishManualTask()
        {
            var processModelId = "test_consumer_api_manualtask";
            var identity       = this.fixture.DefaultIdentity;
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnProcessInstanceCreated;

            ProcessStartResponsePayload processInstance = await this
                                                          .fixture
                                                          .ConsumerAPIClient
                                                          .StartProcessInstance(identity, processModelId, "StartEvent_1", payload, callbackType);

            // Give the ProcessEngine time to reach the ManualTask
            await Task.Delay(1000);

            ManualTaskList manualTasks = await this
                                         .fixture
                                         .ConsumerAPIClient
                                         .GetManualTasksForCorrelation(identity, processInstance.CorrelationId);

            Assert.NotEmpty(manualTasks.ManualTasks);

            var manualTaskToBeFinished = manualTasks.ManualTasks.ElementAt(0);

            await this
            .fixture
            .ConsumerAPIClient
            .FinishManualTask(
                identity,
                processInstance.ProcessInstanceId,
                processInstance.CorrelationId,
                manualTaskToBeFinished.FlowNodeInstanceId
                );
        }
        public void StartProcessInstance_EmptyParameters_ShouldThrowException()
        {
            var payload = new ProcessStartRequestPayload <object>();

            Assert.ThrowsAsync <ArgumentNullException>(async() => await this
                                                       .fixture
                                                       .ConsumerAPIClient
                                                       .StartProcessInstance(this.fixture.DefaultIdentity, "", "Test", payload));
        }
        public void StartProcessInstance_ProcessModelNotFound_ShouldThrowException()
        {
            var payload = new ProcessStartRequestPayload <object>();

            Assert.ThrowsAsync <Exception>(async() => await this
                                           .fixture
                                           .ConsumerAPIClient
                                           .StartProcessInstance(this.fixture.DefaultIdentity, "Test", "Test", payload));
        }
        public async Task BPMN_StartProcessInstance_ShouldCreateAndFinishProcess()
        {
            var processModelId = "test_start_process";
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnEndEventReached;

            ProcessStartResponsePayload processInstance = await this
                                                          .fixture
                                                          .ConsumerAPIClient
                                                          .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload, callbackType, "EndEvent_1");
        }
Ejemplo n.º 10
0
        static internal ProcessStartRequestPayload <StartPayload> CreatePayload(string inputText)
        {
            StartPayload startPayload = new StartPayload();

            startPayload.InputProperty = inputText;

            var processStartPayload = new ProcessStartRequestPayload <StartPayload>();

            processStartPayload.InputValues = startPayload;

            return(processStartPayload);
        }
        public async Task BPMN_StartProcessInstance_ShouldCreateCorrelationIdIfNoneProvided()
        {
            var processModelId = "test_start_process";
            var payload        = new ProcessStartRequestPayload <object>();

            ProcessStartResponsePayload processStartResponsePayload = await this
                                                                      .fixture
                                                                      .ConsumerAPIClient
                                                                      .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload);

            Assert.NotEmpty(processStartResponsePayload.CorrelationId);
        }
        public async Task BPMN_StartProcessInstance_ShouldCreateProcessWithDistinctCorrelationId()
        {
            var processModelId = "test_start_process";
            var correlationId  = "CorrelationId_1";
            var payload        = new ProcessStartRequestPayload <object>
            {
                CorrelationId = correlationId
            };

            ProcessStartResponsePayload processStartResponsePayload = await this
                                                                      .fixture
                                                                      .ConsumerAPIClient
                                                                      .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload);

            Assert.Equal(processStartResponsePayload.CorrelationId, correlationId);
        }
Ejemplo n.º 13
0
        public async Task BPMN_GetWaitingEmptyActivitiesByIdentity_ShouldFetchEmptyActivityList()
        {
            var processModelId = "test_consumer_api_emptyactivity";
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnProcessInstanceCreated;

            var processInstance = await this
                                  .fixture
                                  .ConsumerAPIClient
                                  .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload, callbackType);

            // Give the ProcessEngine time to reach the EmptyActivity
            await Task.Delay(2000);

            var emptyActivities = await this.fixture.ConsumerAPIClient.GetWaitingEmptyActivitiesByIdentity(this.fixture.DefaultIdentity);

            Assert.NotEmpty(emptyActivities.EmptyActivities);
        }
        public async Task BPMN_GetProcessInstancesByIdentity_ShouldGetProcessInstances()
        {
            var processModelId = "test_consumer_api_correlation_result";
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnProcessInstanceFinished;

            var processInstance = await this
                                  .fixture
                                  .ConsumerAPIClient
                                  .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload, callbackType);

            var processInstances = await this
                                   .fixture
                                   .ConsumerAPIClient
                                   .GetProcessInstancesByIdentity(this.fixture.DefaultIdentity);

            Assert.NotNull(processInstances.ProcessInstances);
        }
        public async Task BPMN_GetWaitingManualTasksByIdentity_ShouldFetchManualTaskList()
        {
            var processModelId = "test_consumer_api_manualtask";
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnProcessInstanceCreated;

            ProcessStartResponsePayload processInstance = await this
                                                          .fixture
                                                          .ConsumerAPIClient
                                                          .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload, callbackType);

            // Give the ProcessEngine time to reach the ManualTask
            await Task.Delay(2000);

            ManualTaskList manualTasks = await this.fixture.ConsumerAPIClient.GetWaitingManualTasksByIdentity(this.fixture.DefaultIdentity);

            Assert.NotEmpty(manualTasks.ManualTasks);
        }
Ejemplo n.º 16
0
        public async Task BPMN_GetUserTasksForCorrelation_ShouldFetchUserTaskList()
        {
            var processModelId = "test_consumer_api_usertask";
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnProcessInstanceCreated;

            ProcessStartResponsePayload processInstance = await this
                                                          .fixture
                                                          .ConsumerAPIClient
                                                          .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload, callbackType);

            // Give the ProcessEngine time to reach the UserTask
            await Task.Delay(1000);

            UserTaskList userTasks = await this
                                     .fixture
                                     .ConsumerAPIClient
                                     .GetUserTasksForCorrelation(this.fixture.DefaultIdentity, processInstance.CorrelationId);

            Assert.NotEmpty(userTasks.UserTasks);
        }
Ejemplo n.º 17
0
        public async Task BPMN_FinishUserTask_ShouldFinishUserTask()
        {
            var processModelId = "test_consumer_api_usertask";
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnProcessInstanceCreated;

            ProcessStartResponsePayload processInstance = await this
                                                          .fixture
                                                          .ConsumerAPIClient
                                                          .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload, callbackType);

            // Give the ProcessEngine time to reach the UserTask
            await Task.Delay(5000);

            UserTaskList userTasks = await this
                                     .fixture
                                     .ConsumerAPIClient
                                     .GetUserTasksForCorrelation(this.fixture.DefaultIdentity, processInstance.CorrelationId);

            Assert.NotEmpty(userTasks.UserTasks);

            var userTaskToBeFinished = userTasks.UserTasks.ElementAt(0);
            var userTaskResult       = new UserTaskResult()
            {
                FormFields = new Dictionary <string, object>()
            };

            userTaskResult.FormFields.Add("my_test_key", "my_test_value");

            await this
            .fixture
            .ConsumerAPIClient
            .FinishUserTask(
                this.fixture.DefaultIdentity,
                processInstance.ProcessInstanceId,
                processInstance.CorrelationId,
                userTaskToBeFinished.FlowNodeInstanceId,
                userTaskResult
                );
        }
Ejemplo n.º 18
0
        static async Task StartProcess()
        {
            ConsumerApiClientService client = Program.CreateConsumerClient("http://localhost:8000");

            ProcessStartRequestPayload <StartPayload> payload = Program.CreatePayload("Dies ist die Eingabe für den Prozess aus DotNet.");

            IIdentity identity = CreateIdentity();

            Console.WriteLine($"Prozess gestartet '{PROCESS_MODEL_ID}' mit Start-Event '{START_EVENT_ID}'.");

            ProcessStartResponsePayload result = await client.StartProcessInstance <StartPayload>(
                identity,
                PROCESS_MODEL_ID,
                START_EVENT_ID,
                payload,
                StartCallbackType.CallbackOnEndEventReached,
                END_EVENT_ID);

            Console.WriteLine($"Prozess beendet (CorrelationId: '{result.CorrelationId}').");
            Console.Write("Daten: ");
            Console.WriteLine(result.TokenPayload);
        }
Ejemplo n.º 19
0
        public async Task <ProcessStartResponse <TResponsePayload> > StartProcessInstance <TRequestPayload, TResponsePayload>(
            string processModelId,
            string startEventId,
            ProcessStartRequest <TRequestPayload> request,
            StartCallbackType startCallbackType = StartCallbackType.CallbackOnProcessInstanceCreated,
            string endEventId = ""
            )
            where TRequestPayload : new()
            where TResponsePayload : new()
        {
            var noEndEventIdProvided = startCallbackType == StartCallbackType.CallbackOnEndEventReached &&
                                       String.IsNullOrEmpty(endEventId);

            if (noEndEventIdProvided)
            {
                throw new ArgumentNullException(nameof(endEventId), "Must provide an EndEventId, when using callback type 'CallbackOnEndEventReached'!");
            }

            var payload = new ProcessStartRequestPayload <TRequestPayload>();

            payload.CallerId      = request.ParentProcessInstanceId;
            payload.CorrelationId = request.CorrelationId;
            payload.InputValues   = request.Payload;

            var url = this.BuildStartProcessInstanceUrl(processModelId, startEventId, endEventId, startCallbackType);

            var response = await this.HttpFacade.SendRequestAndExpectResult <ProcessStartRequestPayload <TRequestPayload>, ProcessStartResponsePayload>(HttpMethod.Post, url, payload);

            var parsedResponse = new ProcessStartResponse <TResponsePayload>(
                response.ProcessInstanceId,
                response.CorrelationId,
                response.EndEventId,
                (TResponsePayload)response.TokenPayload
                );

            return(parsedResponse);
        }
Ejemplo n.º 20
0
        public async Task BPMN_GetProcessModelByProcessInstanceId_ShouldGetProcessModel()
        {
            var processModelId = "test_consumer_api_correlation_result";
            var payload        = new ProcessStartRequestPayload <object>();
            var callbackType   = StartCallbackType.CallbackOnProcessInstanceFinished;

            var processStartResponsePayload = await this
                                              .fixture
                                              .ConsumerAPIClient
                                              .StartProcessInstance(this.fixture.DefaultIdentity, processModelId, "StartEvent_1", payload, callbackType);

            Assert.NotNull(processStartResponsePayload);

            var processModel = await this
                               .fixture
                               .ConsumerAPIClient
                               .GetProcessModelByProcessInstanceId(this.fixture.DefaultIdentity, processStartResponsePayload.ProcessInstanceId);

            Assert.NotNull(processModel);

            Assert.Equal(processModelId, processModel.ID);
            Assert.Equal("StartEvent_1", processModel.StartEvents.ToList()[0].Id);
            Assert.Equal("EndEvent_Success", processModel.EndEvents.ToList()[0].Id);
        }