specification = (YSpecification) YMarshal.
unmarshalSpecifications(yawlXMLFile.getAbsolutePath()).get(0);
_engine = YEngine.getInstance();
EngineClearer.clear(_engine);
_engine.loadSpecification(specification);
YIdentifier caseID = _engine.startCase(null, null, specification.getID().toString(), null, null);
{
YWorkItem itemA = (YWorkItem) _engine.getAvailableWorkItems().iterator().next();
_engine.startWorkItem(itemA, "admin");
try {
Thread.sleep(_sleepTime);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
itemA = (YWorkItem) _engine.getChildrenOfWorkItem(
itemA).iterator().next();
_engine.completeWorkItem(itemA, "<data/>", false);
try {
Thread.sleep(_sleepTime);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
{
YWorkItem itemF = null;
Iterator it = _engine.getAvailableWorkItems().iterator();
while (it.hasNext()) {
YWorkItem item = (YWorkItem) it.next();
if (item.getTaskID().equals("F")) {
itemF = item;
break;
}
}
_engine.startWorkItem(itemF, "admin");
try {
Thread.sleep(_sleepTime);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
itemF = (YWorkItem) _engine.getChildrenOfWorkItem(itemF).iterator().next();
_engine.completeWorkItem(itemF, "<data/>", false);
try {
Thread.sleep(_sleepTime);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
{
YWorkItem itemB = null;
Iterator it = _engine.getAvailableWorkItems().iterator();
while (it.hasNext()) {
YWorkItem item = (YWorkItem) it.next();
if (item.getTaskID().equals("B")) {
itemB = item;
break;
}
}
_engine.startWorkItem(itemB, "admin");
try {
Thread.sleep(_sleepTime);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
itemB = (YWorkItem) _engine.getChildrenOfWorkItem(itemB).iterator().next();
_engine.completeWorkItem(itemB, "<data/>", false);
try {
Thread.sleep(_sleepTime);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
{
YWorkItem itemA = (YWorkItem) _engine.getAvailableWorkItems()
.iterator().next();
//get the real net elements that contain the identifier tokens.
List locations = caseID.getLocations();
for (int i = 0; i < locations.size(); i++) {
YExternalNetElement element = (YExternalNetElement) locations.get(i);
if (element instanceof YTask) {
YTask task = (YTask) element;
Set preset = task.getPresetElements();
Set items = _engine.getAvailableWorkItems();
//If the task is enabled we test that the work items reflect this.
if (task.t_enabled(caseID)) {
boolean tokenFound = false;
//Check that the conitions in the preset confirm the enabled
//state of the task.
for (Iterator presetIter = preset.iterator(); presetIter.hasNext();) {
YCondition condition = (YCondition) presetIter.next();
if (condition.containsIdentifier()) {
tokenFound = true;
}
}
assertTrue("State misaligment found: task [" +
task + "] is enabled but has no tokens in " +
"its preset2.", tokenFound);
//Check that there is one work enabled work item to match the enabled
//state of the task.
boolean workItemFound = false;
for (Iterator iterator = items.iterator(); iterator.hasNext();) {
YWorkItem anItem = (YWorkItem) iterator.next();
if(anItem.getTaskID().equals(task.getID())){
if(! anItem.getStatus().equals(YWorkItem.statusEnabled)){
fail("The work item [" + anItem + "] " +
"should be enabled because the corresponding " +
"task is enabled but this wokr item is in " +
"the state : [" + anItem.getStatus() + "]");
}
workItemFound = true;
}
assertTrue("State misaligment found: task [" +
task + "] is enabled but there is no corresponding" +
" work item found.", workItemFound);
}
//if the task is busy we test if the work items reflect this.
}else if (task.t_isBusy()) {
boolean tokenFound = false;
//Check that the locations of the id confirm the busy state of the task
List idlocs = caseID.getLocations();
for (Iterator idlocsIter = idlocs.iterator(); idlocsIter.hasNext();) {
YExternalNetElement netElem = (YExternalNetElement) idlocsIter.next();
if (netElem.getID().equals(task.getID())) {
tokenFound = true;
}
}
assertTrue("State misaligment found: task [" +
task + "] is busy but there is no token inside it.",
tokenFound);
//Check that there is at least one fired or executing work item
//to match the busy state of the task.
int workItemCount = 0;
for (Iterator iterator = items.iterator(); iterator.hasNext();) {
YWorkItem anItem = (YWorkItem) iterator.next();
if(anItem.getTaskID().equals(task.getID())){
if(! (anItem.getStatus().equals(YWorkItem.statusFired)
|| anItem.getStatus().equals(YWorkItem.statusExecuting)
|| anItem.getStatus().equals(YWorkItem.statusIsParent))){
fail("The work item [" + anItem + "] " +
"should be fired, executing, or isParent " +
"because the corresponding " +
"task is busy but this wokr item is in " +
"the state : [" + anItem.getStatus() + "]");
}
workItemCount++;
}
assertTrue("State misaligment found: task [" +
task + "] is enabled but there is no corresponding" +
" work item found.", workItemCount > 1);
}
}
//the task must be inactive, we test if the work items reflect this.
else {
boolean tokenNotFound = true;
//Check that the locations of the id confirm the
//task is indeed not busy
List idlocs = caseID.getLocations();
for (Iterator idlocsIter = idlocs.iterator(); idlocsIter.hasNext();) {
YExternalNetElement netElem = (YExternalNetElement) idlocsIter.next();
if (netElem.getID().equals(task.getID())) {
tokenNotFound = false;
}