Search in sources :

Example 1 with BpmnModelResource

use of org.camunda.bpm.model.bpmn.util.BpmnModelResource in project camunda-bpmn-model by camunda.

the class ProcessTest method shouldImportProcess.

@Test
@BpmnModelResource
public void shouldImportProcess() {
    ModelElementInstance modelElementById = bpmnModelInstance.getModelElementById("exampleProcessId");
    assertThat(modelElementById).isNotNull();
    Collection<RootElement> rootElements = bpmnModelInstance.getDefinitions().getRootElements();
    assertThat(rootElements).hasSize(1);
    org.camunda.bpm.model.bpmn.instance.Process process = (Process) rootElements.iterator().next();
    assertThat(process.getId()).isEqualTo("exampleProcessId");
    assertThat(process.getName()).isNull();
    assertThat(process.getProcessType()).isEqualTo(ProcessType.None);
    assertThat(process.isExecutable()).isFalse();
    assertThat(process.isClosed()).isFalse();
}
Also used : RootElement(org.camunda.bpm.model.bpmn.instance.RootElement) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) Process(org.camunda.bpm.model.bpmn.instance.Process) Process(org.camunda.bpm.model.bpmn.instance.Process) BpmnModelResource(org.camunda.bpm.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Example 2 with BpmnModelResource

use of org.camunda.bpm.model.bpmn.util.BpmnModelResource 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)

Aggregations

Process (org.camunda.bpm.model.bpmn.instance.Process)2 BpmnModelResource (org.camunda.bpm.model.bpmn.util.BpmnModelResource)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 RootElement (org.camunda.bpm.model.bpmn.instance.RootElement)1 ModelValidationException (org.camunda.bpm.model.xml.ModelValidationException)1 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)1