Search in sources :

Example 11 with Process

use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.

the class DefinitionsTest method shouldAddParentChildElementInCorrectOrder.

@Test
public void shouldAddParentChildElementInCorrectOrder() {
    // create empty model
    BpmnModelInstance bpmnModelInstance = Bpmn.createEmptyModel();
    // add definitions to model
    Definitions definitions = bpmnModelInstance.newInstance(Definitions.class);
    definitions.setTargetNamespace("Examples");
    bpmnModelInstance.setDefinitions(definitions);
    // add process
    Process process = bpmnModelInstance.newInstance(Process.class);
    process.setId("messageEventDefinition");
    definitions.getRootElements().add(process);
    // add start event
    StartEvent startEvent = bpmnModelInstance.newInstance(StartEvent.class);
    startEvent.setId("theStart");
    process.getFlowElements().add(startEvent);
    // create and add message
    Message message = bpmnModelInstance.newInstance(Message.class);
    message.setId("start-message-id");
    definitions.getRootElements().add(message);
    // add message event definition to start event
    MessageEventDefinition startEventMessageEventDefinition = bpmnModelInstance.newInstance(MessageEventDefinition.class);
    startEventMessageEventDefinition.setMessage(message);
    startEvent.getEventDefinitions().add(startEventMessageEventDefinition);
    // add property after message event definition
    Property property = bpmnModelInstance.newInstance(Property.class);
    startEvent.getProperties().add(property);
    // finally add an extensions element
    ExtensionElements extensionElements = bpmnModelInstance.newInstance(ExtensionElements.class);
    process.setExtensionElements(extensionElements);
    // validate model
    try {
        Bpmn.validateModel(bpmnModelInstance);
    } catch (ModelValidationException e) {
        Assert.fail();
    }
}
Also used : ModelValidationException(org.camunda.bpm.model.xml.ModelValidationException) Process(org.camunda.bpm.model.bpmn.instance.Process) Test(org.junit.Test)

Example 12 with Process

use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.

the class DefinitionsTest method shouldAddMessageAndMessageEventDefinition.

@Test
public void shouldAddMessageAndMessageEventDefinition() {
    // create empty model
    BpmnModelInstance bpmnModelInstance = Bpmn.createEmptyModel();
    // add definitions to model
    Definitions definitions = bpmnModelInstance.newInstance(Definitions.class);
    definitions.setTargetNamespace("Examples");
    bpmnModelInstance.setDefinitions(definitions);
    // create and add message
    Message message = bpmnModelInstance.newInstance(Message.class);
    message.setId("start-message-id");
    definitions.getRootElements().add(message);
    // create and add message event definition
    MessageEventDefinition messageEventDefinition = bpmnModelInstance.newInstance(MessageEventDefinition.class);
    messageEventDefinition.setId("message-event-def-id");
    messageEventDefinition.setMessage(message);
    definitions.getRootElements().add(messageEventDefinition);
    // test if message was set correctly
    Message setMessage = messageEventDefinition.getMessage();
    assertThat(setMessage).isEqualTo(message);
    // add process
    Process process = bpmnModelInstance.newInstance(Process.class);
    process.setId("messageEventDefinition");
    definitions.getRootElements().add(process);
    // add start event
    StartEvent startEvent = bpmnModelInstance.newInstance(StartEvent.class);
    startEvent.setId("theStart");
    process.getFlowElements().add(startEvent);
    // create and add message event definition to start event
    MessageEventDefinition startEventMessageEventDefinition = bpmnModelInstance.newInstance(MessageEventDefinition.class);
    startEventMessageEventDefinition.setMessage(message);
    startEvent.getEventDefinitions().add(startEventMessageEventDefinition);
    // create another message but do not add it
    Message anotherMessage = bpmnModelInstance.newInstance(Message.class);
    anotherMessage.setId("another-message-id");
    // create a message event definition and try to add last create message
    MessageEventDefinition anotherMessageEventDefinition = bpmnModelInstance.newInstance(MessageEventDefinition.class);
    try {
        anotherMessageEventDefinition.setMessage(anotherMessage);
        Assert.fail("Message should not be added to message event definition, cause it is not part of the model");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(ModelReferenceException.class);
    }
    // first add message to model than to event definition
    definitions.getRootElements().add(anotherMessage);
    anotherMessageEventDefinition.setMessage(anotherMessage);
    startEvent.getEventDefinitions().add(anotherMessageEventDefinition);
    // message event definition and add message by id to it
    anotherMessageEventDefinition = bpmnModelInstance.newInstance(MessageEventDefinition.class);
    startEvent.getEventDefinitions().add(anotherMessageEventDefinition);
    // validate model
    try {
        Bpmn.validateModel(bpmnModelInstance);
    } catch (ModelValidationException e) {
        Assert.fail();
    }
}
Also used : ModelValidationException(org.camunda.bpm.model.xml.ModelValidationException) Process(org.camunda.bpm.model.bpmn.instance.Process) ModelReferenceException(org.camunda.bpm.model.xml.ModelReferenceException) IOException(java.io.IOException) ModelValidationException(org.camunda.bpm.model.xml.ModelValidationException) ModelParseException(org.camunda.bpm.model.xml.ModelParseException) ModelReferenceException(org.camunda.bpm.model.xml.ModelReferenceException) Test(org.junit.Test)

Example 13 with Process

use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.

the class DefinitionsTest method shouldNotAffectComments.

@Test
@BpmnModelResource
public void shouldNotAffectComments() throws IOException {
    Definitions definitions = bpmnModelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    // create another Process element and add it to the definitions
    Process process = bpmnModelInstance.newInstance(Process.class);
    process.setId("another-process-id");
    definitions.getRootElements().add(process);
    // create another Import element and add it to the definitions
    Import importElement = bpmnModelInstance.newInstance(Import.class);
    importElement.setNamespace("Imports");
    importElement.setLocation("there");
    importElement.setImportType("example");
    definitions.getImports().add(importElement);
    // validate model
    try {
        Bpmn.validateModel(bpmnModelInstance);
    } catch (ModelValidationException e) {
        Assert.fail();
    }
    // convert the model to the XML string representation
    OutputStream outputStream = new ByteArrayOutputStream();
    Bpmn.writeModelToStream(outputStream, bpmnModelInstance);
    InputStream inputStream = IoUtil.convertOutputStreamToInputStream(outputStream);
    String modelString = IoUtil.getStringFromInputStream(inputStream);
    IoUtil.closeSilently(outputStream);
    IoUtil.closeSilently(inputStream);
    // read test process from file as string
    inputStream = getClass().getResourceAsStream("DefinitionsTest.shouldNotAffectCommentsResult.bpmn");
    String fileString = IoUtil.getStringFromInputStream(inputStream);
    IoUtil.closeSilently(inputStream);
    // compare strings
    assertThat(modelString).endsWith(fileString);
}
Also used : ModelValidationException(org.camunda.bpm.model.xml.ModelValidationException) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Process(org.camunda.bpm.model.bpmn.instance.Process) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BpmnModelResource(org.camunda.bpm.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Example 14 with Process

use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.

the class GenerateIdTest method shouldGenerateIdsOnCreate.

@Test
public void shouldGenerateIdsOnCreate() {
    BpmnModelInstance modelInstance = Bpmn.createEmptyModel();
    Definitions definitions = modelInstance.newInstance(Definitions.class);
    assertThat(definitions.getId()).isNotNull();
    Process process = modelInstance.newInstance(Process.class);
    assertThat(process.getId()).isNotNull();
    StartEvent startEvent = modelInstance.newInstance(StartEvent.class);
    assertThat(startEvent.getId()).isNotNull();
    UserTask userTask = modelInstance.newInstance(UserTask.class);
    assertThat(userTask.getId()).isNotNull();
}
Also used : Definitions(org.camunda.bpm.model.bpmn.instance.Definitions) StartEvent(org.camunda.bpm.model.bpmn.instance.StartEvent) UserTask(org.camunda.bpm.model.bpmn.instance.UserTask) Process(org.camunda.bpm.model.bpmn.instance.Process) Test(org.junit.Test)

Example 15 with Process

use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.

the class CreateModelTest method createProcessWithParallelGateway.

@Test
public void createProcessWithParallelGateway() {
    // create process
    Process process = createElement(definitions, "process-with-parallel-gateway", Process.class);
    // create elements
    StartEvent startEvent = createElement(process, "start", StartEvent.class);
    ParallelGateway fork = createElement(process, "fork", ParallelGateway.class);
    UserTask task1 = createElement(process, "task1", UserTask.class);
    ServiceTask task2 = createElement(process, "task2", ServiceTask.class);
    ParallelGateway join = createElement(process, "join", ParallelGateway.class);
    EndEvent endEvent = createElement(process, "end", EndEvent.class);
    // create flows
    createSequenceFlow(process, startEvent, fork);
    createSequenceFlow(process, fork, task1);
    createSequenceFlow(process, fork, task2);
    createSequenceFlow(process, task1, join);
    createSequenceFlow(process, task2, join);
    createSequenceFlow(process, join, endEvent);
}
Also used : Process(org.camunda.bpm.model.bpmn.instance.Process) Test(org.junit.Test)

Aggregations

Process (org.camunda.bpm.model.bpmn.instance.Process)22 Test (org.junit.Test)13 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)6 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)5 ModelValidationException (org.camunda.bpm.model.xml.ModelValidationException)4 Definitions (org.camunda.bpm.model.bpmn.instance.Definitions)3 ArrayList (java.util.ArrayList)2 StartEvent (org.camunda.bpm.model.bpmn.instance.StartEvent)2 UserTask (org.camunda.bpm.model.bpmn.instance.UserTask)2 BpmnModelResource (org.camunda.bpm.model.bpmn.util.BpmnModelResource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Properties (java.util.Properties)1 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1