Search in sources :

Example 1 with Process

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);
}
Also used : Process(org.camunda.bpm.model.bpmn.instance.Process) Test(org.junit.Test)

Example 2 with Process

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();
    }
}
Also used : ModelValidationException(org.camunda.bpm.model.xml.ModelValidationException) Process(org.camunda.bpm.model.bpmn.instance.Process) Test(org.junit.Test)

Example 3 with Process

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();
}
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 4 with Process

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);
}
Also used : Process(org.camunda.bpm.model.bpmn.instance.Process) Before(org.junit.Before)

Example 5 with Process

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);
}
Also used : ModelElementValidator(org.camunda.bpm.model.xml.validation.ModelElementValidator) ValidationResults(org.camunda.bpm.model.xml.validation.ValidationResults) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Process(org.camunda.bpm.model.bpmn.instance.Process) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) ValidationResult(org.camunda.bpm.model.xml.validation.ValidationResult) 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