Package ras

Source Code of ras.Basic

/*
* Danet GmbH
* Beratung und Software-Entwicklung
* Gesch�ftstelle AN
*
* $Id: Basic.java 2368 2007-05-03 21:58:25Z mlipp $
*
* $Log$
* Revision 1.5  2006/10/13 13:58:32  drmlipp
* Adapted to new environment.
*
* Revision 1.4  2006/10/07 20:41:34  mlipp
* Merged J2EE 1.4 adaptions from test branch.
*
* Revision 1.3  2005/04/22 15:11:07  drmlipp
* Merged changes from 1.3 branch up to 1.3p15.
*
* Revision 1.2.2.1  2005/04/21 12:51:38  drmlipp
* Fixed test.
*
* Revision 1.2  2004/12/30 12:10:23  mlipp
* Adadpted to JNDI name changes.
*
* Revision 1.1.1.3  2004/08/18 15:18:47  drmlipp
* Update to 1.2
*
* Revision 1.39  2004/06/14 19:37:20  lipp
* Fixed assignment functions and cleaned up assignment related
* interfaces.
*
* Revision 1.38  2004/03/03 17:23:14  lipp
* Implemented setAssignee and cleaned up code a bit.
*
* Revision 1.37  2004/02/21 21:31:01  lipp
* Some more refactoring to resolve cyclic dependencies.
*
* Revision 1.36  2004/01/27 11:45:33  lipp
* Preserve newlines when reading process definitions.
*
* Revision 1.35  2003/10/21 21:00:45  lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.34  2003/10/08 11:52:55  huaiyang
* make test weblogic compatible.
*
* Revision 1.33  2003/05/02 14:55:58  lipp
* Resolved some more package dependencies.
*
* Revision 1.32  2003/04/26 16:46:55  lipp
* Made unittests and systemtests coexist in eclipse.
*
* Revision 1.31  2003/04/16 19:25:04  lipp
* Adapted to jdk 1.4
*
* Revision 1.30  2003/02/25 17:08:27  lipp
* Reorganized requester implementation.
*
* Revision 1.29  2003/02/05 15:57:06  lipp
* Replaced DummyRequester with DefaultRequester.
*
* Revision 1.28  2003/01/13 20:29:42  lipp
* Classpath fixes.
*
* Revision 1.27  2002/12/19 21:37:42  lipp
* Reorganized interfaces.
*
* Revision 1.26  2002/12/05 10:20:39  lipp
* Adapted unittests to assignment changes.
*
* Revision 1.25  2002/12/04 16:05:08  lipp
* Reorganized assignment handling.
*
* Revision 1.24  2002/10/23 11:36:47  lipp
* Got them running again.
*
* Revision 1.23  2002/09/18 21:26:51  lipp
* Removed SAXFacade (integrated with WorkflowEngine).
*
* Revision 1.22  2002/09/18 20:48:21  lipp
* Cleanly separated workflow engine and service.
*
* Revision 1.21  2002/09/18 13:00:26  lipp
* Renamed WorkflowEngine to WorkflowService and introduced
* WorkflowServiceFactory.
*
* Revision 1.20  2002/09/08 18:49:18  lipp
* Proper use of packageId and processId.
*
* Revision 1.19  2002/09/04 20:50:44  lipp
* Adapted to new process manager name schema.
*
* Revision 1.18  2002/08/30 21:32:07  lipp
* Finished transition to WorkflowEngine.
*
* Revision 1.17  2002/08/30 13:37:05  lipp
* Using Workflow engine facade now.
*
* Revision 1.16  2002/08/26 20:23:14  lipp
* Lots of method renames.
*
* Revision 1.15  2002/08/21 22:06:48  lipp
* Finished transition to ProcessMgrStub.
*
* Revision 1.14  2002/06/27 10:48:36  lipp
* Adapted to change in RAS/RMS interface.
*
* Revision 1.13  2002/02/04 15:18:55  lipp
* Made ActivityFinderAndKey visible in EJB Remote interface.
*
* Revision 1.12  2002/02/03 21:41:42  lipp
* Cleaned up unittests.
*
* Revision 1.11  2002/01/23 14:09:57  huaiyang
* Adapted to API changed and new test case.
*
* Revision 1.10  2002/01/09 14:00:01  lipp
* Cleaned up relation between wfcore, resource assignment and resource
* management service.
*
* Revision 1.9  2001/12/19 09:06:15  lipp
* Added some comments.
*
* Revision 1.8  2001/12/18 22:16:53  lipp
* Restructured DOM generation, implemented "assignments" method from ras.
*
* Revision 1.7  2001/12/18 15:35:11  lipp
* Implemented workItems and isMemberOfWorkItem.
*
* Revision 1.6  2001/12/17 15:52:12  lipp
* New version.
*
* Revision 1.5  2001/12/17 12:14:04  lipp
* Adapted to configurable ResourceManagement/AssignmentServices.
*
* Revision 1.4  2001/12/16 21:48:57  lipp
* addAssignment implemented.
*
* Revision 1.3  2001/12/16 10:37:35  lipp
* Assignment service implemented.
*
* Revision 1.2  2001/12/15 18:04:28  lipp
* Fixed client class packing.
*
* Revision 1.1  2001/12/15 15:52:01  lipp
* Implementation of ActivityFinder completed.
*
*/
package ras;

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

import java.util.Collection;
import java.util.Iterator;

import javax.security.auth.login.LoginException;

import de.danet.an.util.EJBUtil;
import de.danet.an.util.junit.EJBClientTest;

import de.danet.an.workflow.omgcore.WfAssignment;
import de.danet.an.workflow.omgcore.WfAssignmentAuditEvent;
import de.danet.an.workflow.omgcore.WfAuditEvent;
import de.danet.an.workflow.omgcore.WfExecutionObject.State;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.workflow.omgcore.WfProcessMgr;
import de.danet.an.workflow.omgcore.WfResource;

import de.danet.an.workflow.api.Activity;
import de.danet.an.workflow.api.DefaultRequester;
import de.danet.an.workflow.api.FactoryConfigurationError;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.WorkflowService;
import de.danet.an.workflow.api.WorkflowServiceFactory;

import de.danet.an.workflow.apix.ExtActivity;
import de.danet.an.workflow.ejbs.WorkflowEngine;
import de.danet.an.workflow.ejbs.WorkflowEngineHome;
import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectoryHome;
import de.danet.an.workflow.spis.ras.ActivityFinder;
import de.danet.an.workflow.spis.ras.ResourceAssignmentService;
import de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory;
import de.danet.an.workflow.spis.rms.ResourceManagementService;
import de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory;

import common.UTLoginContext;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* Zusammenstellung aller RasObjectTests.
*/
public class Basic extends TestCase {
    private static UTLoginContext plc = null;
    static {
  try {
      plc = new UTLoginContext();
      plc.login();
  } catch (LoginException e) {
      throw new IllegalStateException (e.getMessage ());
  }
    }

    /**
     * Konstruktor zum Erzeugen eines TestCase
     */
    public Basic(String name) {
  super (name);
    }

    /**
     * Stellt diese TestSuite zusammen.
     */
    public static Test suite() {
        TestSuite suite = new TestSuite();
  suite.addTest(new Basic("getAFinder"));
  suite.addTest(new Basic("changeAssignment"));
  suite.addTest(new Basic("removeAssignment"));
        return new EJBClientTest (plc, suite);
    }

    private static WorkflowService wfsCache = null;

    private WorkflowService workflowService() {
  if (wfsCache == null) {
      try {
    WorkflowServiceFactory wfsf
        = WorkflowServiceFactory.newInstance ();
    wfsCache = wfsf.newWorkflowService();
      } catch (FactoryConfigurationError e) {
    throw new IllegalStateException (e.getMessage());
      }
  }
  return wfsCache;
    }

    private static WfProcess testProc = null;

    /**
     * "Simply" try to get a finder.
     */
    public void getAFinder () throws Exception {
  importProcessDefinition ();
  // To get a finder, we need a process.
  testProc = createProcess ("ut-ras", "ras_test");
  testProc.start ();
  while (testProc.workflowState() != State.OPEN) {
      Thread.sleep (100);
  }
  assertTrue (testProc != null);
  Collection acts = testProc.steps();
  assertTrue (acts.size() > 0);
  Iterator i = acts.iterator();
  ExtActivity act = (ExtActivity)i.next();
  assertTrue (act != null);
//  ActivityFinder af = act.activityFinder();
//  Activity restored = (Activity)af.find(act.key());
//  assertTrue (act.key().equals(restored.key()));
    }

    private static ResourceAssignmentService ras = null;

    /**
     * Change an assignment
     */
    public void changeAssignment () throws Exception {
  // find predefined resource "Test, JUnit" and "Lipp, Michael"
  WfResource resOP = null;
  WfResource resMLipp = null;
  Collection resList = workflowService().knownResources();
  for (Iterator i = resList.iterator(); i.hasNext();) {
      WfResource resource = (WfResource)i.next();
      if (resource.resourceName().equals ("ML")) {
    resMLipp = resource;
      }
      if (resource.resourceName().equals ("Order Processing")) {
    resOP = resource;
      }
  }
  assertTrue (resOP != null);
  assertTrue (resMLipp != null);
  // get current number of work items
  ExtActivity act = null;
  for (Iterator i = testProc.steps().iterator(); i.hasNext ();) {
      act = (ExtActivity)i.next();
      if (act.name().equals ("RAS Test A1")) {
    break;
      }
  }
  assertTrue (act.name().equals ("RAS Test A1"));
  // assign
  Collection assmnts = act.assignments ();
  WfAssignment amnt = (WfAssignment)assmnts.iterator().next ();
  assertTrue (resMLipp.resourceKey (), amnt.assignee().resourceKey()
        .equals (resMLipp.resourceKey()));
  amnt.setAssignee (resOP);
  assertTrue (amnt.assignee().resourceKey()
        .equals (resOP.resourceKey()));
  // re-get assignment to make sure
  assmnts = act.assignments ();
  assertTrue (assmnts.size() == 1);
  Iterator i = assmnts.iterator();
  WfAssignment assmnt = (WfAssignment)i.next();
  assertTrue (assmnt.assignee().resourceKey()
        .equals (resOP.resourceKey()));
    }

    /**
     * Remove an assignment
     */
    public void removeAssignment () throws Exception {
  // get current number of work items
  ExtActivity act = null;
  for (Iterator i = testProc.steps().iterator(); i.hasNext ();) {
      act = (ExtActivity)i.next();
      if (act.name().equals ("RAS Test A1")) {
    break;
      }
  }
  assertTrue (act.name().equals ("RAS Test A1"));
  // release
  Collection assmnts = act.assignments ();
  WfAssignment amnt = (WfAssignment)assmnts.iterator().next ();
  amnt.assignee().release (amnt, "");
  assmnts = act.assignments ();
  assertTrue (assmnts.size() == 0);
  // check events
  Thread.sleep (500);
  boolean noneToJ = false;
  boolean jToM = false;
  boolean mToNone = false;
  for (Iterator i = act.history().iterator (); i.hasNext ();) {
      WfAuditEvent evt = (WfAuditEvent)i.next ();
      if (evt instanceof WfAssignmentAuditEvent) {
    WfAssignmentAuditEvent ae = (WfAssignmentAuditEvent)evt;
    if (ae.oldResourceName() == null
        && ae.newResourceName().equals ("ML")
        && !noneToJ) {
        noneToJ = true;
    } else if (ae.oldResourceName().equals ("ML")
        && ae.newResourceName().equals ("Order Processing")
        && !jToM) {
        jToM = true;
    } else if (ae.oldResourceName().equals ("Order Processing")
        && ae.newResourceName() == null
        && !mToNone) {
        mToNone = true;
    } else {
        assertTrue (false);
    }
      }
  }
  assertTrue (noneToJ);
  assertTrue (jToM);
  assertTrue (mToNone);
    }

    /**
     * Uploading the XPDL file and saving the process definitions in the
     * database.
     */
    private void importProcessDefinition() throws Exception {
  // now read input
  InputStream is = getClass()
      .getResourceAsStream("/ras/rasTestXPDL.xml");
  if (is == null) {
      return;
  }
  BufferedReader br = null;
  br = new BufferedReader (new InputStreamReader(is, "ISO-8859-1"));
            
  StringBuffer toParse = new StringBuffer();
  String st;
  while ((st = br.readLine()) != null) {
      toParse.append(st + "\n");
  }

  ProcessDefinitionDirectory pdd
            = workflowService().processDefinitionDirectory();
  if (!pdd.processDefinitionExists("ut-ras", "ras_test")) {
      pdd.importProcessDefinitions(toParse.toString());
  }
    }

    /**
     * Try to create the process identified by the id
     */
    public WfProcess createProcess (String pkgId, String prcId)
        throws Exception {
  ProcessDefinitionDirectory pdd = null;
  try {
      pdd = workflowService().processDefinitionDirectory();
      WfProcessMgr pmgr = pdd.processMgr(pkgId, prcId);
      return pmgr.createProcess (new DefaultRequester(workflowService()));
  } finally {
      workflowService().release (pdd);
  }
    }

}
TOP

Related Classes of ras.Basic

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.