Package process

Source Code of process.ProcData

/*
* 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: ProcData.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1.1.3  2004/08/18 15:18:47  drmlipp
* Update to 1.2
*
* Revision 1.20  2004/02/13 09:01:41  lipp
* Method renamed.
*
* Revision 1.19  2004/02/09 15:15:29  lipp
* Support for looking up processes by the value of a data item.
*
* Revision 1.18  2003/10/21 21:00:45  lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.17  2003/10/08 11:52:55  huaiyang
* make test weblogic compatible.
*
* Revision 1.16  2003/06/27 09:44:13  lipp
* Fixed copyright/license information.
*
* Revision 1.15  2003/05/14 08:30:07  lipp
* Package import behaviour changed.
*
* Revision 1.14  2003/04/26 16:46:55  lipp
* Made unittests and systemtests coexist in eclipse.
*
* Revision 1.13  2003/04/26 16:12:35  lipp
* Moved some classes to reduce package dependencies.
*
* Revision 1.12  2003/04/16 19:25:04  lipp
* Adapted to jdk 1.4
*
* Revision 1.11  2003/03/31 16:50:29  huaiyang
* Logging using common-logging.
*
* Revision 1.10  2003/02/25 17:08:27  lipp
* Reorganized requester implementation.
*
* Revision 1.9  2003/02/05 15:57:06  lipp
* Replaced DummyRequester with DefaultRequester.
*
* Revision 1.8  2002/10/23 07:29:15  lipp
* Adapted to state handling changes.
*
* Revision 1.7  2002/09/08 18:49:18  lipp
* Proper use of packageId and processId.
*
* Revision 1.6  2002/08/30 13:37:05  lipp
* Using Workflow engine facade now.
*
* Revision 1.5  2002/08/29 12:49:52  lipp
* Fixed lookup.
*
* Revision 1.4  2002/08/21 22:06:48  lipp
* Finished transition to ProcessMgrStub.
*
* Revision 1.3  2002/08/20 07:20:19  lipp
* Extended test.
*
* Revision 1.2  2002/08/19 19:21:06  lipp
* Fixed.
*
* Revision 1.1  2002/08/19 15:29:02  lipp
* New test.
*
*/
package process;

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

import javax.security.auth.login.LoginException;

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

import de.danet.an.workflow.omgcore.InvalidDataException;
import de.danet.an.workflow.omgcore.ProcessData;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.workflow.omgcore.WfRequester;

import de.danet.an.workflow.api.DefaultProcessData;
import de.danet.an.workflow.api.DefaultRequester;
import de.danet.an.workflow.api.FactoryConfigurationError;
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 common.UTLoginContext;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

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

    static final org.apache.commons.logging.Log logger
  = org.apache.commons.logging.LogFactory.getLog(ProcData.class);

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

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

    /**
     * Check initialized data.
     */
    public void verifyInit() throws Exception {
  Basic.importProcessDefinitions("/process/testXPDL.xml");
  WfRequester req = new DefaultRequester(workflowService());
  // create the process
  WfProcess process = createProcess("ut-process", "jut1", req);
  ProcessData procData = process.processContext ();
  assertTrue (procData.containsKey("testValue"));
  assertTrue (procData.get("testValue").equals ("42"));
    }
 
    /**
     * Check change data.
     */
    public void modifyData() throws Exception {
  WfRequester req = new DefaultRequester(workflowService());
  // create the process
  WfProcess process = createProcess("ut-process", "jut1", req);
  ProcessData pd = new DefaultProcessData ();
  pd.put ("testValue", "modifiedValue");
  process.setProcessContext (pd);
  ProcessData procData = process.processContext ();
  assertTrue (procData.get("testValue").equals ("modifiedValue"));
  boolean caught = false;
  pd.clear ();
  pd.put ("Test key", "42");
  try {
      process.setProcessContext (pd);
  } catch (InvalidDataException inv) {
      caught = true;
  }
  assertTrue (caught);
    }

    /**
     * Lookup by data.
     */
    public void lookupByData () throws Exception {
  WfRequester req = new DefaultRequester(workflowService());

  // Remove all old processes
  ProcessDefinitionDirectory procDefDir
      = workflowService().processDefinitionDirectory ();
  ProcessDirectory procDir = workflowService().processDirectory ();
  ProcessMgr pmgr = procDefDir.processMgr("ut-process", "dataItemLookup");
  Collection oldProcs = pmgr.processes();
  for (Iterator i = oldProcs.iterator(); i.hasNext ();) {
      procDir.removeProcess ((Process)i.next());
  }

  // Create some processes, first with null data item
  WfProcess null1 = pmgr.createProcess(req);
  WfProcess null2 = pmgr.createProcess(req);
  null2.start (); // start one to show it makes no difference

  // Now with value item
  ProcessData pd = new DefaultProcessData ();
  pd.put ("testValue", "Find this");
  WfProcess procThis1 = pmgr.createProcess(req);
  procThis1.setProcessContext (pd);
  WfProcess procThis2 = pmgr.createProcess(req);
  procThis2.setProcessContext (pd);
  WfProcess procThis3 = pmgr.createProcess(req);
  procThis3.setProcessContext (pd);

  pd.put ("testValue", "Find that");
  WfProcess procThat1 = pmgr.createProcess(req);
  procThat1.setProcessContext (pd);
  WfProcess procThat2 = pmgr.createProcess(req);
  procThat2.setProcessContext (pd);

  // very long value item
  String dummyText = "Streng dem definierten Wesen des Blindtextes "
      + "folgend, fungiere ich als solcher und gebe mich unverbindlich "
      + "inhaltsleer. In bedr�ckender Enge in vorgefertigte Masken "
      + "gepresst friste ich ein freudloses Dasein auf dem schmalen "
      + "Grat zwischen Nichtbeachtung und Bedeutungslosigkeit und habe "
      + "doch eine Bitte: Handeln Sie Sinn stiftend f�r meine Existenz "
      + "und lesen Sie mich.";
  pd.put ("testValue", dummyText);
  WfProcess procLong = pmgr.createProcess(req);
  procLong.setProcessContext (pd);

  // Do tests
  Collection c = pmgr.findByDataItem("testValue", null);
  assertTrue (c.size () == 2);
  c = toKeys (c);
  assertTrue (c.contains(null1.key()));
  assertTrue (c.contains(null2.key()));

  c = pmgr.findByDataItem ("testValue", "Find this");
  assertTrue (c.size () == 3);
  c = toKeys (c);
  assertTrue (c.contains(procThis1.key ()));
  assertTrue (c.contains(procThis2.key ()));
  assertTrue (c.contains(procThis3.key ()));
 
  c = pmgr.findByDataItem ("testValue", "Find that");
  assertTrue (c.size () == 2);
  c = toKeys (c);
  assertTrue (c.contains(procThat1.key ()));
  assertTrue (c.contains(procThat2.key ()));

  c = pmgr.findByDataItem ("testValue", dummyText);
  assertTrue (c.size () == 1);
  c = toKeys (c);
  assertTrue (c.contains(procLong.key ()));

  // Cleanup
  oldProcs = pmgr.processes();
  for (Iterator i = oldProcs.iterator(); i.hasNext ();) {
      procDir.removeProcess ((Process)i.next());
  }
    }

    private Collection toKeys (Collection pc) throws Exception {
  Collection res = new ArrayList ();
  for (Iterator i = pc.iterator(); i.hasNext ();) {
      res.add (((Process)i.next()).key ());
  }
  return res;
    }
}
TOP

Related Classes of process.ProcData

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.