use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.
the class CreateModelTest method createProcessWithOneTask.
@Test
public void createProcessWithOneTask() {
// create process
Process process = createElement(definitions, "process-with-one-task", Process.class);
// create elements
StartEvent startEvent = createElement(process, "start", StartEvent.class);
UserTask task1 = createElement(process, "task1", UserTask.class);
EndEvent endEvent = createElement(process, "end", EndEvent.class);
// create flows
createSequenceFlow(process, startEvent, task1);
createSequenceFlow(process, task1, endEvent);
}
use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.
the class DefinitionsTest method shouldAddChildElementsInCorrectOrder.
@Test
public void shouldAddChildElementsInCorrectOrder() {
// create an empty model
BpmnModelInstance bpmnModelInstance = Bpmn.createEmptyModel();
// add definitions
Definitions definitions = bpmnModelInstance.newInstance(Definitions.class);
definitions.setTargetNamespace("Examples");
bpmnModelInstance.setDefinitions(definitions);
// create a Process element and add it to the definitions
Process process = bpmnModelInstance.newInstance(Process.class);
process.setId("some-process-id");
definitions.getRootElements().add(process);
// create an Import element and add it to the definitions
Import importElement = bpmnModelInstance.newInstance(Import.class);
importElement.setNamespace("Imports");
importElement.setLocation("here");
importElement.setImportType("example");
definitions.getImports().add(importElement);
// create another Process element and add it to the definitions
process = bpmnModelInstance.newInstance(Process.class);
process.setId("another-process-id");
definitions.getRootElements().add(process);
// create another Import element and add it to the definitions
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();
}
}
use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.
the class GenerateIdTest method shouldNotGenerateIdsOnRead.
@Test
public void shouldNotGenerateIdsOnRead() {
BpmnModelInstance modelInstance = Bpmn.readModelFromStream(GenerateIdTest.class.getResourceAsStream("GenerateIdTest.bpmn"));
Definitions definitions = modelInstance.getDefinitions();
assertThat(definitions.getId()).isNull();
Process process = modelInstance.getModelElementsByType(Process.class).iterator().next();
assertThat(process.getId()).isNull();
StartEvent startEvent = modelInstance.getModelElementsByType(StartEvent.class).iterator().next();
assertThat(startEvent.getId()).isNull();
UserTask userTask = modelInstance.getModelElementsByType(UserTask.class).iterator().next();
assertThat(userTask.getId()).isNull();
}
use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.
the class ReferenceTest method createModel.
@Before
public void createModel() {
testBpmnModelInstance = Bpmn.createEmptyModel();
Definitions definitions = testBpmnModelInstance.newInstance(Definitions.class);
testBpmnModelInstance.setDefinitions(definitions);
message = testBpmnModelInstance.newInstance(Message.class);
message.setId("message-id");
definitions.getRootElements().add(message);
Process process = testBpmnModelInstance.newInstance(Process.class);
process.setId("process-id");
definitions.getRootElements().add(process);
startEvent = testBpmnModelInstance.newInstance(StartEvent.class);
startEvent.setId("start-event-id");
process.getFlowElements().add(startEvent);
messageEventDefinition = testBpmnModelInstance.newInstance(MessageEventDefinition.class);
messageEventDefinition.setId("msg-def-id");
messageEventDefinition.setMessage(message);
startEvent.getEventDefinitions().add(messageEventDefinition);
startEvent.getEventDefinitionRefs().add(messageEventDefinition);
}
use of org.camunda.bpm.model.bpmn.instance.Process in project camunda-bpmn-model by camunda.
the class ValidateProcessTest method validationFailsIfNoStartEventFound.
@Test
public void validationFailsIfNoStartEventFound() {
List<ModelElementValidator<?>> validators = new ArrayList<ModelElementValidator<?>>();
validators.add(new ProcessStartEventValidator());
BpmnModelInstance bpmnModelInstance = Bpmn.createProcess().done();
ValidationResults validationResults = bpmnModelInstance.validate(validators);
assertThat(validationResults.hasErrors()).isTrue();
Map<ModelElementInstance, List<ValidationResult>> results = validationResults.getResults();
assertThat(results.size()).isEqualTo(1);
Process process = bpmnModelInstance.getDefinitions().getChildElementsByType(Process.class).iterator().next();
assertThat(results.containsKey(process)).isTrue();
List<ValidationResult> resultsForProcess = results.get(process);
assertThat(resultsForProcess.size()).isEqualTo(1);
ValidationResult validationResult = resultsForProcess.get(0);
assertThat(validationResult.getElement()).isEqualTo(process);
assertThat(validationResult.getCode()).isEqualTo(10);
assertThat(validationResult.getMessage()).isEqualTo("Process does not have exactly one start event. Got 0.");
assertThat(validationResult.getType()).isEqualTo(ValidationResultType.ERROR);
}
Aggregations