From 15c17d56df8b8b517763ef248a1503e09309e232 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Tue, 18 Jun 2024 09:19:34 +0200 Subject: [PATCH] refactoring, minor improvements issue #346 --- .../java/org/openbpmn/bpmn/elements/BPMNProcess.java | 2 +- .../bpmn/validation/BPMNValidationHandler.java | 10 ++++++++-- .../test/validation/TestBPMNValidationIssue346.java | 11 ++++------- .../src/test/resources/validation_issue_346.bpmn | 7 ++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java index 3c3373d4..1dd30433 100644 --- a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java +++ b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/elements/BPMNProcess.java @@ -1459,7 +1459,7 @@ public Set findMessageFlowsByElementId(String id) { } /** - * Returns all BPMN Edges associated with a geiven FlowElement. + * Returns all BPMN Edges associated with a given FlowElement. * * @param id * @return diff --git a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/validation/BPMNValidationHandler.java b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/validation/BPMNValidationHandler.java index 13ae886b..e916051b 100644 --- a/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/validation/BPMNValidationHandler.java +++ b/open-bpmn.metamodel/src/main/java/org/openbpmn/bpmn/validation/BPMNValidationHandler.java @@ -9,6 +9,7 @@ import org.openbpmn.bpmn.elements.BPMNProcess; import org.openbpmn.bpmn.elements.Event; import org.openbpmn.bpmn.elements.Gateway; +import org.openbpmn.bpmn.exceptions.BPMNModelException; /** * The BPMNValidationHandler validates a complete BPMNModel for validation @@ -28,8 +29,9 @@ public class BPMNValidationHandler { * * @param forceValidation - if true the full model will be validated. * @return + * @throws BPMNModelException */ - public List validate(BPMNModel model, boolean forceValidation) { + public List validate(BPMNModel model, boolean forceValidation) throws BPMNModelException { List result = new ArrayList<>(); // iterate over all process Set processes = model.getProcesses(); @@ -48,9 +50,13 @@ public List validate(BPMNModel model, boolean forceValidat * for only new added or changed element nodes. * * @return + * @throws BPMNModelException */ - private List validateProcess(BPMNProcess process, boolean forceValidation) { + public List validateProcess(BPMNProcess process, boolean forceValidation) + throws BPMNModelException { List result = new ArrayList<>(); + // make sure that the process is initialized + process.init(); // validate events.... Set events = process.getEvents(); for (Event event : events) { diff --git a/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/validation/TestBPMNValidationIssue346.java b/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/validation/TestBPMNValidationIssue346.java index d7a8653c..a6776781 100644 --- a/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/validation/TestBPMNValidationIssue346.java +++ b/open-bpmn.metamodel/src/test/java/org/openbpmn/metamodel/test/validation/TestBPMNValidationIssue346.java @@ -50,6 +50,7 @@ public void testValidationTaskWithMessageFlow() { // Test default process BPMNProcess process = model.openDefaultProces(); assertNotNull(process); + assertEquals(1, process.getActivities().size()); BPMNValidationHandler bpmnValidationHandler = new BPMNValidationHandler(); List result = bpmnValidationHandler.validate(model, true); @@ -57,15 +58,11 @@ public void testValidationTaskWithMessageFlow() { // we expect no errors assertEquals(0, result.size()); - // Now open the 'Pool-1' containing a receive Task + // Now verify the 'Pool-1'. We expect that the process was initialized by the + // validate method process = model.findProcessByName("Pool-1"); - process = model.openProcess(process.getId()); assertNotNull(process); - bpmnValidationHandler = new BPMNValidationHandler(); - result = bpmnValidationHandler.validate(model, true); - - // we expect no errors - assertEquals(0, result.size()); + assertEquals(3, process.getActivities().size()); } catch (BPMNModelException e) { diff --git a/open-bpmn.metamodel/src/test/resources/validation_issue_346.bpmn b/open-bpmn.metamodel/src/test/resources/validation_issue_346.bpmn index 181e71e1..e5fe546d 100644 --- a/open-bpmn.metamodel/src/test/resources/validation_issue_346.bpmn +++ b/open-bpmn.metamodel/src/test/resources/validation_issue_346.bpmn @@ -69,6 +69,7 @@ sequenceFlow_kIA1WQ + messageFlow_oBGang @@ -151,9 +152,9 @@ - - - + + +