/*
* 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: ServiceRegistry.java 2329 2007-03-29 11:45:27Z schnelle $
*
* $Log$
* Revision 1.11 2007/03/27 21:59:42 mlipp
* Fixed lots of checkstyle warnings.
*
* Revision 1.10 2007/02/14 10:19:37 schnelle
* Cleaend imports.
*
* Revision 1.9 2007/02/02 08:18:29 schnelle
* Prepared tests with an Umlaut.
*
* Revision 1.8 2007/02/01 12:39:13 schnelle
* Use of receiver toool to keep the first activity running.
*
* Revision 1.7 2007/01/31 22:56:25 mlipp
* Fixed.
*
* Revision 1.6 2007/01/31 15:13:20 schnelle
* Unified method to create the base url.
*
* Revision 1.5 2007/01/31 13:39:45 schnelle
* Implemented setUp of test cases.
*
* Revision 1.4 2007/01/31 10:57:36 schnelle
* Adapted to change in receiver key.
*
* Revision 1.3 2007/01/30 21:02:22 mlipp
* Fixed resource path.
*
* Revision 1.2 2007/01/30 11:56:16 drmlipp
* Merged Wf-XML branch.
*
* Revision 1.1.2.5 2006/12/20 14:38:33 schnelle
* Implemented Factory GetDefinition.
*
* Revision 1.1.2.4 2006/12/19 14:44:12 schnelle
* Implementation of GetProperties for ServiceRegistry and Factory.
*
* Revision 1.1.2.3 2006/12/14 08:51:05 schnelle
* Implemented CompleteActivity.
*
* Revision 1.1.2.2 2006/12/12 09:35:19 schnelle
* Implemented ChangeState for Instance.
*
* 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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.soap.Detail;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Test WfXML service registry resource.
* @author Dirk Schnelle
*/
public class ServiceRegistry extends TestCase {
/** name of the default test process */
private static final String TEST_PROCESS_NAME = "wfxmltestprocess";
/** Base URL of the service registry */
private static final String BASE_URL = Basic.getBaseUrl("ServiceRegistry");
/**
* Constructor of this TestCase.
* @param name name of the test case.
*/
public ServiceRegistry(String name) {
super (name);
}
/**
* Creates this test suite.
* @return created test suite.
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new ServiceRegistry("newDefinition"));
suite.addTest(new ServiceRegistry("getProperties"));
suite.addTest(new ServiceRegistry("getPropertiesInvalidKey"));
suite.addTest(new ServiceRegistry("getPropertiesInvalidFactory"));
suite.addTest(new ServiceRegistry("listProcDefs"));
return suite;
}
/**
* Test Service Registry NewDefinition.
* @exception Exception
* Test failed.
*/
public void newDefinition() throws Exception {
String receiver = BASE_URL;
String sender = ServiceRegistry.class.getName() + "/newDefinition";
String id = "43";
SOAPMessage response = importDefinition(sender, id);
Basic.checkNoFault(response);
assertEquals(sender, Basic.getHeaderValue(response, "ReceiverKey"));
assertEquals(receiver, 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("NewDefinitionRs", answerName.getLocalName());
}
/**
* Imports the test process into WfMOpen.
* @param sender originator of the call
* @param id custom id
* @return response of the service call
* @throws SOAPException
* Error creating the SOAP message.
* @throws SAXException
* Error in the XPDL file.
* @throws IOException
* Error reading the XPDL file.
*/
static SOAPMessage importDefinition(String sender, String id)
throws SOAPException, SAXException, IOException {
String receiver = BASE_URL;
SOAPMessage message = Basic.createMessage();
Basic.fillRequestHeadet(message, receiver, sender, id);
SOAPBodyElement action
= Basic.createActionElement(message, "NewDefinitionRq");
SOAPElement language
= action.addChildElement("ProcessLanguage", "wfxml");
language.addTextNode("XPDL");
javax.xml.parsers.DocumentBuilderFactory factory
= DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new SAXException(e.getMessage(), e);
}
InputStream is = ServiceRegistry.class
.getResourceAsStream("/wfxml/wfxmltest.xpdl");
assertTrue (is != null);
BufferedReader br = new BufferedReader
(new InputStreamReader(is, "UTF-8"));
StringBuffer sb = new StringBuffer();
String st;
while ((st = br.readLine()) != null) {
sb.append(st + "\n");
}
org.w3c.dom.Document document
= builder.parse(new InputSource
(new StringReader(sb.toString())));
SOAPElement definition = action.addChildElement("Definition", "wfxml");
org.w3c.dom.Document owner = language.getOwnerDocument();
org.w3c.dom.Node node
= owner.importNode(document.getFirstChild(), true);
definition.appendChild(node);
message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
SOAPMessage response = Basic.call(message);
return response;
}
/**
* Retrieves the factory to handle the test process.
* @return factory key.
* @throws SOAPException
* Error in the SOAP message.
*/
static String getTestProcessFactory()
throws SOAPException {
String receiver = BASE_URL;
String sender = ServiceRegistry.class.getName()
+ "/getTestProcessFactory";
String id = "42";
SOAPMessage message = Basic.createMessage();
Basic.fillRequestHeadet(message, receiver,
sender, id);
Basic.createActionElement(message, "ListDefinitionsRq");
SOAPMessage response = Basic.call(message);
Basic.checkNoFault(response);
SOAPBodyElement processlist = Basic.getFirstBodyElement(response);
processlist.getElementName();
for (Iterator processIterator = processlist.getChildElements();
processIterator.hasNext();) {
SOAPElement child = (SOAPElement) processIterator.next();
String definitionName = Basic.getChildTextContent(child, "Name");
if (definitionName.equals(TEST_PROCESS_NAME)) {
return Basic.getChildTextContent(child, "DefinitionKey");
}
}
throw new SOAPException("Process '" + TEST_PROCESS_NAME
+ "' not found");
}
/**
* Test Service Registry GetProperties.
* @exception Exception
* Test failed.
*/
public void getProperties() throws Exception {
String receiver = BASE_URL;
String sender = ServiceRegistry.class.getName() + "/getProperties";
String id = "44";
SOAPMessage message = Basic.createMessage();
Basic.fillRequestHeadet(message, receiver, sender, id);
Basic.createActionElement(message, "GetPropertiesRq");
SOAPMessage response = Basic.call(message);
Basic.checkNoFault(response);
assertEquals(sender, Basic.getHeaderValue(response, "ReceiverKey"));
assertEquals(receiver, 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("GetPropertiesRs", answerName.getLocalName());
}
/**
* Test Service Registry GetProperties with an invalid receiver key.
* @exception Exception
* Test failed.
*/
public void getPropertiesInvalidKey() throws Exception {
String receiver = Basic.WFXML_SERVLET + "?Resource=";
String sender = ServiceRegistry.class.getName()
+ "/getPropertiesInvalidKey";
String id = "45";
SOAPMessage message = Basic.createMessage();
Basic.fillRequestHeadet(message, receiver, sender, id);
Basic.createActionElement(message, "GetPropertiesRq");
SOAPMessage response = Basic.call(message);
String code = Basic.getAsapErrorCode(response);
// We must obtain ASAP_INVALID_KEY.
assertEquals("105", code);
}
/**
* Test Service Registry GetProperties with an invalid factory.
* @exception Exception
* Test failed.
*/
public void getPropertiesInvalidFactory() throws Exception {
String receiver = Basic.WFXML_SERVLET + "?Resource=Invalid";
String sender = ServiceRegistry.class.getName()
+ "/getPropertiesInvalidFactory";
String id = "46";
SOAPMessage message = Basic.createMessage();
Basic.fillRequestHeadet(message, receiver, sender, id);
Basic.createActionElement(message, "GetPropertiesRq");
SOAPMessage response = Basic.call(message);
String code = Basic.getAsapErrorCode(response);
// We must obtain ASAP_INVALID_FACTORY.
assertEquals("502", code);
}
/**
* Test Service Registry ListDefinitions.
* @exception Exception
* Test failed.
*/
public void listProcDefs() throws Exception {
String receiver = BASE_URL;
String sender = ServiceRegistry.class.getName() + "/listProcDefs";
String id = "47";
SOAPMessage message = Basic.createMessage();
Basic.fillRequestHeadet(message, receiver, sender, id);
Basic.createActionElement(message, "ListDefinitionsRq");
SOAPMessage response = Basic.call(message);
Basic.checkNoFault(response);
assertEquals(sender, Basic.getHeaderValue(response, "ReceiverKey"));
assertEquals(receiver, Basic.getHeaderValue(response, "SenderKey"));
assertEquals(id, Basic.getHeaderValue(response, "RequestID"));
SOAPBodyElement procDefList = Basic.getFirstBodyElement(response);
Name answerName = procDefList.getElementName();
assertEquals(Basic.WFXML_NS, answerName.getURI());
assertEquals("ListDefinitionsRs", answerName.getLocalName());
for (Iterator processIterator = procDefList.getChildElements();
processIterator.hasNext();) {
SOAPElement child = (SOAPElement) processIterator.next();
Name childName = child.getElementName();
assertEquals("wfxml", childName.getPrefix());
assertEquals("DefinitionInfo", childName.getLocalName());
String definitionKey = Basic.getChildTextContent(child,
"DefinitionKey");
assertFalse(definitionKey.equals(""));
}
}
}