[jboss-svn-commits] JBL Code SVN: r19927 - in labs/jbossesb/trunk/product: rosetta/tests/src/org/jboss/soa/esb/listeners and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon May 12 05:27:38 EDT 2008
Author: tfennelly
Date: 2008-05-12 05:27:38 -0400 (Mon, 12 May 2008)
New Revision: 19927
Added:
labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/JBESB_1713_RedpillSoapUIClientServiceMBeanUnitTest.java
labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_JBESB_1713.xml
labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/handdator.wsdl
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java
labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/SoapUIClientServiceMBeanUnitTest.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1713
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java 2008-05-11 03:45:22 UTC (rev 19926)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/soap/OGNLUtils.java 2008-05-12 09:27:38 UTC (rev 19927)
@@ -67,40 +67,46 @@
}
public static String getOGNLExpression(Element element, String nameSpace) {
- StringBuffer ognlExpression = new StringBuffer();
- Node parent = element.getParentNode();
- boolean isInBody = false;
+ String preassignedOgnl = element.getAttributeNS(JBOSSESB_SOAP_NS, OGNL_ATTRIB);
- ognlExpression.append(getOGNLToken(element));
+ if(preassignedOgnl != null && !preassignedOgnl.equals("")) {
+ return preassignedOgnl;
+ } else {
+ StringBuffer ognlExpression = new StringBuffer();
+ Node parent = element.getParentNode();
+ boolean isInBody = false;
- while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
- Element parentElement = (Element) parent;
- String parentName = YADOMUtil.getName(parentElement);
+ ognlExpression.append(getOGNLToken(element));
- if (parentName.equalsIgnoreCase("body") && checkParentNameSpace( parent.getNamespaceURI(), nameSpace ) ) {
- isInBody = true;
- break;
+ while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
+ Element parentElement = (Element) parent;
+ String parentName = YADOMUtil.getName(parentElement);
+
+ if (parentName.equalsIgnoreCase("body") && checkParentNameSpace( parent.getNamespaceURI(), nameSpace ) ) {
+ isInBody = true;
+ break;
+ }
+
+ preassignedOgnl = parentElement.getAttributeNS(JBOSSESB_SOAP_NS, OGNL_ATTRIB);
+ if(preassignedOgnl != null && !preassignedOgnl.equals("")) {
+ ognlExpression.insert(0, "." + preassignedOgnl);
+ isInBody = true;
+ break;
+ } else {
+ ognlExpression.insert(0, getOGNLToken(parentElement));
+ }
+ parent = parent.getParentNode();
}
- String preassignedOgnl = parentElement.getAttributeNS(JBOSSESB_SOAP_NS, OGNL_ATTRIB);
- if(preassignedOgnl != null && !preassignedOgnl.equals("")) {
- ognlExpression.insert(0, "." + preassignedOgnl);
- isInBody = true;
- break;
- } else {
- ognlExpression.insert(0, getOGNLToken(parentElement));
+ if(!isInBody) {
+ return "";
}
- parent = parent.getParentNode();
- }
- if(!isInBody) {
- return "";
+ // Remove the leading '.'
+ ognlExpression.deleteCharAt(0);
+
+ return ognlExpression.toString();
}
-
- // Remove the leading '.'
- ognlExpression.deleteCharAt(0);
-
- return ognlExpression.toString();
}
public static String getOGNLToken(Element element) {
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java 2008-05-11 03:45:22 UTC (rev 19926)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java 2008-05-12 09:27:38 UTC (rev 19927)
@@ -71,7 +71,7 @@
invoker.deliverAsync(message);
sleep(50);
- assertEquals(message, MockAction.message);
+ assertTrue(message == MockAction.message);
esbConfig.stopController();
} finally {
@@ -124,7 +124,7 @@
invoker.deliverAsync(message);
sleep(50);
- assertEquals(message, MockAction.message);
+ assertTrue(message == MockAction.message);
}
public void test_sync() throws IOException, SAXException, ConfigurationException, ManagedLifecycleException, ParamRepositoryException, MessageDeliverException, RegistryException, FaultMessageException {
@@ -142,8 +142,8 @@
message.getBody().add("Hi there!");
Message response = invoker.deliverSync(message, 2000);
- assertEquals(message, MockAction.message);
- assertEquals(message, response);
+ assertTrue(message == MockAction.message);
+ assertTrue(message == response);
esbConfig.stopController();
} finally {
@@ -226,7 +226,7 @@
} catch (Exception e) {
fail("Error delivering message: " + e.getMessage());
}
- assertEquals(message, response);
+ assertTrue(message == response);
assertEquals("Tom Fennelly", response.getBody().get());
InVMListenerUnitTest.sleep(10);
Modified: labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java
===================================================================
--- labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java 2008-05-11 03:45:22 UTC (rev 19926)
+++ labs/jbossesb/trunk/product/services/soapui-client/src/main/java/org/jboss/soa/esb/services/soapui/SoapUIClientService.java 2008-05-12 09:27:38 UTC (rev 19927)
@@ -21,6 +21,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.StringReader;
import java.util.*;
import javax.xml.parsers.DocumentBuilder;
@@ -28,6 +29,7 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stream.StreamResult;
import org.apache.log4j.Logger;
import org.apache.commons.httpclient.HttpClient;
@@ -43,6 +45,7 @@
import org.milyn.resource.URIResourceLocator;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlProject;
@@ -162,20 +165,45 @@
return new EsbWsdlLoader(wsdl, httpClient);
}
- private String buildRequest(String soapMessage, Map params, String smooksResource, String soapNs) throws IOException, SAXException {
- Document messageDoc = getDocBuilder().parse(new ByteArrayInputStream(soapMessage.getBytes()));
+ private String buildRequest(String soapMessageTemplate, Map params, String smooksResource, String soapNs) throws IOException, SAXException {
+ Document messageDoc = getDocBuilder().parse(new InputSource(new StringReader(soapMessageTemplate)));
Element docRoot = messageDoc.getDocumentElement();
expandMessage(docRoot, params);
+
+ // Purposely not using log levels to output because I want to make
+ // it as easy as possible for the developer to dump the SOAP during dev. They
+ // just need to set "dumpSOAP" in the param Map....
+ boolean dumpSOAP = params.containsKey("dumpSOAP");
+ if(dumpSOAP) {
+ dumpSOAP("SOAP Template:", docRoot);
+ }
+
injectParameters(docRoot, params, soapNs);
+
if(smooksResource != null) {
applySmooksTransform(smooksResource, messageDoc);
}
+ if(dumpSOAP) {
+ dumpSOAP("SOAP Message (populated Template):", docRoot);
+ }
+
return XmlUtil.serialize(messageDoc.getChildNodes());
}
+ private void dumpSOAP(String message, Element docRoot) {
+ System.out.println("------------------------------------------------------------------------------------------------------------------------------------------");
+ System.out.println(message + "\n");
+ try {
+ YADOMUtil.serialize(docRoot, new StreamResult(System.out));
+ } catch (ConfigurationException e) {
+ logger.error("Unable to dump SOAP.", e);
+ }
+ System.out.println("------------------------------------------------------------------------------------------------------------------------------------------");
+ }
+
private void applySmooksTransform(String smooksResource, Document messageDoc) throws IOException, SAXException {
if(smooksResource != null) {
Smooks smooks = smooksCache.get(smooksResource);
Added: labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/JBESB_1713_RedpillSoapUIClientServiceMBeanUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/JBESB_1713_RedpillSoapUIClientServiceMBeanUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/JBESB_1713_RedpillSoapUIClientServiceMBeanUnitTest.java 2008-05-12 09:27:38 UTC (rev 19927)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.services.soapui;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.math.BigDecimal;
+import java.util.*;
+
+import javax.xml.transform.stream.StreamResult;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.services.soapui.orderprocessing.Order;
+import org.jboss.soa.esb.services.soapui.orderprocessing.LineItem;
+import org.jboss.soa.esb.services.soapui.orderprocessing.ProcessOrderRequest;
+import org.jboss.soa.esb.http.HttpClientFactory;
+import org.jboss.soa.esb.dom.YADOMUtil;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * @author someone at redpill
+ */
+public class JBESB_1713_RedpillSoapUIClientServiceMBeanUnitTest extends TestCase {
+
+ private class PostTrainMessage1 {
+ public String arg0 = "argument 0";
+ public List<String> arg1;
+ public boolean arg2 = true;
+ public String arg3 = "argument 3";
+ public long arg4 = 1;
+ public long arg5 = 2;
+ }
+
+ private class PostTrainMessage2 {
+ public String arg0 = "argument 0";
+ public String[] arg1;
+ public boolean arg2 = true;
+ public String arg3 = "argument 3";
+ public long arg4 = 1;
+ public long arg5 = 2;
+ }
+
+ private void addTrains(List<String> trains) {
+ trains.add(new String("1111"));
+ trains.add(new String("2222"));
+ trains.add(new String("3333"));
+ trains.add(new String("4444"));
+ }
+
+ private static final String WSDL_LOCATAION = "src/test/java/org/jboss/soa/esb/services/soapui";
+ private Properties properties;
+
+ protected void setUp() throws Exception {
+ properties = new Properties();
+ }
+
+ public void test_redpill() throws IOException, SAXException, ConfigurationException {
+ File wsdlFile = new File(WSDL_LOCATAION + "/handdator.wsdl");
+ SoapUIClientService mbean = new SoapUIClientService();
+ Map params = new HashMap();
+
+ params.put("dumpSOAP", null);
+
+ PostTrainMessage1 postTrainMessage1 = new PostTrainMessage1();
+ PostTrainMessage2 postTrainMessage2 = new PostTrainMessage2();
+ List<String> trains1 = new ArrayList<String>();
+ String[] trains2 = new String[4];
+
+ properties.setProperty(HttpClientFactory.TARGET_HOST_URL, wsdlFile.toURI().toString());
+
+ addTrains(trains1);
+ postTrainMessage1.arg1 = trains1;
+ trains1.toArray(trains2);
+ postTrainMessage2.arg1 = trains2;
+
+ params.put("postTrainMessage", postTrainMessage1);
+
+ String message = mbean.buildRequest(wsdlFile.toURI().toString(), "postTrainMessage", params, properties, null, null);
+ assertTrue("Generated SOAP message not as expected. See expected_JBESB_1713.xml. Generated message: \n" + message, compareCharStreams(getClass().getResourceAsStream("expected_JBESB_1713.xml"), new ByteArrayInputStream(message.getBytes())));
+
+ params.put("postTrainMessage", postTrainMessage2);
+
+ message = mbean.buildRequest(wsdlFile.toURI().toString(), "postTrainMessage", params, properties, null, null);
+
+ assertTrue("Generated SOAP message not as expected. See expected_JBESB_1713.xml. Generated message: \n" + message, compareCharStreams(getClass().getResourceAsStream("expected_JBESB_1713.xml"), new ByteArrayInputStream(message.getBytes())));
+ }
+
+ // Lifted from milyn commons
+ public static boolean compareCharStreams(InputStream s1, InputStream s2) {
+ try {
+ final String xml1 = trimLines(s1).toString() ;
+ final String xml2 = trimLines(s2).toString() ;
+
+ final Document doc1 = YADOMUtil.parse(xml1) ;
+ final Document doc2 = YADOMUtil.parse(xml2) ;
+
+ final StringWriter writer1 = new StringWriter() ;
+ final StringWriter writer2 = new StringWriter() ;
+ YADOMUtil.serialize(doc1, new StreamResult(writer1)) ;
+ YADOMUtil.serialize(doc2, new StreamResult(writer2)) ;
+ return (writer1.toString().equals(writer2.toString())) ;
+ } catch (IOException e) {
+ // fail the comparison
+ } catch (SAXException e) {
+ // fail the comparison
+ } catch (ConfigurationException e) {
+ // fail the comparison
+ }
+
+ return false;
+ }
+ public static StringBuffer trimLines(InputStream charStream) throws IOException {
+ StringBuffer stringBuf = new StringBuffer();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(charStream));
+ String line;
+
+ while((line = reader.readLine()) != null) {
+ stringBuf.append(line.trim());
+ }
+
+ return stringBuf;
+ }
+
+ public static void main(final String[] args)
+ {
+ final InputStream expectedIS = SoapUIClientServiceMBeanUnitTest.class.getResourceAsStream("expected_02.xml") ;
+ final InputStream outputIS = SoapUIClientServiceMBeanUnitTest.class.getResourceAsStream("output.xml") ;
+
+ System.out.println("compare returns: " + compareCharStreams(expectedIS, outputIS));
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/JBESB_1713_RedpillSoapUIClientServiceMBeanUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/SoapUIClientServiceMBeanUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/SoapUIClientServiceMBeanUnitTest.java 2008-05-11 03:45:22 UTC (rev 19926)
+++ labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/SoapUIClientServiceMBeanUnitTest.java 2008-05-12 09:27:38 UTC (rev 19927)
@@ -77,6 +77,8 @@
List<OrderItem> items1 = new ArrayList<OrderItem>();
OrderItem[] items2 = new OrderItem[4];
+ params.put("dumpSOAP", null);
+
properties.setProperty(HttpClientFactory.TARGET_HOST_URL, wsdlFile.toURI().toString());
addOrderItems(items1);
Copied: labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_JBESB_1713.xml (from rev 19919, labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_01.xml)
===================================================================
--- labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_JBESB_1713.xml (rev 0)
+++ labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/expected_JBESB_1713.xml 2008-05-12 09:27:38 UTC (rev 19927)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.itrl.ipl.sj.se/">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <ws:postTrainMessage>
+ <!--Optional:-->
+ <arg0>argument 0</arg0>
+ <!--Zero or more repetitions: - cloned-->
+ <arg1>1111</arg1>
+ <arg1>2222</arg1>
+<arg1>3333</arg1>
+<arg1>4444</arg1>
+<arg2>true</arg2>
+ <!--Optional:-->
+ <arg3>argument 3</arg3>
+ <arg4>1</arg4>
+ <arg5>2</arg5>
+ </ws:postTrainMessage>
+ </soapenv:Body>
+</soapenv:Envelope>
\ No newline at end of file
Added: labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/handdator.wsdl
===================================================================
--- labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/handdator.wsdl (rev 0)
+++ labs/jbossesb/trunk/product/services/soapui-client/src/test/java/org/jboss/soa/esb/services/soapui/handdator.wsdl 2008-05-12 09:27:38 UTC (rev 19927)
@@ -0,0 +1,50 @@
+<definitions name='DummyHanddatorWSBeanService' targetNamespace='http://ws.itrl.ipl.sj.se/' xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:tns='http://ws.itrl.ipl.sj.se/' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
+ <types>
+ <xs:schema targetNamespace='http://ws.itrl.ipl.sj.se/' version='1.0' xmlns:tns='http://ws.itrl.ipl.sj.se/' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+ <xs:element name='postTrainMessage' type='tns:postTrainMessage'/>
+ <xs:element name='postTrainMessageResponse' type='tns:postTrainMessageResponse'/>
+ <xs:complexType name='postTrainMessage'>
+ <xs:sequence>
+ <xs:element minOccurs='0' name='arg0' type='xs:string'/>
+ <xs:element maxOccurs='unbounded' minOccurs='0' name='arg1' type='xs:string'/>
+ <xs:element name='arg2' type='xs:boolean'/>
+ <xs:element minOccurs='0' name='arg3' type='xs:string'/>
+ <xs:element name='arg4' type='xs:long'/>
+ <xs:element name='arg5' type='xs:long'/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name='postTrainMessageResponse'>
+ <xs:sequence/>
+ </xs:complexType>
+ </xs:schema>
+ </types>
+ <message name='DummyHanddatorWSBean_postTrainMessageResponse'>
+ <part element='tns:postTrainMessageResponse' name='postTrainMessageResponse'></part>
+ </message>
+ <message name='DummyHanddatorWSBean_postTrainMessage'>
+ <part element='tns:postTrainMessage' name='postTrainMessage'></part>
+ </message>
+ <portType name='DummyHanddatorWSBean'>
+ <operation name='postTrainMessage' parameterOrder='postTrainMessage'>
+ <input message='tns:DummyHanddatorWSBean_postTrainMessage'></input>
+ <output message='tns:DummyHanddatorWSBean_postTrainMessageResponse'></output>
+ </operation>
+ </portType>
+ <binding name='DummyHanddatorWSBeanBinding' type='tns:DummyHanddatorWSBean'>
+ <soap:binding style='document' transport='http://schemas.xmlsoap.org/soap/http'/>
+ <operation name='postTrainMessage'>
+ <soap:operation soapAction=''/>
+ <input>
+ <soap:body use='literal'/>
+ </input>
+ <output>
+ <soap:body use='literal'/>
+ </output>
+ </operation>
+ </binding>
+ <service name='DummyHanddatorWSBeanService'>
+ <port binding='tns:DummyHanddatorWSBeanBinding' name='DummyHanddatorWSBeanPort'>
+ <soap:address location='http://localhost:8380/HanddatorDummyWS/DummyHanddatorWSBean'/>
+ </port>
+ </service>
+</definitions>
More information about the jboss-svn-commits
mailing list