Skip to content

Commit

Permalink
impl, junit tests
Browse files Browse the repository at this point in the history
Issue #311
  • Loading branch information
rsoika committed Nov 19, 2023
1 parent 5211ca9 commit 9fc18df
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.openbpmn.bpmn.elements;

import java.util.ArrayList;
import java.util.List;

import org.openbpmn.bpmn.BPMNModel;
import org.openbpmn.bpmn.BPMNNS;
import org.openbpmn.bpmn.BPMNTypes;
import org.openbpmn.bpmn.elements.core.BPMNElementNode;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -57,4 +61,39 @@ public void setPosition(double x, double y) {
}
}

/**
* This method adds a new Boundary Event this activity.
*
* The element has not position assigned yet!
*
* @return
* @throws BPMNModelException
*/
public Event createBoundaryEvent(String eventID, String name) throws BPMNModelException {
Event boundaryEvent;
boundaryEvent = bpmnProcess.addEvent(eventID, name, BPMNTypes.BOUNDARY_EVENT);
boundaryEvent.setAttribute("attachedToRef", this.getId());
return boundaryEvent;
}

/**
* This method returns a list of all boundaray Events attached to this activity.
*
* @return
*/
public List<Event> getAllBoundaryEvents() {
List<Event> result = new ArrayList<>();
for (Event e : bpmnProcess.getEvents()) {
if (BPMNTypes.BOUNDARY_EVENT.equals(e.getType())) {

// test ref....
if (this.getId().equals(e.getAttribute("attachedToRef"))) {
result.add(e);
}

}
}
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.openbpmn.metamodel.examples;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.List;
import java.util.logging.Logger;

import org.junit.jupiter.api.Test;
import org.openbpmn.bpmn.BPMNModel;
import org.openbpmn.bpmn.BPMNTypes;
import org.openbpmn.bpmn.elements.Activity;
import org.openbpmn.bpmn.elements.BPMNProcess;
import org.openbpmn.bpmn.elements.Event;
import org.openbpmn.bpmn.exceptions.BPMNModelException;
import org.openbpmn.bpmn.util.BPMNModelFactory;

/**
* This test class tests the creation of Events
*
* @author rsoika
*
*/
public class TestCreateEvents {

private static Logger logger = Logger.getLogger(TestCreateEvents.class.getName());

/**
* This test creates a bpmn file with Task and a Boundary Event
*/
@Test
public void testCreateBoundaryEvent() {
String out = "src/test/resources/output/process-example-10.bpmn";

logger.info("...create model");

String exporter = "demo";
String version = "1.0.0";
String targetNameSpace = "http://org.openbpmn";
BPMNModel model = BPMNModelFactory.createInstance(exporter, version,
targetNameSpace);

try {
BPMNProcess process = model.openDefaultProces();
// Create a Task
Activity task = process.addTask("task-1", "Task", BPMNTypes.TASK);

// add a boundary event
Event boundaryEvent = task.createBoundaryEvent("boundary-event-1", "Boundary Event");
assertEquals(task.getId(), boundaryEvent.getAttribute("attachedToRef"));

// we expect one boundary event
List<Event> boundaryEventList = task.getAllBoundaryEvents();
assertEquals(1, boundaryEventList.size());

} catch (BPMNModelException e) {
e.printStackTrace();
fail();
}
assertNotNull(model);
assertEquals(1, model.getProcesses().size());

model.save(out);
logger.info("...model created sucessful: " + out);
}

/**
* This test creates a bpmn file with multiple Tasks and a Boundary Events
*/
@Test
public void testCreateBoundaryMultiEvent() {
String out = "src/test/resources/output/process-example-11.bpmn";

logger.info("...create model");

String exporter = "demo";
String version = "1.0.0";
String targetNameSpace = "http://org.openbpmn";
BPMNModel model = BPMNModelFactory.createInstance(exporter, version,
targetNameSpace);

try {
BPMNProcess process = model.openDefaultProces();
// Create a Task
Activity task1 = process.addTask("task-1", "Task", BPMNTypes.TASK);
Activity task2 = process.addTask("task-2", "Task", BPMNTypes.TASK);

// add a boundary event
Event boundaryEvent = task1.createBoundaryEvent("boundary-event-1", "Boundary Event");
assertEquals(task1.getId(), boundaryEvent.getAttribute("attachedToRef"));

boundaryEvent = task2.createBoundaryEvent("boundary-event-2", "Boundary Event");

boundaryEvent = task2.createBoundaryEvent("boundary-event-3", "Boundary Event");

// we expect one boundary event
List<Event> boundaryEventList = task1.getAllBoundaryEvents();
assertEquals(1, boundaryEventList.size());
// we expect tgwo boundary event
boundaryEventList = task2.getAllBoundaryEvents();
assertEquals(2, boundaryEventList.size());

} catch (BPMNModelException e) {
e.printStackTrace();
fail();
}
assertNotNull(model);
assertEquals(1, model.getProcesses().size());

model.save(out);
logger.info("...model created sucessful: " + out);
}

}

0 comments on commit 9fc18df

Please sign in to comment.