Package ras

Source Code of ras.Engine

/*
* Danet GmbH
* Beratung und Software-Entwicklung
* Gesch�ftstelle AN
*
* $Id: Engine.java 1733 2006-10-13 13:59:37Z drmlipp $
*
* $Log$
* Revision 1.4  2006/10/07 20:41:34  mlipp
* Merged J2EE 1.4 adaptions from test branch.
*
* Revision 1.3  2005/08/18 14:49:12  drmlipp
* Removed staffmgmt dependend test cases.
*
* 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.25  2004/02/21 21:31:01  lipp
* Some more refactoring to resolve cyclic dependencies.
*
* Revision 1.24  2003/11/19 14:04:31  lipp
* Proper authentication handling.
*
* Revision 1.23  2003/10/21 21:00:45  lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.22  2003/10/08 11:52:55  huaiyang
* make test weblogic compatible.
*
* Revision 1.21  2003/05/23 15:42:41  lipp
* Fixed deployment unit dependencies.
*
* Revision 1.20  2003/05/02 14:55:58  lipp
* Resolved some more package dependencies.
*
* Revision 1.19  2003/04/26 16:46:55  lipp
* Made unittests and systemtests coexist in eclipse.
*
* Revision 1.18  2003/04/16 19:25:04  lipp
* Adapted to jdk 1.4
*
* Revision 1.17  2003/02/25 17:08:27  lipp
* Reorganized requester implementation.
*
* Revision 1.16  2003/01/13 20:29:42  lipp
* Classpath fixes.
*
* Revision 1.15  2002/12/19 21:37:42  lipp
* Reorganized interfaces.
*
* Revision 1.14  2002/10/23 11:36:47  lipp
* Got them running again.
*
* Revision 1.13  2002/09/18 21:26:51  lipp
* Removed SAXFacade (integrated with WorkflowEngine).
*
* Revision 1.12  2002/09/18 20:48:21  lipp
* Cleanly separated workflow engine and service.
*
* Revision 1.11  2002/09/18 13:00:26  lipp
* Renamed WorkflowEngine to WorkflowService and introduced
* WorkflowServiceFactory.
*
* Revision 1.10  2002/09/08 18:49:18  lipp
* Proper use of packageId and processId.
*
* Revision 1.9  2002/09/04 20:50:44  lipp
* Adapted to new process manager name schema.
*
* Revision 1.8  2002/08/30 21:32:07  lipp
* Finished transition to WorkflowEngine.
*
* Revision 1.7  2002/08/30 13:37:05  lipp
* Using Workflow engine facade now.
*
* Revision 1.6  2002/08/26 20:23:14  lipp
* Lots of method renames.
*
* Revision 1.5  2002/08/21 22:06:48  lipp
* Finished transition to ProcessMgrStub.
*
* Revision 1.4  2002/08/04 11:39:04  lipp
* Fixed test case.
*
* Revision 1.3  2002/02/03 21:41:42  lipp
* Cleaned up unittests.
*
* Revision 1.2  2002/01/24 14:59:50  huaiyang
* Add test method for autoAssignResources.
*
* Revision 1.1  2002/01/23 14:09:57  huaiyang
* Adapted to API changed and new test case.
*
*/
package ras;

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

import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
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.WfActivity;
import de.danet.an.workflow.omgcore.WfAssignment;
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.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.ejbs.WorkflowEngine;
import de.danet.an.workflow.ejbs.WorkflowEngineHome;
import de.danet.an.workflow.spis.ras.ResourceAssignmentService;

import common.UTLoginContext;
import junit.framework.*;

public class Engine 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 Engine(String name) {
  super (name);
    }

    /**
     * Stellt diese TestSuite zusammen.
     */
    public static Test suite() {
        TestSuite suite = new TestSuite();
  suite.addTest(new Engine("runProcess"));
//   suite.addTest(new Engine("autoAssignResources"));
        return new EJBClientTest (plc, suite);
    }
    
    private static ResourceAssignmentService ras = null;

    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;
    }

    /**
     * Initialisierung.
     */
    protected void setUp() throws Exception {
    }

    private static WfProcess testProc = null;

    /**
     * Run the process
     */
    public void runProcess () throws Exception {
  // start process
  testProc = createProcess ("ut-ras", "ras_test");
  assertTrue (testProc != null);
  assertTrue(testProc.state().equals("open.not_running.not_started"));
  testProc.start();
  assertTrue(testProc.state().startsWith("open.running"));
  Thread.sleep (1000);
    }

//     /**
//      * Check autoAssignResources
//      */
//     public void autoAssignResources() throws Exception {
//   if (testProc == null)
//       runProcess();
 
//   String[][] names = {{"M1", "Test, JUnit"},
//           {"M2", "Lipp, Michael"},
//           {"G?", "Auftragsbearbeitung"}};
//   InitialContext ic = new InitialContext();
//   Object objref = ic.lookup("de.danet.an.workflow.StaffDirectory");
//   StaffDirectoryHome home
//       = (StaffDirectoryHome)PortableRemoteObject.narrow
//       (objref, StaffDirectoryHome.class);
//   StaffDirectory sd = home.create();
//   StaffGroup sg = sd.findStaffGroupByName (names[2][1]);
//   names[2][0] = "G" + sg.key();

//   Collection allActs = testProc.steps();
//   for (int i = 0; i < 3; i++) {
//       assertTrue(assignmentExists(names[i][0], names[i][1]));
//   }
//     }

    /**
     * Check if the resource identified by its key is assigned to the
     * activity whose container is the created test process.
     */
    private boolean assignmentExists(String key, String name)
  throws Exception {
  boolean found = false;
  WfResource resource = ras.resourceByKey(key);
  Collection assignedActivities = ras.workItems(resource);
  for (Iterator i = assignedActivities.iterator(); i.hasNext();) {
      WfAssignment assignment = (WfAssignment)i.next();
      WfActivity act = assignment.activity();
      if (testProc.key().equals(act.container().key())) {
    found = true;
    assertTrue(assignment.assignee().resourceName()
         .equals(name));
    break;
      }
  }
  return found;
    }

    /**
     * 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.Engine

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.