Package procdef

Source Code of procdef.Create

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: Create.java 2326 2007-03-27 21:59:44Z mlipp $
*
* $Log$
* Revision 1.2  2006/09/29 12:32:09  drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.1.1.2  2003/12/19 13:01:45  drmlipp
* Updated to 1.1rc1
*
* Revision 1.14  2003/10/27 15:32:05  huaiyang
* use wrappedProcess/Activity.
*
* Revision 1.13  2003/10/21 21:00:45  lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.12  2003/10/08 12:39:40  huaiyang
* make test weblogic compatible.
*
* Revision 1.11  2003/06/27 09:44:03  lipp
* Fixed copyright/license information.
*
* Revision 1.10  2003/06/02 15:25:19  lipp
* Activated IPR38 check.
*
* Revision 1.9  2003/05/31 18:29:59  lipp
* Fixed test case.
*
* Revision 1.8  2003/05/22 11:39:57  lipp
* Fixed test case.
*
* Revision 1.7  2003/05/14 12:02:26  schlue
* Import of process descriptions changed due to modified import behaviour.
*
* Revision 1.6  2003/05/14 09:30:27  schlue
* Package names for minimal and full changed due to modified import behaviour.
*
* Revision 1.5  2003/05/07 09:55:21  schlue
* Redefinable header with version info added.
*
* Revision 1.4  2003/04/26 16:12:22  lipp
* Moved some classes to reduce package dependencies.
*
* Revision 1.3  2003/04/16 14:06:26  schlue
* Some renames.
*
* Revision 1.2  2003/04/15 14:17:22  schlue
* Cleanup added.
*
* Revision 1.1  2003/04/15 12:57:25  schlue
* Static tests of process and activity (definitions) moved to directory process.
* More test cases for block activities added.
*
* Revision 1.3  2003/04/11 14:39:56  schlue
* System tests for activitites added.
*
* Revision 1.2  2003/04/10 09:44:08  schlue
* Test cases for process data added.
*
* Revision 1.1  2003/03/21 10:00:59  schlue
* Initial version.
*
*
*
*/
package procdef;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import java.rmi.RemoteException;

import de.danet.an.workflow.omgcore.InvalidPriorityException;
import de.danet.an.workflow.omgcore.NotEnabledException;
import de.danet.an.workflow.omgcore.WfExecutionObject;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.workflow.omgcore.WfProcessMgr;
import de.danet.an.workflow.omgcore.WfRequester;

import de.danet.an.util.junit.EJBClientTest;
import de.danet.an.workflow.api.Activity;
import de.danet.an.workflow.api.DefaultRequester;
import de.danet.an.workflow.api.ImportException;
import de.danet.an.workflow.api.InvalidKeyException;
import de.danet.an.workflow.api.PrioritizedMessage;
import de.danet.an.workflow.api.Process;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.ProcessDirectory;
import de.danet.an.workflow.api.ProcessMgr;
import de.danet.an.workflow.api.WorkflowService;
import de.danet.an.workflow.api.WorkflowServiceFactory;

import junit.framework.Test;
import junit.framework.TestSuite;
import process.WfMOpenTestCase;
import process.EventWatch;
import common.WrappedProcess;
import common.WrappedActivity;
import common.WrappedProcessDefinitionDirectory;

/**
* Test creation of processes.
* After completion, all previously imported process descriptions
* and created processes are cleared.
* @author <a href="mailto:schlueter@danet.de">Holger Schlueter</a>
* @version 1.0
*/
public class Create extends WfMOpenTestCase {

    private static Collection createdProcs = new ArrayList ();

    /**
     * Access to process definition directory (singleton)
     */
    private WrappedProcessDefinitionDirectory defDir = null;

    /**
     * Access to process directory (singleton)
     */
    private ProcessDirectory procDir = null;

    /**
     * Access to default requester (singleton)
     */
    private WfRequester requester = null;

    /**
     * Constructor of this TestCase
     * @param name a <code>String</code> value
     */
    public Create(String name) {
  super (name);
    }

    /**
     * Construct this test suite.
     * @return a <code>Test</code> value
     */
    public static Test suite() {
        TestSuite suite = new TestSuite();
     suite.addTest(new Create("testEnabled"));
     suite.addTest(new Create("createMinimal"));
     suite.addTest(new Create("testProcAttributes"));
     suite.addTest(new Create("testActivities"));
     suite.addTest(new Create("testActivitiesBlock1"));
     suite.addTest(new Create("testActivitiesBlock2"));
     suite.addTest(new Create("removeProcesses"))
     suite.addTest(new Create("cleanup"))
     suite.addTest(new Create("testActivitiesBlock2"));
     suite.addTest(new Create("removeProcesses"))
        return new EJBClientTest (plc, suite);
    }

    /**
     * Test enable flag on creation of a process.
     * @exception Exception if an error occurs
     */
    public void testEnabled() throws Exception {
  boolean gotException = false;
  // test default setting
  assertTrue(defDir.isEnabled("SystemTest_minimal", "minimal"));
  defDir.setEnabled("SystemTest_minimal", "minimal", false);
  ProcessMgr mgr = defDir.processMgr("SystemTest_minimal", "minimal");
  int noprocs = mgr.processes().size();
  //WfProcess proc = null;
  WrappedProcess proc = null;
  // Make sure that default is "disabled"
  assertTrue(mgr.processMgrState() == WfProcessMgr.DISABLED);
  // Test that process creation is not possible
  try {
      //proc = mgr.createProcess(requester);
      proc = new WrappedProcess(mgr.createProcess(requester));
  } catch (NotEnabledException exc) {
      gotException = true;
  }
  assertTrue(gotException);
  // Enable now and make sure that process can be created
  mgr.setProcessMgrState(WfProcessMgr.ENABLED);
  assertTrue(mgr.processes().size() == noprocs);
  proc = new WrappedProcess(mgr.createProcess(requester));
  createdProcs.add (proc);
  assertTrue(mgr.processes().size() == noprocs+1);
    }

    /**
     * Test creation of a process with minimal process definition.
     * @exception Exception if an error occurs
     */
    public void createMinimal() throws Exception {
  boolean gotException = false;
  // Try invald packageId
  try {
      defDir.processMgr("Systemtest", "minimal");
  } catch (InvalidKeyException exc) {
      gotException = true;
  }
  assertTrue(gotException);
  // Try invald processId
  gotException = false;
  try {
      defDir.processMgr("SystemTest_minimal", "Minimal");
  } catch (InvalidKeyException exc) {
      gotException = true;
  }
  assertTrue(gotException);   
  // Try correct identifier
  ProcessMgr mgr = defDir.processMgr("SystemTest_minimal", "minimal");
  int noprocs = mgr.processes().size();
  //WfProcess proc = mgr.createProcess(requester);
  WrappedProcess proc = new WrappedProcess(mgr.createProcess(requester));
  assertTrue(mgr.processes().size() == noprocs+1);
  createdProcs.add (proc);
    }

    /**
     * Test removal of all previously created processes.
     * @exception Exception if an error occurs
     */
    public void removeProcesses() throws Exception {
  int noprocs = procDir.processes().size();
  Iterator procs = createdProcs.iterator ();
  while (procs.hasNext()) {
      //WfProcess proc = (Process)procs.next();
      WrappedProcess proc = (WrappedProcess)procs.next();
      procDir.removeProcess(proc.getWfProcess());
  }
  assertTrue
      (procDir.processes().size() == noprocs - createdProcs.size ());
  createdProcs.clear();
    }

    /**
     * Remove all imported process definitions.
     * @exception Exception if an error occurs
     */
    public void cleanup() throws Exception {
  defDir.removeProcessDefinition("SystemTest_minimal", "minimal");
  boolean procdefRemoved = false;
  try {
      defDir.processMgr("SystemTest_minimal", "minimal");
  } catch (InvalidKeyException exc) {
      procdefRemoved = true;
  }
  assertTrue(procdefRemoved);
  defDir.removeProcessDefinition("SystemTest_full", "full");
  procdefRemoved = false;
  try {
      defDir.processMgr("SystemTest_full", "full");
  } catch (InvalidKeyException exc) {
      procdefRemoved = true;
  }
  assertTrue(procdefRemoved);
  defDir.removeProcessDefinition("SystemTest", "block_diamond");
  procdefRemoved = false;
  try {
      defDir.processMgr("SystemTest", "block_diamond");
  } catch (InvalidKeyException exc) {
      procdefRemoved = true;
  }
  assertTrue(procdefRemoved);
  defDir.removeProcessDefinition("SystemTest", "block_2_in_2_out");
  procdefRemoved = false;
  try {
      defDir.processMgr("SystemTest", "block_2_in_2_out");
  } catch (InvalidKeyException exc) {
      procdefRemoved = true;
  }
  assertTrue(procdefRemoved);
    }

    /**
     * Test all accessible attributes of process manager and process
     * (except process data and process context information).
     * @exception Exception if an error occurs
     */
    public void testProcAttributes() throws Exception {
  ProcessMgr mgrMin = defDir.processMgr("SystemTest_minimal", "minimal");
  ProcessMgr mgrFull = defDir.processMgr("SystemTest_full", "full");

  // Test attributes of process manager
  assertTrue(mgrMin.category() == null);
  assertTrue(mgrMin.description() == null);
  assertTrue(mgrMin.version() == null);
  assertTrue(mgrMin.name().equals("SystemTest_minimal/minimal"));
  assertTrue(mgrFull.category().equals("System Test (procdef)"));
  assertTrue(mgrFull.description()
       .equals("Description for test of all accessible attributes"));
 
  assertTrue(mgrFull.version().equals("beta 1"));
  assertTrue(mgrFull.name().equals("SystemTest_full/full"));

//   WfProcess proc1 = mgrMin.createProcess(requester);
//   WfProcess proc2 = mgrFull.createProcess(requester);
//   WfProcess proc3 = mgrFull.createProcess(requester);
  WrappedProcess proc1
      = new WrappedProcess(mgrMin.createProcess(requester));
  WrappedProcess proc2
      = new WrappedProcess(mgrFull.createProcess(requester));
  WrappedProcess proc3
      = new WrappedProcess(mgrFull.createProcess(requester));
  // Test attributes of processes without existing process definition
  defDir.removeProcessDefinition("SystemTest_minimal", "minimal");
  defDir.removeProcessDefinition("SystemTest_full", "full");
  boolean procdefRemoved = false;
  try {
      mgrMin = defDir.processMgr("SystemTest_minimal", "minimal");
  } catch (InvalidKeyException exc) {
      procdefRemoved = true;
  }
  assertTrue(procdefRemoved);
  procdefRemoved = false;
  try {
      mgrFull = defDir.processMgr("SystemTest_full", "full");
  } catch (InvalidKeyException exc) {
      procdefRemoved = true;
  }
  assertTrue(procdefRemoved);

  assertTrue(proc1.name() == null);
  proc1.setName("minimal Process");
  assertTrue(proc2.name().equals("PROCESS_COMPLETE_ATTRIBUTES"));
  assertTrue(proc3.name().equals("PROCESS_COMPLETE_ATTRIBUTES"));
  proc2.setName(null);
  assertTrue(proc1.name().equals("minimal Process"));
  assertTrue(proc2.name() == null);
  assertTrue(proc3.name().equals("PROCESS_COMPLETE_ATTRIBUTES"));
  assertTrue(!proc2.key().equals(proc3.key()));
  assertTrue(proc1.description() == null);
  assertTrue(proc2.description()
       .equals("Description for test of all accessible attributes"));
  assertTrue(proc3.description()
       .equals("Description for test of all accessible attributes"));
  proc3.setDescription("full");
  assertTrue(proc2.description()
       .equals("Description for test of all accessible attributes"));
  assertTrue(proc3.description().equals("full"));
  assertTrue(proc1.priority() == 3); // default priority
  assertTrue(proc2.priority() == 5);
  boolean gotException = false;
  try {
      proc1.setPriority(0);
  } catch (InvalidPriorityException exc) {
      gotException = true;
  }
  assertTrue(gotException);
  proc1.setPriority(1);
  gotException = false;
  try {
      proc2.setPriority(6);
  } catch (InvalidPriorityException exc) {
      gotException = true;
  }
  assertTrue(gotException);
  proc2.setPriority(4);
  assertTrue(proc1.priority() == 1);
  assertTrue(proc2.priority() == 4);

  /* Make sure that process attributes are no longer
     accessible after removal of process */
  procDir.removeProcess(proc1.getWfProcess());
  procDir.removeProcess(proc2.getWfProcess());
  procDir.removeProcess(proc3.getWfProcess());
  boolean processNotAccessible = false;
  try {
      int dummy = proc1.priority();
  } catch (RemoteException exc) {
      processNotAccessible = true;
  }
  assertTrue(processNotAccessible);
    }

    /**
     * Test activitiy information for minimal and full description.
     * @exception Exception if an error occurs
     */
    public void testActivities() throws Exception {
  ProcessMgr mgrMin = defDir.processMgr("SystemTest_minimal", "minimal");
  ProcessMgr mgrFull = defDir.processMgr("SystemTest_full", "full");
//   WfProcess proc1 = mgrMin.createProcess(requester);
//   WfProcess proc2 = mgrFull.createProcess(requester);
//   WfProcess proc3 = mgrFull.createProcess(requester);
  WrappedProcess proc1
      = new WrappedProcess(mgrMin.createProcess(requester));
  WrappedProcess proc2
      = new WrappedProcess(mgrFull.createProcess(requester));
  WrappedProcess proc3
      = new WrappedProcess(mgrFull.createProcess(requester));

  // Test activity of process 1
  assertTrue(proc1.steps().size() == 1);
  WrappedActivity act = (WrappedActivity)proc1.steps().toArray()[0];
  assertTrue(act.assignments().size() == 0);
  assertTrue(act.name() == null);
  assertTrue(act.priority() == 3); // Default priority
  assertTrue(act.container().key().equals(proc1.key()));
  assertTrue(act.nextActivities().size() == 0);

  // Test activities of processes 2 and 3
  assertTrue(proc2.steps().size() == 3);
  assertTrue(proc3.steps().size() == 3);
  Iterator it = proc2.steps().iterator();
  List acts = new LinkedList();
  while (it.hasNext()) {
      act = (WrappedActivity)it.next();
      acts.clear();
      if (act.name().equals("ACT1")) {
    assertTrue(act.priority() == 1);
    assertTrue(act.description()
         .equals("Activity with dummy implementation"));
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.container().equals(proc2));
    assertTrue(act.nextActivities().size() == 1);
    acts.add("SET1");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("ACT2")) {
    assertTrue(act.priority() == 2);
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 1);
    acts.add("SET1");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("SET1")) {
    assertTrue(act.priority() == 3); // default priority
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 0);
      } else {
    assertTrue("Invalid activity " + act.name(), false);
      }
  }
  it = proc3.steps().iterator();
  Set step3Keys = new HashSet();
  while (it.hasNext()) {
      step3Keys.add(((WrappedActivity) it.next()).key());
  }
  it = proc3.activitiesInState("open.not_running.not_started")
      .iterator();
  Set state3NSKeys = new HashSet();
  while (it.hasNext()) {
      state3NSKeys.add(((WrappedActivity) it.next()).key());
  }
  it = proc3.activitiesInState("open.not_running.not_started")
      .iterator();
  Set state3NRKeys = new HashSet();
  while (it.hasNext()) {
      state3NRKeys.add(((WrappedActivity) it.next()).key());
  }
  it = proc2.activitiesInState("open.not_running")
      .iterator();
  Set state2Keys = new HashSet();
  while (it.hasNext()) {
      state2Keys.add(((WrappedActivity) it.next()).key());
  }
  // Make sure that all activities are in state
  // "open.not_running.not_started" and differ between process
  // instances.
  assertTrue(step3Keys.equals(state3NSKeys));
  assertTrue(step3Keys.equals(state3NRKeys));
  assertTrue(!step3Keys.equals(state2Keys));
  assertTrue(proc3.activitiesInState("open.not_running.suspended")
       .size() == 0);
  assertTrue(proc3.steps().size()
       == proc3.activitiesInState("open").size());
  assertTrue(proc3.activitiesInState("closed").size() == 0);
 
  assertTrue(proc1.workflowState() == WfExecutionObject.State.OPEN);
  assertTrue(proc2.workflowState() == WfExecutionObject.State.OPEN);
  assertTrue(proc3.workflowState() == WfExecutionObject.State.OPEN);

  procDir.removeProcess(proc1.getWfProcess());
  procDir.removeProcess(proc2.getWfProcess());
  procDir.removeProcess(proc3.getWfProcess());
    }

    /**
     * Test activitiy information for second block activity
     * @exception Exception if an error occurs
     */
    public void testActivitiesBlock1() throws Exception {
  ProcessMgr mgr = defDir.processMgr("SystemTest", "block_2_in_2_out");
  //WfProcess proc = mgr.createProcess(requester);
  WrappedProcess proc = new WrappedProcess(mgr.createProcess(requester));

  // Test activities of process
  assertTrue(proc.steps().size() == 9);
  Iterator it = proc.steps().iterator();
  List acts = new LinkedList();
  while (it.hasNext()) {
      WrappedActivity act = (WrappedActivity)it.next();
      acts.clear();
      if (act.name().equals("ACT1")) {
    assertTrue(act.priority() == 1);
    assertTrue(act.description()
         .equals("Activity with dummy implementation"));
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.container().key().equals(proc.key()));
    assertTrue(act.nextActivities().size() == 2);
    acts.add("B1");
    acts.add("B2");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("ACT2")) {
    assertTrue(act.priority() == 2);
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 2);
    acts.add("B1");
    acts.add("B2");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("ACT3")) {
    assertTrue(act.priority() == 3);
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 0);
      } else if (act.name().equals("ACT4")) {
    assertTrue(act.priority() == 4);
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 0);
      } else if (act.name().equals("B0")) {
    assertTrue(act.priority() == 3); // default priority
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 2);
    acts.add("B3");
    acts.add("B4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("B1")) {
    assertTrue(act.priority() == 3); // default priority
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 1);
    acts.add("B0");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("B2")) {
    assertTrue(act.priority() == 3); // default priority
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 1);
    acts.add("B0");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("B3")) {
    assertTrue(act.priority() == 5);
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 2);
    acts.add("ACT3");
    acts.add("ACT4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("B4")) {
    assertTrue(act.priority() == 3); // default priority
    assertTrue(act.description() == null);
    assertTrue(act.assignments().size() == 0);
    assertTrue(act.nextActivities().size() == 2);
    acts.add("ACT3");
    acts.add("ACT4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else {
    assertTrue("Invalid activity " + act.name(), false);
      }
  }
  procDir.removeProcess(proc.getWfProcess());
    }

    /**
     * Test activitiy information for second block activity
     * @exception Exception if an error occurs
     */
    public void testActivitiesBlock2() throws Exception {
  ProcessMgr mgr = defDir.processMgr("SystemTest", "block_diamond");
  //  WfProcess proc = mgr.createProcess(requester);
  WrappedProcess proc = new WrappedProcess(mgr.createProcess(requester));
  // Test activities of process
  assertTrue(proc.steps().size() == 15);
  Iterator it = proc.steps().iterator();
  List acts = new LinkedList();
  while (it.hasNext()) {
      WrappedActivity act = (WrappedActivity)it.next();
      acts.clear();
      if (act.name().equals("S1A1")) {
    assertTrue(act.nextActivities().size() == 2);
    acts.add("S1A3");
    acts.add("S1A4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S1A2")) {
    assertTrue(act.nextActivities().size() == 2);
    acts.add("S1A3");
    acts.add("S1A4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S1A3")) {
    assertTrue(act.nextActivities().size() == 3);
    acts.add("S2A1");
    acts.add("S3A1");
    acts.add("S3A2");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S1A4")) {
    assertTrue(act.nextActivities().size() == 3);
    acts.add("S2A1");
    acts.add("S3A1");
    acts.add("S3A2");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S2A1")) {
    assertTrue(act.nextActivities().size() == 3);
    acts.add("S2A2");
    acts.add("S2A3");
    acts.add("S2A4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S2A2")) {
    assertTrue(act.nextActivities().size() == 3);
    acts.add("S4A1");
    acts.add("S4A2");
    acts.add("S4A3");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S2A3")) {
    assertTrue(act.nextActivities().size() == 3);
    acts.add("S4A1");
    acts.add("S4A2");
    acts.add("S4A3");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S2A4")) {
    assertTrue(act.nextActivities().size() == 3);
    acts.add("S4A1");
    acts.add("S4A2");
    acts.add("S4A3");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S3A1")) {
    assertTrue(act.nextActivities().size() == 1);
    acts.add("S3A3");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S3A2")) {
    assertTrue(act.nextActivities().size() == 1);
    acts.add("S3A3");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S3A3")) {
    assertTrue(act.nextActivities().size() == 3);
    acts.add("S4A1");
    acts.add("S4A2");
    acts.add("S4A3");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S4A1")) {
    assertTrue(act.nextActivities().size() == 1);
    acts.add("S4A4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S4A2")) {
    assertTrue(act.nextActivities().size() == 1);
    acts.add("S4A4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S4A3")) {
    assertTrue(act.nextActivities().size() == 1);
    acts.add("S4A4");
    assertTrue(activitiesIncluded(act.nextActivities(), acts));
      } else if (act.name().equals("S4A4")) {
    assertTrue(act.nextActivities().size() == 0);
      } else {
    assertTrue("Invalid activity " + act.name(), false);
      }
  }
  procDir.removeProcess(proc.getWfProcess());
    }

    /**
     * Initialisation.
     * The <code>setUp</code> method defines the way a state change is
     * realized. Override this method to change this way.
     * @exception Exception if an error occurs
     */
    protected void setUp() throws Exception {
  super.setUp();
  WorkflowService wfs = WorkflowServiceFactory.newInstance()
      .newWorkflowService();
  try {
      defDir = new WrappedProcessDefinitionDirectory
    (wfs.processDefinitionDirectory());
  } catch(RemoteException exc) {
      System.err.println("Process definition directory not accessible: "
             + exc.getMessage());
      System.exit(-1);
  }

  // Read process definitions
  importProcessDefinition("/procdef/full.xml");
  importProcessDefinition("/procdef/minimal.xml");
  importProcessDefinition("/procdef/blockActivities.xml");
  procDir = wfs.processDirectory();
  requester = new DefaultRequester(wfs);
    }

    private static boolean activitiesIncluded(List activities, List names)
    throws Exception {
  List acts = new LinkedList();
  Iterator it = activities.iterator();
  while (it.hasNext()) {
      acts.add(((WrappedActivity) it.next()).name());
  }
  return acts.containsAll(names) && (acts.size() == names.size());
    }

    private void importProcessDefinition(String name) throws Exception {
  StringBuffer processDefinition = new StringBuffer();
  InputStream is = getClass().getResourceAsStream(name);
  BufferedReader in = new BufferedReader
      (new InputStreamReader(is, "ISO-8859-1"));
  String line = null;
  while ((line = in.readLine())!= null) {
      processDefinition.append(line+"\n");
  }
  try {
      defDir.importProcessDefinitions(processDefinition.toString());
  } catch (ImportException exc) {
      Iterator msg = exc.messages().iterator();
      while (msg.hasNext()) {
    System.out.println(((PrioritizedMessage)msg.next())
           .message());
      }
  }
    }
}
TOP

Related Classes of procdef.Create

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.