WSIF.java :  » Workflow-Engines » wfmopen-2.1.1 » tools » Java Open Source

Java Open Source » Workflow Engines » wfmopen 2.1.1 
wfmopen 2.1.1 » tools » WSIF.java
/*
 * 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: WSIF.java,v 1.2 2006/09/29 12:32:08 drmlipp Exp $
 *
 * $Log: WSIF.java,v $
 * Revision 1.2  2006/09/29 12:32:08  drmlipp
 * Consistently using WfMOpen as projct name now.
 *
 * Revision 1.1.1.2  2003/12/19 13:01:45  drmlipp
 * Updated to 1.1rc1
 *
 * 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/06/02 14:19:05  huaiyang
 * change the check.
 *
 * Revision 1.4  2003/05/28 15:17:21  huaiyang
 * integrate the testWSIF- and testWSIFBasic.xml
 *
 * Revision 1.3  2003/05/28 13:59:39  huaiyang
 * new test of googleSearch.
 *
 * Revision 1.2  2003/04/16 19:58:49  lipp
 * Adapted to jdk 1.4
 *
 * Revision 1.1  2003/03/26 11:14:34  huaiyang
 * initial.
 *
 *
 */
package tools; 

import java.util.Iterator;
import java.util.Map;

import junit.framework.Test;
import junit.framework.TestSuite;
import process.WfMOpenTestCase;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.ProcessMgr;
import de.danet.an.workflow.omgcore.WfProcess;
import de.danet.an.util.junit.EJBClientTest;


/**
 * Test the tool of WSIFDynamicInvocationTool.
 * @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
 * @version 1.0
 */
public class WSIF extends WfMOpenTestCase {
    private ProcessDefinitionDirectory pdd = null;
  
   /**
     * Constructor of this TestCase
     * @param name a <code>String</code> value
     */
    public WSIF(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 WSIF("importProcessDefinitions"));
  // suite.addTest(new WSIF("checkWSIFToolInvocation"));
      // suite.addTest(new WSIF("googleSearch"));
     suite.addTest(new WSIF("removeProcessDefinition"));
        return new EJBClientTest (plc, suite);
    }

    /**
     * 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();
  xpdlFile = "/tools/testWSIF.xml";
  System.out.println("xpdlFile = " + xpdlFile);
  pdd = workflowService().processDefinitionDirectory();
    }

    /**
     * Test a simple process definition with a simple soap tool invocation. 
     * @exception Exception if an error occurs
     */
    public void checkWSIFToolInvocation() throws Exception {
  // create the process
  ProcessDefinitionDirectory pdd 
      = workflowService().processDefinitionDirectory();
  // dynamic invoke WSIF with WSDL definition as DOM tree.
  ProcessMgr pmgr = pdd.processMgr("st-testWSIF", "testWSIF1");
  WfProcess process = pmgr.createProcess(defaultRequester());
   process.start();
  checkResult(process);
  // dynamic invoke WSIF with WSDL definition retrieved from URL.
  ProcessMgr pmgr2 = pdd.processMgr("st-testWSIF", "testWSIF2");
  WfProcess process2 = pmgr2.createProcess(defaultRequester());
   process2.start();
  checkResult(process2);
    }

    /**
     * Test a soap tool invocation which returns a complex data type of JDOM 
     * element. 
     * @exception Exception if an error occurs
     */
    public void googleSearch() throws Exception {
  ProcessMgr pmgr3 = pdd.processMgr("st-testWSIF", "testWSIF3");
  WfProcess process3 = pmgr3.createProcess(defaultRequester());
   process3.start();
  Thread.sleep(30000); 
   Map map = (Map)process3.result();
  for (Iterator it2 = map.keySet().iterator(); it2.hasNext();) {
      String name = (String) it2.next();
      System.out.println("name = " + name);
      if (name.equals("searchresult")) {
    String returnResult = (String)map.get(name);
    System.out.println("return = " + returnResult);
      }
   }
    }

    private void checkResult(WfProcess process) throws Exception {
  // wait so that invocation of the WSIF tool for the first activity 
  // is completed. Wait time is needed for wsdl fetch and wsif dynamic
  // calling.
  Thread.sleep(10000); 
   Map map = (Map)process.result();
  for (Iterator it2 = map.keySet().iterator(); it2.hasNext();) {
      String name = (String) it2.next();
      if (name.equals("Result")) {
    float stockquote = Float.parseFloat((String)map.get(name));
    System.out.println
        ("stockquote of " + name + " = " + stockquote);
    assertTrue(stockquote != 0);
      }
   }
    }

    /**
     * Test a simple process definition with a simple soap tool invocation. 
     * @exception Exception if an error occurs
     */
    public void removeProcessDefinition() throws Exception {
  removeProcessDefinition("st-testWSIF", "testWSIF1");
  removeProcessDefinition("st-testWSIF", "testWSIF2");
  removeProcessDefinition("st-testWSIF", "testWSIF3");
    }
}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.