Package procdef

Source Code of procdef.CacheTests

/*
* Danet GmbH
* Beratung und Software-Entwicklung
* Gesch�ftstelle AN
*
* $Id: CacheTests.java 2326 2007-03-27 21:59:44Z mlipp $
*
* $Log$
* Revision 1.3  2006/10/13 13:58:32  drmlipp
* Adapted to new environment.
*
* 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.8  2004/01/27 11:45:33  lipp
* Preserve newlines when reading process definitions.
*
* Revision 1.7  2003/10/21 21:00:45  lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.6  2003/10/08 07:42:34  lipp
* Made tests weblogic compatible.
*
* Revision 1.5  2003/04/26 16:46:55  lipp
* Made unittests and systemtests coexist in eclipse.
*
* Revision 1.4  2003/04/23 14:28:12  lipp
* Improved modelling of header data.
*
* Revision 1.3  2003/04/16 19:25:04  lipp
* Adapted to jdk 1.4
*
* Revision 1.2  2002/09/27 12:02:56  barzik
* removed obsolete println
*
* Revision 1.1  2002/09/27 12:00:25  barzik
* add cache tests ...
*
*/
package procdef;

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

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.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 Caching-Testf�lle f�r das
* Prozessdefinitionsverzeichnis.
*/
public class CacheTests 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
     * @param name test case name
     */
    public CacheTests(String name) {
  super (name);
    }

    /**
     * Stellt diese TestSuite zusammen.
     * @return the test suite
     */
    public static Test suite() {
        TestSuite suite = new TestSuite();
  suite.addTest(new CacheTests("connect"));
  suite.addTest(new CacheTests("checkUpdatedProcessDefinition"));
        return new EJBClientTest (plc, suite);
    }
 
   /**
     * Simple test to check the jndi settings
     * @throws Exception ...
     */
    public void connect() throws Exception {
  InitialContext ic = new InitialContext();
  assertTrue (ic != null);
    }

    /**
     * Tests if an updated process definition is used, rather than the cached
     * version of the process definition.
     * Imports a process definition, reads the package header's creation
     * date, imports a duplicate of the the first process definition which
     * differs in the creation date, only.
     * The saved craetion date (from the first process definition) and the
     * current creation date (from the dublicate) are expected to differ.
     * In this case, it can be assumed, that the duplicate was found in the
     * database, rather than in the cache.
     * @throws Exception ...
     */
    public void checkUpdatedProcessDefinition() throws Exception {
        ProcessDefinitionDirectory pdd
            = WorkflowServiceFactory.newInstance()
            .newWorkflowService().processDefinitionDirectory();

  // import the origin process definition
  InputStream is = getClass().getResourceAsStream
      ("/procdef/initialProcessesCache1.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());

  // Lookup for the process definition and save creation date
  ProcessDefinition pd
      = pdd.lookupProcessDefinition("ut-procdef", "jut2");
  assertTrue (pd!=null);
  String firstDate = pd.processHeader().packageHeader().created();

  // Import the duplicate process definition
  is = getClass().getResourceAsStream
      ("/procdef/initialProcessesCache2.xml");
  assertTrue (is != null);
  br = new BufferedReader
      (new InputStreamReader(is, "ISO-8859-1"));
  sb = new StringBuffer();
  st = null;
  while ((st = br.readLine()) != null) {
      sb.append(st + "\n");
  }
  pdd.importProcessDefinitions(sb.toString());

  // Lookup for the duplicate process definition
  pd = pdd.lookupProcessDefinition("ut-procdef", "jut2");
  assertTrue (pd!=null);
  String secondDate = pd.processHeader().packageHeader().created();

  // check for different creation dates
  //System.err.println(firstDate);
  //System.err.println(secondDate);
  assertTrue(!firstDate.equals(secondDate));
    }
}
TOP

Related Classes of procdef.CacheTests

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.