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();
}
}
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();
}
}
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);
}
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();
}
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);
}
Aggregations