Search in sources :

Example 1 with BpmnModelInstance

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

the class CompatabilityTest method modifyingAttributeWithActivitiNsKeepsIt.

@Test
public void modifyingAttributeWithActivitiNsKeepsIt() {
    BpmnModelInstance modelInstance = Bpmn.readModelFromStream(CamundaExtensionsTest.class.getResourceAsStream("CamundaExtensionsCompatabilityTest.xml"));
    ProcessImpl process = modelInstance.getModelElementById(PROCESS_ID);
    String priority = "9000";
    process.setCamundaJobPriority(priority);
    process.setCamundaTaskPriority(priority);
    Integer historyTimeToLive = 10;
    process.setCamundaHistoryTimeToLive(historyTimeToLive);
    assertThat(process.getAttributeValueNs(BpmnModelConstants.ACTIVITI_NS, "jobPriority"), is(priority));
    assertThat(process.getAttributeValueNs(BpmnModelConstants.ACTIVITI_NS, "taskPriority"), is(priority));
    assertThat(process.getAttributeValueNs(BpmnModelConstants.ACTIVITI_NS, "historyTimeToLive"), is(historyTimeToLive.toString()));
}
Also used : ProcessImpl(org.camunda.bpm.model.bpmn.impl.instance.ProcessImpl) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) CamundaExtensionsTest(org.camunda.bpm.model.bpmn.CamundaExtensionsTest) CamundaExtensionsTest(org.camunda.bpm.model.bpmn.CamundaExtensionsTest) Test(org.junit.Test)

Example 2 with BpmnModelInstance

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

Example 3 with BpmnModelInstance

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

the class TransactionTest method shouldWriteTransaction.

@Test
public void shouldWriteTransaction() throws ParserConfigurationException, SAXException, IOException {
    // given a model
    BpmnModelInstance newModel = Bpmn.createProcess("process").done();
    Process process = newModel.getModelElementById("process");
    Transaction transaction = newModel.newInstance(Transaction.class);
    transaction.setId("transaction");
    transaction.setMethod(TransactionMethod.Store);
    process.addChildElement(transaction);
    // that is written to a stream
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    Bpmn.writeModelToStream(outStream, newModel);
    // when reading from that stream
    ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document actualDocument = docBuilder.parse(inStream);
    // then it possible to traverse to the transaction element and assert its attributes
    NodeList transactionElements = actualDocument.getElementsByTagName("transaction");
    assertThat(transactionElements.getLength()).isEqualTo(1);
    Node transactionElement = transactionElements.item(0);
    assertThat(transactionElement).isNotNull();
    Node methodAttribute = transactionElement.getAttributes().getNamedItem("method");
    assertThat(methodAttribute.getNodeValue()).isEqualTo("##Store");
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 4 with BpmnModelInstance

use of org.camunda.bpm.model.bpmn.BpmnModelInstance in project camunda-bpm-platform by camunda.

the class ProcessDefinitionQueryImpl method addProcessDefinitionToCacheAndRetrieveDocumentation.

protected void addProcessDefinitionToCacheAndRetrieveDocumentation(List<ProcessDefinition> list) {
    for (ProcessDefinition processDefinition : list) {
        BpmnModelInstance bpmnModelInstance = Context.getProcessEngineConfiguration().getDeploymentCache().findBpmnModelInstanceForProcessDefinition((ProcessDefinitionEntity) processDefinition);
        ModelElementInstance processElement = bpmnModelInstance.getModelElementById(processDefinition.getKey());
        if (processElement != null) {
            Collection<Documentation> documentations = processElement.getChildElementsByType(Documentation.class);
            List<String> docStrings = new ArrayList<String>();
            for (Documentation documentation : documentations) {
                docStrings.add(documentation.getTextContent());
            }
            ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) processDefinition;
            processDefinitionEntity.setProperty(BpmnParse.PROPERTYNAME_DOCUMENTATION, BpmnParse.parseDocumentation(docStrings));
        }
    }
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) Documentation(org.camunda.bpm.model.bpmn.instance.Documentation) ArrayList(java.util.ArrayList) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 5 with BpmnModelInstance

use of org.camunda.bpm.model.bpmn.BpmnModelInstance in project camunda-bpm-platform by camunda.

the class SpringTransactionIntegrationDeleteDeploymentFailTest method testFailingAfterDeleteDeployment.

public void testFailingAfterDeleteDeployment() {
    // given
    final BpmnModelInstance model = Bpmn.createExecutableProcess().startEvent().userTask().endEvent().done();
    deploymentId = processEngine.getRepositoryService().createDeployment().addModelInstance("model.bpmn", model).deploy().getId();
    // 4. DeleteDeploymentFailListener is called
    try {
        processEngine.getRepositoryService().deleteDeployment(deploymentId);
    } catch (Exception ex) {
    // expected exception
    }
    // then
    // DeleteDeploymentFailListener succeeded to registered deployments back
    assertEquals(1, processEngineConfiguration.getRegisteredDeployments().size());
}
Also used : BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance)

Aggregations

BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)587 Test (org.junit.Test)408 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)258 Task (org.camunda.bpm.engine.task.Task)139 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)124 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)119 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)67 ProcessApplicationDeployment (org.camunda.bpm.engine.repository.ProcessApplicationDeployment)47 Deployment (org.camunda.bpm.engine.repository.Deployment)39 ProcessDefinitionQuery (org.camunda.bpm.engine.repository.ProcessDefinitionQuery)27 Job (org.camunda.bpm.engine.runtime.Job)24 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)22 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)21 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)16 Date (java.util.Date)15 HashMap (java.util.HashMap)15 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)14 Execution (org.camunda.bpm.engine.runtime.Execution)14 MigratingBpmnEventTrigger (org.camunda.bpm.engine.test.api.runtime.migration.util.MigratingBpmnEventTrigger)14 SequenceFlow (org.camunda.bpm.model.bpmn.instance.SequenceFlow)14