Package process

Source Code of process.ToolInvocation

/*
* 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: ToolInvocation.java 2326 2007-03-27 21:59:44Z mlipp $
*
* $Log$
* Revision 1.4  2006/10/13 13:58:32  drmlipp
* Adapted to new environment.
*
* Revision 1.3  2006/10/07 20:41:34  mlipp
* Merged J2EE 1.4 adaptions from test branch.
*
* Revision 1.2  2006/09/29 12:32:10  drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.1.1.3  2004/08/18 15:18:47  drmlipp
* Update to 1.2
*
* Revision 1.18  2004/01/27 11:45:33  lipp
* Preserve newlines when reading process definitions.
*
* Revision 1.17  2003/10/21 21:00:45  lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.16  2003/10/08 11:52:55  huaiyang
* make test weblogic compatible.
*
* Revision 1.15  2003/09/19 13:12:29  lipp
* Adapted to closed.completed having a substate.
*
* Revision 1.14  2003/06/27 09:44:13  lipp
* Fixed copyright/license information.
*
* Revision 1.13  2003/04/26 16:46:55  lipp
* Made unittests and systemtests coexist in eclipse.
*
* Revision 1.12  2003/04/17 13:28:41  lipp
* Modification for analysis fixed problem. Magic.
*
* Revision 1.11  2003/04/16 19:25:04  lipp
* Adapted to jdk 1.4
*
* Revision 1.10  2003/02/25 17:08:27  lipp
* Reorganized requester implementation.
*
* Revision 1.9  2003/02/24 10:46:41  lipp
* Removed usage of System.out and .err.
*
* Revision 1.8  2003/02/19 08:35:12  lipp
* Added delay.
*
* Revision 1.7  2003/02/05 15:57:06  lipp
* Replaced DummyRequester with DefaultRequester.
*
* Revision 1.6  2002/11/19 15:14:52  lipp
* New transition manager.
*
* Revision 1.5  2002/10/23 11:36:47  lipp
* Got them running again.
*
* Revision 1.4  2002/10/23 07:29:15  lipp
* Adapted to state handling changes.
*
* Revision 1.3  2002/10/22 17:19:01  lipp
* Still adapting to state handling changes.
*
* Revision 1.2  2002/09/24 15:54:08  lipp
* Removed not needed import.
*
* Revision 1.1  2002/09/23 12:57:40  huaiyang
* Check the datafield.
*
*
*/
package process;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.Iterator;

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

import common.UTLoginContext;
import javax.security.auth.login.LoginException;

import de.danet.an.util.EJBUtil;
import de.danet.an.util.junit.EJBClientTest;
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.ProcessMgr;
import de.danet.an.workflow.api.WorkflowService;
import de.danet.an.workflow.api.WorkflowServiceFactory;
import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectoryHome;
import de.danet.an.workflow.omgcore.ProcessData;
import de.danet.an.workflow.omgcore.WfActivity;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.workflow.omgcore.WfRequester;

/**
* Test the life cycle of different processes.
*/
public class ToolInvocation extends TestCase {
    private static UTLoginContext plc = null;
    static {
  try {
      plc = new UTLoginContext();
      plc.login();
  } catch (LoginException e) {
      throw new IllegalStateException (e.getMessage ());
  }
    }

    /**
     * Constructor of this TestCase
     */
    public ToolInvocation(String name) {
  super (name);
    }

    /**
     * Stellt diese TestSuite zusammen.
     */
    public static Test suite() {
        TestSuite suite = new TestSuite();
     suite.addTest(new ToolInvocation("importProcessDefinitions"));
     suite.addTest(new ToolInvocation("processjutToolInvocation"));
        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;
    }

    /**
     * Import the process definitions from a XPDL file
     * unsing the ProcessDefinitionDirectory bean.
     */
    public void importProcessDefinitions() throws Exception {
  // Create process definition directory bean
        ProcessDefinitionDirectory pdd
            = workflowService().processDefinitionDirectory();

  InputStream is = getClass()
            .getResourceAsStream("/process/testToolInvocation.xml");
  assertTrue (is != null);
  BufferedReader br = new BufferedReader
      (new InputStreamReader(is, "ISO-8859-1"));
  StringBuffer sb = new StringBuffer();
  String st;
  while ((st = br.readLine()) != null) {
      sb.append(st + "\n");
  }
  pdd.importProcessDefinitions(sb.toString());
  Collection processDefinitions = pdd.processDefinitions();
  assertTrue (processDefinitions.size() > 0);
    }

    private WfProcess createProcess
  (String pkgId, String prcId, WfRequester req)
        throws Exception {
  ProcessDefinitionDirectory procDir = null;
  try {
      procDir = workflowService().processDefinitionDirectory();
      ProcessMgr pmgr = procDir.processMgr(pkgId, prcId);
      return pmgr.createProcess (req);
  } finally {
      workflowService().release (procDir);
  }
    }
 
    /**
     *
     */
    public void processjutToolInvocation() throws Exception {
  WfRequester req = new DefaultRequester(workflowService());
  // create the process
  WfProcess process
      = createProcess("ut-process", "jut_tool_invocation", req);
  assertTrue(process.state().equals("open.not_running.not_started"));
  // start the process
  process.start();
  Thread.sleep (1000);
  assertTrue(process.state().startsWith("open.running"));
  WfActivity act = actByName(process, "Account Antrag erstellen");
  assertTrue(invoke(act));
  act = actByName(process, "Account Antrag bearbeiten");
  assertTrue(invoke(act));
  Thread.sleep (1500);
  assertTrue(actByName(process, "Account Antrag r�ckmelden").state()
       .startsWith("closed.completed"));
  assertTrue(process.state().startsWith("closed.completed"));
    }

    private WfActivity actByName(WfProcess proc, String name) throws Exception {
  WfActivity a = null;
  for (Iterator it = proc.steps().iterator(); it.hasNext(); ) {
      WfActivity ai = (WfActivity)it.next();
      if (ai.name().equals (name)) {
    a = ai;
    break;
      }
  }
  return a;
    }

    private boolean invoke(WfActivity a) throws Exception {
  assertTrue(a.state() != null);
  ProcessData processData = a.processContext();
  // Check data field has been read correctly.
  processData.containsKey("emailAddress");
  processData.containsValue("account@bank.com");
  a.complete();
  Thread.sleep (1000);
  return true;
    }

}
TOP

Related Classes of process.ToolInvocation

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.