Package procdef

Source Code of procdef.Basic

/*
* Danet GmbH
* Beratung und Software-Entwicklung
* Gesch�ftstelle AN
*
* $Id: Basic.java 1733 2006-10-13 13:59:37Z drmlipp $
*
* $Log$
* Revision 1.2  2006/10/07 20:41:34  mlipp
* Merged J2EE 1.4 adaptions from test branch.
*
* Revision 1.1.1.3  2004/08/18 15:18:46  drmlipp
* Update to 1.2
*
* Revision 1.22  2004/01/27 11:45:33  lipp
* Preserve newlines when reading process definitions.
*
* Revision 1.21  2003/10/21 21:00:45  lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.20  2003/10/07 15:55:57  lipp
* Made tests weblogic compatible.
*
* Revision 1.19  2003/05/14 08:30:07  lipp
* Package import behaviour changed.
*
* Revision 1.18  2003/05/09 10:40:16  huaiyang
* test the reading of redefinable header in process.
*
* Revision 1.17  2003/04/26 16:46:55  lipp
* Made unittests and systemtests coexist in eclipse.
*
* Revision 1.16  2003/04/23 14:28:12  lipp
* Improved modelling of header data.
*
* Revision 1.15  2003/04/16 19:25:04  lipp
* Adapted to jdk 1.4
*
* Revision 1.14  2003/04/08 12:31:23  lipp
* Implemented version and category.
*
* Revision 1.13  2003/04/08 11:49:05  lipp
* ResultSignature implemented.
*
* Revision 1.12  2002/11/06 12:15:18  huaiyang
* Add the test of removeClosedProcess.
*
* Revision 1.11  2002/09/08 18:49:18  lipp
* Proper use of packageId and processId.
*
* Revision 1.10  2002/09/04 20:38:44  lipp
* Removed dubious use of id as process definition identifier.
*
* Revision 1.9  2002/09/02 12:26:51  huaiyang
* Use initialProcesses instead of testXPDL.
*
* Revision 1.8  2002/08/30 13:37:05  lipp
* Using Workflow engine facade now.
*
* Revision 1.7  2002/08/28 10:58:45  huaiyang
* Remove the test of importNewProcessDefintions temporarily.
*
* Revision 1.6  2002/08/28 09:24:12  huaiyang
* New method of importNewProcessDefinitions for new procDef spec.
*
* Revision 1.5  2002/08/26 20:23:14  lipp
* Lots of method renames.
*
* Revision 1.4  2002/08/25 18:51:01  lipp
* Extended test case.
*
* Revision 1.3  2002/08/22 08:47:29  lipp
* Some minor optimizations.
*
* Revision 1.2  2002/02/06 20:45:24  lipp
* Test for enabled.
*
* Revision 1.1  2002/02/03 21:41:42  lipp
* Cleaned up unittests.
*
*/
package procdef;

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

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

import javax.naming.InitialContext;
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.ProcessDataInfo;

import de.danet.an.workflow.api.ProcessDefinition;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.WorkflowServiceFactory;

import de.danet.an.workflow.ejbs.admin.ProcessDefinitionDirectoryHome;

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

/**
* Zusammenstellung der Basis-Testf�lle f�r das Prozessdefinitionsverzeichnis.
*/
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("connect"));
  suite.addTest(new Basic("importProcessDefinitions"));
     suite.addTest(new Basic("listProcessDefinitions"));
     suite.addTest(new Basic("disableProcessDefinition"));
       suite.addTest(new Basic("removeProcessDefinition"));
       suite.addTest(new Basic("getProcessDefinition"));
       suite.addTest(new Basic("removeClosedProcess"));
     suite.addTest(new Basic("importProcessDefinitions"));
     suite.addTest(new Basic("getSignatures"));
  suite.addTest(new Basic("redefinableHeader"));
        return new EJBClientTest (plc, suite);
    }
 
   /**
     * Simple test to check the jndi settings
     */
    public void connect() throws Exception {
  InitialContext ic = new InitialContext();
  assertTrue (ic != null);
    }

    /**
     * Import the process definitions from a XPDL file
     * unsing the ProcessDefinitionDirectory bean.
     */
    public void importProcessDefinitions() throws Exception {
  importProcessDefinitions("/procdef/initialProcesses.xml");
    }

    /**
     * Returns a list of all defined process definitions
     * from the ProcessDefinitionDirectory bean.
     */
    public void listProcessDefinitions() throws Exception {
        ProcessDefinitionDirectory pdd
            = WorkflowServiceFactory.newInstance()
            .newWorkflowService().processDefinitionDirectory();

  Collection processDefinitions = pdd.processDefinitions();
  assertTrue (processDefinitions.size() > 0);
  Collection ids = new ArrayList();
  Collection names = new ArrayList();
  for (Iterator pdi = processDefinitions.iterator(); pdi.hasNext();) {
      ProcessDefinition pd = (ProcessDefinition)pdi.next();
      ids.add (pd.processId());
      names.add (pd.processName());
  }
  assertTrue (ids.contains ("jut1"));
  assertTrue (names.contains ("JUnit Test Process 1"));
  assertTrue (ids.contains ("jut2"));
  assertTrue (names.contains ("JUnit Test Process 2"));
  assertTrue (ids.contains ("jut3"));
  assertTrue (names.contains ("JUnit Test Process 3"));
  assertTrue (ids.contains ("jut4"));
  assertTrue (names.contains ("JUnit Test Process 4"));
  assertTrue (ids.contains ("jut5"));
  assertTrue (names.contains ("JUnit Test Process 5"));
  assertTrue (ids.contains ("jut6"));
  assertTrue (names.contains ("JUnit Test Process 6"));
  assertTrue (ids.contains ("jut7"));
  assertTrue (names.contains ("JUnit Test Process 7"));
    }

    /**
     * Disable/Enable ProcessDefinitionDirectory.
     */
    public void disableProcessDefinition() throws Exception {
        ProcessDefinitionDirectory pdd
            = WorkflowServiceFactory.newInstance()
            .newWorkflowService().processDefinitionDirectory();

  Collection processDefinitions = pdd.processDefinitions();
  assertTrue (processDefinitions.size() > 0);
  ProcessDefinition pd
      = (ProcessDefinition)(processDefinitions.iterator().next());
  assertTrue (pdd.isEnabled(pd.packageId(), pd.processId()));
  pdd.setEnabled (pd.packageId(), pd.processId(), false);
  assertTrue (!pdd.isEnabled(pd.packageId(), pd.processId()));
  pdd.setEnabled (pd.packageId(), pd.processId(), true);
  assertTrue (pdd.isEnabled(pd.packageId(), pd.processId()));
    }

    /**
     * Removes a given process definition using the ProcessDirectory bean.
     */
    public void  removeProcessDefinition() throws Exception {
        ProcessDefinitionDirectory pdd
            = WorkflowServiceFactory.newInstance()
            .newWorkflowService().processDefinitionDirectory();

  ProcessDefinition pd
      = pdd.lookupProcessDefinition("ut-procdef", "jut1");
  assertTrue(pd!=null);
  pdd.removeProcessDefinition("ut-procdef", "jut1");
  boolean gotEx = false;
  try {
      pd = pdd.lookupProcessDefinition("ut-procdef", "jut1");
  } catch (Exception ex) {
      gotEx = true;
  }
  assertTrue(gotEx);
    }

    /**
     * Returns a process definition
     * from the ProcessDefinitionDirectory bean.
     */
    public ProcessDefinition getProcessDefinition() throws Exception {
        ProcessDefinitionDirectory pdd
            = WorkflowServiceFactory.newInstance()
            .newWorkflowService().processDefinitionDirectory();
 
  ProcessDefinition pd
      = pdd.lookupProcessDefinition("ut-procdef", "jut2");
  assertTrue (pd!=null);
  boolean gotEx = false;
  try {
      pd = pdd.lookupProcessDefinition("ut-procdef", "doesn't exist");
  } catch (Exception ex) {
      gotEx = true;
  }
  assertTrue(gotEx);
  return pd;
    }

    public void removeClosedProcess() throws Exception {
  ProcessDefinition procDef = getProcessDefinition();
  assertTrue(!procDef.removeClosedProcess());
    }

    /**
     * Test the signatures
     */
    public void getSignatures() throws Exception {
        ProcessDefinitionDirectory pdd
            = WorkflowServiceFactory.newInstance()
            .newWorkflowService().processDefinitionDirectory();
 
  ProcessDefinition pd
      = pdd.lookupProcessDefinition("ut-procdef", "called1");
  assertTrue (pd != null);
  assertTrue (pd.processHeader().created().equals ("07.04.2003"));
  assertTrue (pd.processHeader().description().equals ("Was tun"));
  ProcessDataInfo pdi = pd.resultSignature();
  assertTrue (pdi.keySet().size () == 1);
  assertTrue (pdi.containsKey("status"));
  assertTrue (pdi.get("status") == String.class);
    }

    /**
     * Test if the refinableHeader in the package header and in the process
     * header can be parsed correctly.
     */
    public void redefinableHeader() throws Exception {
  importProcessDefinitions("/procdef/testRedefinableHeader.xml");
        ProcessDefinitionDirectory pdd
            = WorkflowServiceFactory.newInstance()
            .newWorkflowService().processDefinitionDirectory();
  ProcessDefinition pd = pdd.lookupProcessDefinition
      ("ut-procdef", "testRedefinableHeader");
  assertTrue(pd.processHeader().author().equals("tester"));
  // Redefinable header of version in process overrides the version
  // defined in the package redefinable header.
  assertTrue(pd.processHeader().version().equals("1.2"));
  pdd.removeProcessDefinition("ut-procdef", "testRedefinableHeader");
    }

    public static void importProcessDefinitions(String filename)
  throws Exception {
        ProcessDefinitionDirectory pdd
            = WorkflowServiceFactory.newInstance()
            .newWorkflowService().processDefinitionDirectory();
  InputStream is = Basic.class.getResourceAsStream(filename);
  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);
    }
}
TOP

Related Classes of procdef.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.