Package wfxml

Source Code of wfxml.Factory

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2005 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: Factory.java 2330 2007-03-29 11:45:42Z schnelle $
*
* $Log$
* Revision 1.10  2007/03/27 21:59:42  mlipp
* Fixed lots of checkstyle warnings.
*
* Revision 1.9  2007/03/01 12:29:30  schnelle
* Enhanced Instance.SetProperties to process ContextData.
*
* Revision 1.8  2007/02/02 08:18:29  schnelle
* Prepared tests with an Umlaut.
*
* Revision 1.7  2007/02/01 12:39:13  schnelle
* Use of receiver toool to keep the first activity running.
*
* Revision 1.6  2007/02/01 08:49:23  drmlipp
* Fixed.
*
* Revision 1.5  2007/01/31 15:13:20  schnelle
* Unified method to create the base url.
*
* Revision 1.4  2007/01/31 13:39:45  schnelle
* Implemented setUp of test cases.
*
* Revision 1.3  2007/01/31 10:57:36  schnelle
* Adapted to change in receiver key.
*
* Revision 1.2  2007/01/30 11:56:15  drmlipp
* Merged Wf-XML branch.
*
* Revision 1.1.2.6  2006/12/20 14:38:33  schnelle
* Implemented Factory GetDefinition.
*
* Revision 1.1.2.5  2006/12/19 14:44:12  schnelle
* Implementation of GetProperties for ServiceRegistry and Factory.
*
* Revision 1.1.2.4  2006/12/14 08:51:05  schnelle
* Implemented CompleteActivity.
*
* Revision 1.1.2.3  2006/12/12 09:35:19  schnelle
* Implemented ChangeState for Instance.
*
* Revision 1.1.2.2  2006/12/11 12:22:31  schnelle
* Support of process creation with a later start.
*
* Revision 1.1.2.1  2006/12/01 15:31:28  schnelle
* Separation of test cases dependend on the role.
*
* Revision 1.4.6.7  2006/12/01 14:18:00  schnelle
* Added support for schema type for data in create process
*
* Revision 1.4.6.6  2006/12/01 12:50:11  schnelle
* Basic import of context data for process creation.
*
* Revision 1.4.6.5  2006/11/30 12:45:20  schnelle
* Basic implementation of Factory CreateInstance.
*
* Revision 1.4.6.4  2006/11/30 10:38:21  schnelle
* Implementation of Factory ListInstance.
*
* Revision 1.4.6.3  2006/11/29 14:13:03  schnelle
* Take respect to namespaces of asap requests and responses.
*
* Revision 1.4.6.2  2006/11/29 11:05:40  schnelle
* Full implementation of the request and response headers.
*
* Revision 1.4.6.1  2006/11/28 15:32:35  schnelle
* Proper selection of the response generator.
*
* Revision 1.4  2006/09/29 12:32:11  drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.3  2005/01/24 21:11:39  mlipp
* Extended.
*
* Revision 1.2  2005/01/24 20:26:01  mlipp
* Reverted saaj back to 1.1 to fit Axis version.
*
* Revision 1.1  2005/01/23 21:44:23  mlipp
* Initial version.
*
*/
package wfxml;

import java.util.Iterator;

import javax.xml.soap.Name;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import de.danet.an.util.XMLUtil;

/**
* Test WfXML factory resource.
* @author Dirk Schnelle
*/
public class Factory extends TestCase {
    /** The factory resource. */
    private String factory;
   
    private String timestamp;
   
    /**
     * Constructor of this TestCase.
     * @param name name of this test case.
     */
    public Factory(String name) {
  super (name);
    }

    /**
     * Creates this test suite.
     * @return created test suite.
     */
    public static Test suite() {
        TestSuite suite = new TestSuite();
        suite.addTest(new Factory("createProcInstanceStartImmediately"));
        suite.addTest(new Factory("createProcInstanceStartLater"));
        suite.addTest(new Factory("getDefinition"));
        suite.addTest(new Factory("getProperties"));
        suite.addTest(new Factory("listProcInstances"));
        return suite;
    }

   
    /* (non-Javadoc)
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception {
//        String sender = Factory.class.getName() + "/setUp";
//        String id = "43";

//        ServiceRegistry.importDefinition(sender, id);
        factory = ServiceRegistry.getTestProcessFactory();

        timestamp = XMLUtil.toXsdLocalDateTime(new java.util.Date());
       
        super.setUp();
    }

    /**
     * Test Factory ListInstances.
     * @exception Exception
     *            Test failed.
     */
    public void listProcInstances() throws Exception {
        String sender = Factory.class.getName() + "/listProcInstances";
        String id = "43";
       
        SOAPMessage message = Basic.createMessage();
        Basic.fillRequestHeadet(message, factory, sender, id);
        Basic.createActionElement(message, "ListInstancesRq");
       
        SOAPMessage response = Basic.call(message);
        response.writeTo(System.out);
       
        Basic.checkNoFault(response);
       
        assertEquals(sender, Basic.getHeaderValue(response, "ReceiverKey"));
        assertEquals(factory, Basic.getHeaderValue(response, "SenderKey"));
        assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
       
        SOAPBodyElement processlist = Basic.getFirstBodyElement(response);
        Name answerName = processlist.getElementName();
        assertEquals(Basic.ASAP_NS, answerName.getURI());
        assertEquals("ListInstancesRs", answerName.getLocalName());
        for (Iterator processIterator = processlist.getChildElements();
            processIterator.hasNext();) {
           
            SOAPElement child = (SOAPElement) processIterator.next();
            Name childName = child.getElementName();
            assertEquals("as", childName.getPrefix());
            assertEquals("Instance", childName.getLocalName());
           
            String instanceKey
                = Basic.getChildTextContent(child,  "InstanceKey");
            assertFalse(instanceKey.equals(""));
            String instanceName = Basic.getChildTextContent(child, "Name");
            assertFalse(instanceName.equals(""));
        }
    }

    /**
     * Test Factory create instance and start it automatically.
     * @exception Exception
     *            Test failed.
     */
    public void createProcInstanceStartImmediately() throws Exception {
        String sender = Factory.class.getName()
            + "/createProcInstanceStartImmediately";
        String id = "43";

        SOAPMessage message = Basic.createMessage();
        Basic.fillRequestHeadet(message, factory, sender, id);
        SOAPElement action
            = Basic.createActionElement(message, "CreateInstanceRq");
                           
        SOAPElement name = action.addChildElement("Name", "as");
        name.addTextNode("wfxmltest factory " + timestamp);
        SOAPElement cd = action.addChildElement("ContextData", "as");
        cd.addNamespaceDeclaration("pd",
                "http://localhost:8080/wfxml/dummy-pd.xsd");     
       
        SOAPElement stringdata = cd.addChildElement("newpkg_wp1_string", "pd");
        stringdata.addTextNode("text content " + timestamp);
        SOAPElement intdata = cd.addChildElement("newpkg_wp1_integer", "pd");
        intdata.addTextNode("42");
        SOAPElement floatdata = cd.addChildElement("newpkg_wp1_float", "pd");
        floatdata.addTextNode("42.42");
        SOAPElement booldata = cd.addChildElement("newpkg_wp1_boolean", "pd");
        booldata.addTextNode("true");
        SOAPElement datedata = cd.addChildElement("newpkg_wp1_date", "pd");
        datedata.addTextNode(timestamp);
        SOAPElement schemadata = cd.addChildElement("newpkg_wp1_schema", "pd");
        SOAPElement order = schemadata.addChildElement("order");
        order.setAttribute("id", "08/15");
        SOAPElement position1 = order.addChildElement("position");
        position1.setAttribute("pos", "1");
        SOAPElement position2 = order.addChildElement("position");
        position2.setAttribute("pos", "2");
       
        SOAPMessage response = Basic.call(message);

        Basic.checkNoFault(response);
       
        assertEquals(sender, Basic.getHeaderValue(response, "ReceiverKey"));
        assertEquals(factory, Basic.getHeaderValue(response, "SenderKey"));
        assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
       
        SOAPBodyElement processlist = Basic.getFirstBodyElement(response);
        Name answerName = processlist.getElementName();
        assertEquals(Basic.ASAP_NS, answerName.getURI());
        assertEquals("CreateInstanceRs", answerName.getLocalName());
        Iterator processIterator = processlist.getChildElements();
        assertTrue(processIterator.hasNext());
        SOAPElement child = (SOAPElement) processIterator.next();
        Name childName = child.getElementName();
        assertEquals("as", childName.getPrefix());
        assertEquals("InstanceKey", childName.getLocalName());
       
        String instanceKey = XMLUtil.getFirstLevelTextContent(child);
        assertFalse(instanceKey.equals(""));
        assertFalse(processIterator.hasNext());
    }

    /**
     * Test Factory create instance and start it later.
     * @exception Exception
     *            Test failed.
     */
    public void createProcInstanceStartLater() throws Exception {
        String sender = Factory.class.getName() + "/createProcInstance";
        String id = "43";
       
        SOAPMessage message = Basic.createMessage();
        Basic.fillRequestHeadet(message, factory, sender, id);
        SOAPElement action
            = Basic.createActionElement(message, "CreateInstanceRq");
        SOAPElement start = action.addChildElement("StartImmediately", "as");
        start.addTextNode("NO");

        SOAPElement cd = action.addChildElement("ContextData", "as");
        cd.addNamespaceDeclaration("pd",
                "http://localhost:8080/wfxml/dummy-pd.xsd");       

        SOAPElement name = action.addChildElement("Name", "as");
        name.addTextNode("wfxmltest factory " + timestamp);
        SOAPElement stringdata = cd.addChildElement("newpkg_wp1_string", "pd");
        stringdata.addTextNode("text content " + timestamp);
        SOAPElement intdata = cd.addChildElement("newpkg_wp1_integer", "pd");
        intdata.addTextNode("43");
        SOAPElement floatdata = cd.addChildElement("newpkg_wp1_float", "pd");
        floatdata.addTextNode("43.43");
        SOAPElement booldata = cd.addChildElement("newpkg_wp1_boolean", "pd");
        booldata.addTextNode("true");
        SOAPElement datedata = cd.addChildElement("newpkg_wp1_date", "pd");
        datedata.addTextNode(timestamp);
        SOAPElement schemadata = cd.addChildElement("newpkg_wp1_schema", "pd");
        SOAPElement order = schemadata.addChildElement("order");
        order.setAttribute("id", "08/16");
        SOAPElement position1 = order.addChildElement("position");
        position1.setAttribute("pos", "1");
        SOAPElement position2 = order.addChildElement("position");
        position2.setAttribute("pos", "2");
       
        SOAPMessage response = Basic.call(message);

        Basic.checkNoFault(response);
       
        assertEquals(sender, Basic.getHeaderValue(response, "ReceiverKey"));
        assertEquals(factory, Basic.getHeaderValue(response, "SenderKey"));
        assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
       
        SOAPBodyElement processlist = Basic.getFirstBodyElement(response);
        Name answerName = processlist.getElementName();
        assertEquals(Basic.ASAP_NS, answerName.getURI());
        assertEquals("CreateInstanceRs", answerName.getLocalName());
        Iterator processIterator = processlist.getChildElements();
        assertTrue(processIterator.hasNext());
        SOAPElement child = (SOAPElement) processIterator.next();
        Name childName = child.getElementName();
        assertEquals("as", childName.getPrefix());
        assertEquals("InstanceKey", childName.getLocalName());
       
        String instanceKey = XMLUtil.getFirstLevelTextContent(child);
        assertFalse(instanceKey.equals(""));
        assertFalse(processIterator.hasNext());
    }

    /**
     * Test Factory getProperties.
     */
    public void getDefinition() throws Exception {
        String sender = Factory.class.getName() + "/getDefinition";
        String id = "44";
       
        SOAPMessage message = Basic.createMessage();
        Basic.fillRequestHeadet(message, factory, sender, id);
        SOAPBodyElement action
            = Basic.createActionElement(message, "GetDefinitionRq");
        SOAPElement language = action.addChildElement("ProcessLanguage", "wfxml");
        language.addTextNode("XPDL");
       
        SOAPMessage response = Basic.call(message);
       
        Basic.checkNoFault(response);
       
        assertEquals(sender, Basic.getHeaderValue(response, "ReceiverKey"));
        assertEquals(factory, Basic.getHeaderValue(response, "SenderKey"));
        assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
       
        SOAPBodyElement processlist = Basic.getFirstBodyElement(response);
        Name answerName = processlist.getElementName();
        assertEquals(Basic.WFXML_NS, answerName.getURI());
        assertEquals("GetDefinitionRs", answerName.getLocalName());
    }
   
    /**
     * Test Factory getProperties.
     */
    public void getProperties() throws Exception {
        String sender = Factory.class.getName() + "/getProperties";
        String id = "45";
       
        SOAPMessage message = Basic.createMessage();
        Basic.fillRequestHeadet(message, factory, sender, id);
        Basic.createActionElement(message, "GetPropertiesRq");
       
        SOAPMessage response = Basic.call(message);
       
        Basic.checkNoFault(response);
       
        assertEquals(sender, Basic.getHeaderValue(response, "ReceiverKey"));
        assertEquals(factory, Basic.getHeaderValue(response, "SenderKey"));
        assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
       
        SOAPBodyElement processlist = Basic.getFirstBodyElement(response);
        Name answerName = processlist.getElementName();
        assertEquals(Basic.ASAP_NS, answerName.getURI());
        assertEquals("GetPropertiesRs", answerName.getLocalName());
    }
   
    /**
     * Creates a process without starting it and returns the instance key.
     * @param testFactory the factory resource
     * @param procName the name of the new process
     * @return key of the created instance.
     * @throws SOAPException
     *         Error in the SOAP message.
     */
    static String startTestProcess(String testFactory, String procName)
        throws SOAPException {
        String sender = Factory.class.getName() + "/startTestProcess";
        String id = "43";
        String time = XMLUtil.toXsdLocalDateTime(new java.util.Date());

        SOAPMessage message = Basic.createMessage();
        Basic.fillRequestHeadet(message, testFactory, sender, id);
        SOAPElement action
            = Basic.createActionElement(message, "CreateInstanceRq");
        SOAPElement cd = action.addChildElement("ContextData", "as");
        cd.addNamespaceDeclaration("pd",
                "http://localhost:8080/wfxml/dummy-pd.xsd");       

        SOAPElement start = action.addChildElement("StartImmediately", "as");
        start.addTextNode("YES");
        SOAPElement name = action.addChildElement("Name", "as");
        name.addTextNode(procName);
        SOAPElement stringdata = cd.addChildElement("newpkg_wp1_string", "pd");
        stringdata.addTextNode("text content " + time);
        SOAPElement intdata = cd.addChildElement("newpkg_wp1_integer", "pd");
        intdata.addTextNode("43");
        SOAPElement floatdata = cd.addChildElement("newpkg_wp1_float", "pd");
        floatdata.addTextNode("43.43");
        SOAPElement booldata = cd.addChildElement("newpkg_wp1_boolean", "pd");
        booldata.addTextNode("true");
        SOAPElement datedata = cd.addChildElement("newpkg_wp1_date", "pd");
        datedata.addTextNode(time);
        SOAPElement schemadata = cd.addChildElement("newpkg_wp1_schema", "pd");
        SOAPElement order = schemadata.addChildElement("order");
        order.setAttribute("id", "08/16");
        SOAPElement position1 = order.addChildElement("position");
        position1.setAttribute("pos", "1");
        SOAPElement position2 = order.addChildElement("position");
        position2.setAttribute("pos", "2");
       
        SOAPMessage response = Basic.call(message);
       
        SOAPBodyElement processlist = Basic.getFirstBodyElement(response);
        Iterator processIterator = processlist.getChildElements();
        SOAPElement child = (SOAPElement) processIterator.next();
       
        return XMLUtil.getFirstLevelTextContent(child);
    }  
}
TOP

Related Classes of wfxml.Factory

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.