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()));
}
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);
}
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");
}
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));
}
}
}
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());
}
Aggregations