Search in sources :

Example 6 with ProcessRuntimeConfiguration

use of org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration in project Activiti by Activiti.

the class ProcessExtensionsJsonVarsTest method processInstanceFailsIfVariableTypeIncorrect.

@Test
public void processInstanceFailsIfVariableTypeIncorrect() {
    securityUtil.logInAs("user");
    ProcessRuntimeConfiguration configuration = processRuntime.configuration();
    assertThat(configuration).isNotNull();
    // by default jackson won't ser empty bean so it can't be handled as json
    assertThat(objectMapper.canSerialize(EmptyBean.class)).isFalse();
    assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
        processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(JSON_VARS_PROCESS).withVariable("var2", new EmptyBean()).withVariable("var5", "this one is ok as doesn't have to be json").build());
    }).withMessage("Variables fail type validation: var2");
// we don't test for bad json in the extension file because the context doesn't load for that scenario as failure is during parsing
}
Also used : ProcessRuntimeConfiguration(org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ProcessRuntimeConfiguration

use of org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration in project Activiti by Activiti.

the class ProcessExtensionsJsonVarsTest method processInstanceFailsIfVariableCannotBeSerializedAsJson.

@Test
public void processInstanceFailsIfVariableCannotBeSerializedAsJson() {
    securityUtil.logInAs("user");
    ProcessRuntimeConfiguration configuration = processRuntime.configuration();
    assertThat(configuration).isNotNull();
    // var5 doesn't ave any defined type as not in the file
    // but it still needs to be serlializable as json because serializePOJOsInVariablesToJson is true, meaning java ser is not available
    // by default jackson won't ser empty bean so it can't be handled as json
    assertThat(objectMapper.canSerialize(EmptyBean.class)).isFalse();
    assertThatExceptionOfType(ActivitiException.class).isThrownBy(() -> {
        processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(JSON_VARS_PROCESS).withVariable("var2", new ObjectMapper().readValue("{ \"testvar2element\":\"testvar2element\"}", JsonNode.class)).withVariable("var5", new EmptyBean()).build());
    }).withMessageStartingWith("couldn't find a variable type that is able to serialize");
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ProcessRuntimeConfiguration(org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ProcessRuntimeConfiguration

use of org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration in project Activiti by Activiti.

the class ProcessRuntimeSecurityPoliciesIT method getRestrictedProcessDefs.

@Test
public void getRestrictedProcessDefs() {
    securityUtil.logInAs("user");
    // @TODO: I should get the security policies defined here.
    ProcessRuntimeConfiguration configuration = processRuntime.configuration();
    assertThat(configuration).isNotNull();
    Page<ProcessDefinition> processDefinitionPage = processRuntime.processDefinitions(Pageable.of(0, 50));
    assertThat(processDefinitionPage.getContent()).isNotNull();
    assertThat(processDefinitionPage.getContent()).hasSize(2);
}
Also used : ProcessDefinition(org.activiti.api.process.model.ProcessDefinition) ProcessRuntimeConfiguration(org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with ProcessRuntimeConfiguration

use of org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration in project Activiti by Activiti.

the class ProcessExtensionsIT method processInstanceFailsWithoutRequiredVariables.

@Test
public void processInstanceFailsWithoutRequiredVariables() {
    ProcessRuntimeConfiguration configuration = processRuntime.configuration();
    assertThat(configuration).isNotNull();
    assertThatExceptionOfType(ActivitiException.class).isThrownBy(() -> {
        processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(INITIAL_VARS_PROCESS).withVariable("extraVar", true).build());
    }).withMessage("Can't start process '" + INITIAL_VARS_PROCESS + "' without required variables - age");
}
Also used : ProcessRuntimeConfiguration(org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with ProcessRuntimeConfiguration

use of org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration in project Activiti by Activiti.

the class ProcessExtensionsIT method processInstanceHasInitialVariables.

@Test
public void processInstanceHasInitialVariables() {
    ProcessRuntimeConfiguration configuration = processRuntime.configuration();
    assertThat(configuration).isNotNull();
    // start a process with vars then check default and specified vars exist
    ProcessInstance initialVarsProcess = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(INITIAL_VARS_PROCESS).withVariable("extraVar", true).withVariable("age", 10).withBusinessKey("my business key").build());
    assertThat(initialVarsProcess).isNotNull();
    assertThat(initialVarsProcess.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
    List<VariableInstance> variableInstances = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(initialVarsProcess).build());
    assertThat(variableInstances).isNotNull();
    assertThat(variableInstances).hasSize(4);
    assertThat(variableInstances).extracting("name").contains("extraVar", "name", "age", "birth").doesNotContain("subscribe");
    // cleanup
    processRuntime.delete(ProcessPayloadBuilder.delete(initialVarsProcess));
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) ProcessRuntimeConfiguration(org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProcessRuntimeConfiguration (org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration)17 Test (org.junit.jupiter.api.Test)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 ProcessRuntimeEventListener (org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener)6 VariableEventListener (org.activiti.api.runtime.shared.events.VariableEventListener)6 ProcessInstance (org.activiti.api.process.model.ProcessInstance)4 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ProcessDefinition (org.activiti.api.process.model.ProcessDefinition)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 SimpleDateFormat (java.text.SimpleDateFormat)1 UpdateProcessPayload (org.activiti.api.process.model.payloads.UpdateProcessPayload)1