Search in sources :

Example 1 with BpmnModelResource

use of io.camunda.zeebe.model.bpmn.util.BpmnModelResource in project zeebe by camunda.

the class DefinitionsTest method shouldNotAffectComments.

@Test
@BpmnModelResource
public void shouldNotAffectComments() throws IOException {
    final Definitions definitions = bpmnModelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    // create another Process element and add it to the definitions
    final 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
    final 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 (final ModelValidationException e) {
        Assert.fail();
    }
    // convert the model to the XML string representation
    final OutputStream outputStream = new ByteArrayOutputStream();
    Bpmn.writeModelToStream(outputStream, bpmnModelInstance);
    InputStream inputStream = IoUtil.convertOutputStreamToInputStream(outputStream);
    final String modelString = IoUtil.getStringFromInputStream(inputStream);
    IoUtil.closeSilently(outputStream);
    IoUtil.closeSilently(inputStream);
    // read test process from file as string
    inputStream = getClass().getResourceAsStream("DefinitionsTest.shouldNotAffectCommentsResult.bpmn");
    final String fileString = IoUtil.getStringFromInputStream(inputStream);
    IoUtil.closeSilently(inputStream);
    // compare strings
    assertThat(modelString).endsWith(fileString);
}
Also used : Import(io.camunda.zeebe.model.bpmn.instance.Import) ModelValidationException(org.camunda.bpm.model.xml.ModelValidationException) InputStream(java.io.InputStream) Definitions(io.camunda.zeebe.model.bpmn.instance.Definitions) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Process(io.camunda.zeebe.model.bpmn.instance.Process) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BpmnModelResource(io.camunda.zeebe.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Example 2 with BpmnModelResource

use of io.camunda.zeebe.model.bpmn.util.BpmnModelResource in project zeebe by camunda.

the class DefinitionsTest method shouldImportEmptyDefinitions.

@Test
@BpmnModelResource
public void shouldImportEmptyDefinitions() {
    final Definitions definitions = bpmnModelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    // provided in file
    assertThat(definitions.getTargetNamespace()).isEqualTo("http://camunda.org/test");
    // defaults provided in Schema
    assertThat(definitions.getExpressionLanguage()).isEqualTo(XPATH_NS);
    assertThat(definitions.getTypeLanguage()).isEqualTo(XML_SCHEMA_NS);
    // not provided in file
    assertThat(definitions.getExporter()).isNull();
    assertThat(definitions.getExporterVersion()).isNull();
    assertThat(definitions.getId()).isNull();
    assertThat(definitions.getName()).isNull();
    // has no imports
    assertThat(definitions.getImports()).isEmpty();
}
Also used : Definitions(io.camunda.zeebe.model.bpmn.instance.Definitions) BpmnModelResource(io.camunda.zeebe.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Example 3 with BpmnModelResource

use of io.camunda.zeebe.model.bpmn.util.BpmnModelResource in project zeebe by camunda.

the class ProcessTest method shouldImportProcess.

@Test
@BpmnModelResource
public void shouldImportProcess() {
    final ModelElementInstance modelElementById = bpmnModelInstance.getModelElementById("exampleProcessId");
    assertThat(modelElementById).isNotNull();
    final Collection<RootElement> rootElements = bpmnModelInstance.getDefinitions().getRootElements();
    assertThat(rootElements).hasSize(1);
    final io.camunda.zeebe.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(io.camunda.zeebe.model.bpmn.instance.RootElement) Process(io.camunda.zeebe.model.bpmn.instance.Process) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) Process(io.camunda.zeebe.model.bpmn.instance.Process) BpmnModelResource(io.camunda.zeebe.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Example 4 with BpmnModelResource

use of io.camunda.zeebe.model.bpmn.util.BpmnModelResource in project zeebe by zeebe-io.

the class DefinitionsTest method shouldImportEmptyDefinitions.

@Test
@BpmnModelResource
public void shouldImportEmptyDefinitions() {
    final Definitions definitions = bpmnModelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    // provided in file
    assertThat(definitions.getTargetNamespace()).isEqualTo("http://camunda.org/test");
    // defaults provided in Schema
    assertThat(definitions.getExpressionLanguage()).isEqualTo(XPATH_NS);
    assertThat(definitions.getTypeLanguage()).isEqualTo(XML_SCHEMA_NS);
    // not provided in file
    assertThat(definitions.getExporter()).isNull();
    assertThat(definitions.getExporterVersion()).isNull();
    assertThat(definitions.getId()).isNull();
    assertThat(definitions.getName()).isNull();
    // has no imports
    assertThat(definitions.getImports()).isEmpty();
}
Also used : Definitions(io.camunda.zeebe.model.bpmn.instance.Definitions) BpmnModelResource(io.camunda.zeebe.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Example 5 with BpmnModelResource

use of io.camunda.zeebe.model.bpmn.util.BpmnModelResource in project zeebe by zeebe-io.

the class DefinitionsTest method shouldNotAffectComments.

@Test
@BpmnModelResource
public void shouldNotAffectComments() throws IOException {
    final Definitions definitions = bpmnModelInstance.getDefinitions();
    assertThat(definitions).isNotNull();
    // create another Process element and add it to the definitions
    final 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
    final 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 (final ModelValidationException e) {
        Assert.fail();
    }
    // convert the model to the XML string representation
    final OutputStream outputStream = new ByteArrayOutputStream();
    Bpmn.writeModelToStream(outputStream, bpmnModelInstance);
    InputStream inputStream = IoUtil.convertOutputStreamToInputStream(outputStream);
    final String modelString = IoUtil.getStringFromInputStream(inputStream);
    IoUtil.closeSilently(outputStream);
    IoUtil.closeSilently(inputStream);
    // read test process from file as string
    inputStream = getClass().getResourceAsStream("DefinitionsTest.shouldNotAffectCommentsResult.bpmn");
    final String fileString = IoUtil.getStringFromInputStream(inputStream);
    IoUtil.closeSilently(inputStream);
    // compare strings
    assertThat(modelString).endsWith(fileString);
}
Also used : Import(io.camunda.zeebe.model.bpmn.instance.Import) ModelValidationException(org.camunda.bpm.model.xml.ModelValidationException) InputStream(java.io.InputStream) Definitions(io.camunda.zeebe.model.bpmn.instance.Definitions) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Process(io.camunda.zeebe.model.bpmn.instance.Process) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BpmnModelResource(io.camunda.zeebe.model.bpmn.util.BpmnModelResource) Test(org.junit.Test)

Aggregations

BpmnModelResource (io.camunda.zeebe.model.bpmn.util.BpmnModelResource)12 Test (org.junit.Test)12 Definitions (io.camunda.zeebe.model.bpmn.instance.Definitions)6 Process (io.camunda.zeebe.model.bpmn.instance.Process)6 EventDefinition (io.camunda.zeebe.model.bpmn.instance.EventDefinition)3 Import (io.camunda.zeebe.model.bpmn.instance.Import)3 Message (io.camunda.zeebe.model.bpmn.instance.Message)3 MessageEventDefinition (io.camunda.zeebe.model.bpmn.instance.MessageEventDefinition)3 RootElement (io.camunda.zeebe.model.bpmn.instance.RootElement)3 StartEvent (io.camunda.zeebe.model.bpmn.instance.StartEvent)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 ModelValidationException (org.camunda.bpm.model.xml.ModelValidationException)3 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)3