Package procdef

Source Code of procdef.ClusteredProcData

/*
* 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: ClusteredProcData.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.1  2003/12/19 13:01:44  drmlipp
* Updated to 1.1rc1
*
* Revision 1.1  2003/11/06 15:52:43  huaiyang
* Initial.
*
* Revision 1.11  2003/11/03 13:35:37  huaiyang
* changed based on the supported of null and "" in oracle.
*
* Revision 1.10  2003/11/03 11:31:38  huaiyang
* Fix another error with reading proc data from oracle.
*
* Revision 1.9  2003/11/03 10:03:08  montag
* allow null or empty string for
* packageStringData (due to oracle handling).
*
* Revision 1.8  2003/10/21 21:00:45  lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.7  2003/10/08 12:39:40  huaiyang
* make test weblogic compatible.
*
* Revision 1.6  2003/06/27 09:44:03  lipp
* Fixed copyright/license information.
*
* Revision 1.5  2003/05/14 09:30:27  schlue
* Package names for minimal and full changed due to modified import behaviour.
*
* Revision 1.4  2003/05/07 09:54:43  schlue
* PR30 fixed.
*
* Revision 1.3  2003/04/26 16:12:22  lipp
* Moved some classes to reduce package dependencies.
*
* 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.2  2003/04/11 14:39:56  schlue
* System tests for activitites added.
*
* Revision 1.1  2003/04/10 09:44:08  schlue
* Test cases for process data added.
*
*
*
*/
package procdef;

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

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.rmi.RemoteException;
import java.util.Iterator;

import de.danet.an.util.junit.EJBClientTest;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.ProcessDirectory;
import de.danet.an.workflow.api.WorkflowServiceFactory;
import de.danet.an.workflow.api.WorkflowService;
import de.danet.an.workflow.api.ProcessMgr;
import de.danet.an.workflow.api.DefaultRequester;
import de.danet.an.workflow.api.PrioritizedMessage;
import de.danet.an.workflow.api.ImportException;
import de.danet.an.workflow.api.InvalidKeyException;
import de.danet.an.workflow.omgcore.InvalidDataException;
import de.danet.an.workflow.omgcore.WfActivity;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.workflow.omgcore.WfRequester;
import de.danet.an.workflow.omgcore.ProcessData;
import de.danet.an.workflow.omgcore.ProcessDataInfo;

import common.Util;

import process.WfMOpenTestCase;

/**
* Test dealing with process data (descriptions).
* Every process description that's needed, is imported here.
* @author <a href="mailto:schlueter@danet.de">Holger Schlueter</a>
* @version 1.0
*/
public class ClusteredProcData extends WfMOpenTestCase {
    static final org.apache.commons.logging.Log logger
  = org.apache.commons.logging.LogFactory.getLog(ClusteredProcData.class);
    /**
     * Access to process definition directory (singleton)
     */
    private ProcessDefinitionDirectory 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 ClusteredProcData(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 ClusteredProcData("testInfo"));
     suite.addTest(new ClusteredProcData("testData"));
     suite.addTest(new ClusteredProcData("modifyData"));
     suite.addTest(new ClusteredProcData("cleanup"))
        return new EJBClientTest (plc, suite);
    }

    /**
     * Test context signature of process description.
     * @exception Exception if an error occurs
     */
    public void testInfo() throws Exception {
  Util.logEntry("testInfo");
  ProcessMgr mgr = defDir.processMgr("SystemTest_full", "full");
  // Test context signature
  ProcessDataInfo ctxInfo = mgr.contextSignature();
  assertTrue(((Class)ctxInfo.get("packageBooleanData"))
       .isAssignableFrom(Boolean.class));
  assertTrue(((Class)ctxInfo.get("testString"))
       .isAssignableFrom(String.class));
  assertTrue(((Class)ctxInfo.get("packageIntegerData"))
       .isAssignableFrom(Long.class));
  assertTrue(((Class)ctxInfo.get("packageIntegerData"))
       .isAssignableFrom(Long.class));
  assertTrue(((Class)ctxInfo.get("packageStringData"))
       .isAssignableFrom(String.class));
  //wait to shutdown the processing instance
  Util.sleep(30000);

  // Test result signature (all OUT or INOUT parameters)
  Iterator res = mgr.resultSignature().values().iterator();
  ProcessDataInfo resInfo = mgr.resultSignature();
  assertTrue(((Class)resInfo.get("PARAM-InOut-String"))
       .isAssignableFrom(String.class));
  assertTrue(((Class)resInfo.get("PARAM-Out-Integer"))
       .isAssignableFrom(Long.class));

  mgr = defDir.processMgr("SystemTest_minimal", "minimal");
  //wait to shutdown the processing instance
  Util.sleep(30000);
  assertTrue(mgr.contextSignature().isEmpty());
  assertTrue(mgr.resultSignature().isEmpty());
  Util.logExit("testInfo");
    }

    /**
     * Test initial values of process data.
     * @exception Exception if an error occurs
     */
    public void testData() throws Exception {
  Util.logEntry("testData");
  ProcessMgr mgr = defDir.processMgr("SystemTest_full", "full");
  WfProcess proc = mgr.createProcess(requester);
  ProcessData data = proc.processContext();
  assertTrue(((Boolean)data.get("packageBooleanData")).booleanValue());
  assertTrue(((String)data.get("testString")).equals("WfMOpen"));
  assertTrue((((String)data.get("packageStringData")) == null));
  assertTrue(((Long)data.get("packageIntegerData")).intValue() == 3);

  //wait to shutdown the processing instance
  Util.sleep(30000);
  // Test access to context info via activity
  assertTrue(proc.steps().size() > 0);
  WfActivity act = (WfActivity)proc.steps().toArray()[0];
  data = act.processContext();
  assertTrue(((Boolean)data.get("packageBooleanData")).booleanValue());
  assertTrue(((String)data.get("testString")).equals("WfMOpen"));
  assertTrue((((String)data.get("packageStringData")) == null)
       || (((String)data.get("packageStringData")).equals("")));
  assertTrue(((Long)data.get("packageIntegerData")).intValue() == 3)

  procDir.removeProcess(proc);

  mgr = defDir.processMgr("SystemTest_minimal", "minimal");
  //wait to shutdown the processing instance
  Util.sleep(30000);
  proc = mgr.createProcess(requester);
  assertTrue(proc.processContext().isEmpty());
  procDir.removeProcess(proc);
  Util.logExit("testData");
    }

    /**
     * Test modification of process data.
     * @exception Exception if an error occurs
     */
    public void modifyData() throws Exception {
  Util.logEntry("modifyData");
  ProcessMgr mgr = defDir.processMgr("SystemTest_full", "full");
  WfProcess proc = mgr.createProcess(requester);
  ProcessData data = proc.processContext();
 
  assertTrue(((Boolean)data.get("packageBooleanData")).booleanValue());
  assertTrue(((String)data.get("testString")).equals("WfMOpen"));
  assertTrue((((String)data.get("packageStringData")) == null));
  assertTrue(((Long)data.get("packageIntegerData")).intValue() == 3);
  data.put("", null);
  //wait to shutdown the processing instance
  Util.sleep(30000);
  // Illegal empty entry
  boolean invalidData = false;
  try {
      proc.setProcessContext(data);
  } catch (InvalidDataException exc) {
      invalidData = true;   
  }
  assertTrue(invalidData);
  data.remove("");
  data.put("teststring", "illegal");
  data.put("packageIntegerData", "5");
  // Misspelled teststring and wrong data type for Integer
  invalidData = false;
  try {
      proc.setProcessContext(data);
  } catch (InvalidDataException exc) {
      invalidData = true;   
  }
  data.remove("teststring");
  Iterator it = data.keySet().iterator();
  // Still wrong data type for Integer
  invalidData = false;
  try {
      proc.setProcessContext(data);
  } catch (InvalidDataException exc) {
      invalidData = true;   
  }
  data.put("packageIntegerData", new Integer("5"));

  proc.setProcessContext(data);
  ProcessDataInfo ctxInfo = mgr.contextSignature();
  // Fetch data to check modifications
  data = proc.processContext();
  assertTrue(((Long)data.get("packageIntegerData")).intValue() == 5);

  procDir.removeProcess(proc);

  mgr = defDir.processMgr("SystemTest_minimal", "minimal");
  //wait to shutdown the processing instance
  Util.sleep(30000);
  proc = mgr.createProcess(requester);
  data = proc.processContext();
  assertTrue(data.isEmpty());
  proc.setProcessContext(data);
  data.put("", null);
  invalidData = false;
  try {
      proc.setProcessContext(data);
  } catch (InvalidDataException exc) {
      invalidData = true;   
  }
  assertTrue(invalidData);
  data.remove("");
  proc.setProcessContext(data);
 
  procDir.removeProcess(proc);
  Util.logExit("modifyData");
    }

    /**
     * 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);
    }

    /**
     * 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 = 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");
  procDir = wfs.processDirectory();
  requester = new DefaultRequester(wfs);
    }

    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.ClusteredProcData

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.