Author: mriou
Date: Fri Aug 18 11:54:03 2006
New Revision: 432678

URL: http://svn.apache.org/viewvc?rev=432678&view=rev
Log:
Created an utility class for client willing to use the management API or the 
deployment API with Axis2. Could make the life of some people easier and it's 
used by tests anyway.

Added:
    
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/ServiceClientUtil.java
Modified:
    
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/DeploymentTest.java
    
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ExecutionPathTest.java
    
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java
    
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ProcessManagementTest.java
    incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java

Added: 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/ServiceClientUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/ServiceClientUtil.java?rev=432678&view=auto
==============================================================================
--- 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/ServiceClientUtil.java
 (added)
+++ 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/service/ServiceClientUtil.java
 Fri Aug 18 11:54:03 2006
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.axis2.service;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.ode.utils.Namespaces;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Client utilities that can be used to invoke easily the deployment
+ * and management services with Axis2.
+ */
+public class ServiceClientUtil {
+
+    /**
+     * Sends the provided message to an Axis2 deployed service.
+     * @param msg the message OMElement that will be included in the body
+     * @param url to send the message to
+     * @return the response message
+     * @throws AxisFault when a problem occured during the call
+     */
+    public OMElement send(OMElement msg, String url) throws AxisFault {
+        Options options = new Options();
+        EndpointReference target = new EndpointReference(url);
+        options.setTo(target);
+
+        ServiceClient serviceClient = new ServiceClient();
+        serviceClient.setOptions(options);
+
+        return serviceClient.sendReceive(msg);
+    }
+
+    /**
+     * Builds a message for the deployment and management API using simple 
parameter
+     * passing. Example: <br/>
+     * <code>
+     * buildMessage("listProcesses", new String[] {"filter", "orderKeys"},
+     *          new String[] {"name=DynPartnerResponder 
namespace=http://ode/bpel/responder " +
+     *                  "deployed>=" + notSoLongAgoStr, ""});
+     * </code>
+     * @param operation to call
+     * @param params list of the parameters for the operation as defined in 
the WSDL document
+     * @param values of the parameters
+     * @return the message to send
+     */
+    public OMElement buildMessage(String operation, String[] params, Object[] 
values) {
+        OMFactory _factory = OMAbstractFactory.getOMFactory();
+        OMNamespace pmns = _factory.createOMNamespace(Namespaces.ODE_PMAPI, 
"pmapi");
+        OMElement root = _factory.createOMElement(operation, pmns);
+        for (int m = 0; m < params.length; m++) {
+            OMElement omelmt = _factory.createOMElement(params[m], null);
+            if (values[m] instanceof String)
+                omelmt.setText((String) values[m]);
+            else if (values[m] instanceof QName)
+                omelmt.setText((QName) values[m]);
+            else if (values[m] instanceof OMElement)
+                omelmt.addChild((OMElement) values[m]);
+            else if (values[m] instanceof Object[]) {
+                Object[] subarr = (Object[]) values[m];
+                String elmtName = (String) subarr[0];
+                for (int p = 1; p < subarr.length; p++) {
+                    OMElement omarrelmt = _factory.createOMElement(elmtName, 
null);
+                    omarrelmt.setText(subarr[p].toString());
+                    omelmt.addChild(omarrelmt);
+                }
+            } else throw new UnsupportedOperationException("Type " + 
values[m].getClass() + "isn't supported as " +
+                    "a parameter type (only String and QName are).");
+            root.addChild(omelmt);
+        }
+        return root;
+    }
+
+}

Modified: 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/DeploymentTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/DeploymentTest.java?rev=432678&r1=432677&r2=432678&view=diff
==============================================================================
--- 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/DeploymentTest.java
 (original)
+++ 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/DeploymentTest.java
 Fri Aug 18 11:54:03 2006
@@ -27,23 +27,22 @@
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.util.Base64;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
+import org.apache.ode.axis2.service.ServiceClientUtil;
+import org.apache.ode.utils.Namespaces;
 
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
 public class DeploymentTest extends TestCase {
 
-    public static final String PMAPI_NS = 
"http://www.apache.org/ode/pmapi/types/2006/08/02/";;
+    private ServiceClientUtil _client;
 
     public void testDeployUndeploy() throws Exception {
         // Create a factory
         OMFactory factory = OMAbstractFactory.getOMFactory();
 
         // Use the factory to create three elements
-        OMNamespace depns = factory.createOMNamespace(PMAPI_NS,"deployapi");
+        OMNamespace depns = 
factory.createOMNamespace(Namespaces.ODE_PMAPI,"deployapi");
         OMElement root = factory.createOMElement("deploy", null);
         OMElement namePart = factory.createOMElement("name", depns);
         namePart.setText("DynPartner");
@@ -67,12 +66,12 @@
         sendToDeployment(root);
 
         // Check deployment
-        OMElement listRoot = buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
+        OMElement listRoot = _client.buildMessage("listProcesses", new 
String[] {"filter", "orderKeys"},
                 new String[] {"name=DynPartnerMain", ""});
         OMElement result = sendToPM(listRoot);
         // Ensures that there's only 2 process-info string (ending and closing 
tags) and hence only one process
         assert(result.toString().split("process-info").length == 3);
-        listRoot = buildMessage("listProcesses", new String[] {"filter", 
"orderKeys"},
+        listRoot = _client.buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
                 new String[] {"name=DynPartnerResponder", ""});
         result = sendToPM(listRoot);
         assert(result.toString().split("process-info").length == 3);
@@ -86,44 +85,22 @@
         // Undeploy
         sendToDeployment(root);
 
-        listRoot = buildMessage("listProcesses", new String[] {"filter", 
"orderKeys"},
+        listRoot = _client.buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
                 new String[] {"name=DynPartnerMain", ""});
         result = sendToPM(listRoot);
         assert(result.toString().indexOf("process-info") < 0);
     }
 
-    private OMElement sendToPM(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/ProcessManagement";);
-    }
-
-    private OMElement sendToDeployment(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/DeploymentService";);
+    protected void setUp() throws Exception {
+        _client = new ServiceClientUtil();
     }
 
-    private OMElement send(OMElement msg, String url) throws AxisFault {
-        Options options = new Options();
-        EndpointReference target = new EndpointReference(url);
-        options.setTo(target);
-
-        ServiceClient serviceClient = new ServiceClient();
-        serviceClient.setOptions(options);
-
-        return serviceClient.sendReceive(msg);
+    private OMElement sendToPM(OMElement msg) throws AxisFault {
+        return _client.send(msg, 
"http://localhost:8080/ode/services/ProcessManagement";);
     }
 
-    private OMElement buildMessage(String operation, String[] params, String[] 
values) {
-      //create a factory
-      OMFactory factory = OMAbstractFactory.getOMFactory();
-
-      //use the factory to create three elements
-      OMNamespace pmns = factory.createOMNamespace(PMAPI_NS,"pmapi");
-      OMElement root = factory.createOMElement(operation, pmns);
-      for (int m = 0; m < params.length; m++) {
-        OMElement omelmt = factory.createOMElement(params[m], null);
-        omelmt.setText(values[m]);
-        root.addChild(omelmt);
-      }
-      return root;
+    private OMElement sendToDeployment(OMElement msg) throws AxisFault {
+        return _client.send(msg, 
"http://localhost:8080/ode/services/DeploymentService";);
     }
 
 }

Modified: 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ExecutionPathTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ExecutionPathTest.java?rev=432678&r1=432677&r2=432678&view=diff
==============================================================================
--- 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ExecutionPathTest.java
 (original)
+++ 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ExecutionPathTest.java
 Fri Aug 18 11:54:03 2006
@@ -27,30 +27,25 @@
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.util.Base64;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
+import org.apache.ode.axis2.service.ServiceClientUtil;
 import org.apache.ode.tools.sendsoap.cline.HttpSoapSender;
+import org.apache.ode.utils.Namespaces;
 
 import javax.xml.namespace.QName;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.net.URL;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
 import java.util.HashSet;
 import java.util.Iterator;
 
 
 public class ExecutionPathTest extends TestCase {
 
-    public static final String PMAPI_NS = 
"http://www.apache.org/ode/pmapi/types/2006/08/02/";;
-
     private OMFactory _factory;
-    private DateFormat xsdDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
+    private ServiceClientUtil _client;
 
     public void testListEvents() throws Exception {
-        OMElement root = buildMessage("listEvents", new String[] 
{"instanceFilter", "eventFilter", "maxCount"},
+        OMElement root = _client.buildMessage("listEvents", new String[] 
{"instanceFilter", "eventFilter", "maxCount"},
                 new String[] {"", "", "0"});
         OMElement result = sendToIM(root);
         HashSet<String> aids = new HashSet<String>();
@@ -71,7 +66,7 @@
         int m = 1;
         for (String s : aids) saids[m++] = s;
 
-        root = buildMessage("getExtensibilityElements",
+        root = _client.buildMessage("getExtensibilityElements",
                 new String[] {"pid", "aids"},
                 new Object[] { new QName("http://ode/bpel/unit-test";, 
"DynPartnerMain"), saids });
         result = sendToPM(root);
@@ -87,9 +82,10 @@
     protected void setUp() throws Exception {
         // Create a factory
         _factory = OMAbstractFactory.getOMFactory();
+        _client = new ServiceClientUtil();
 
         // Use the factory to create three elements
-        OMNamespace depns = _factory.createOMNamespace(PMAPI_NS, "deployapi");
+        OMNamespace depns = _factory.createOMNamespace(Namespaces.ODE_PMAPI, 
"deployapi");
         OMElement root = _factory.createOMElement("deploy", null);
         OMElement namePart = _factory.createOMElement("name", depns);
         namePart.setText("DynPartner");
@@ -122,7 +118,7 @@
 
     protected void tearDown() throws Exception {
         // Prepare undeploy message
-        OMNamespace depns = _factory.createOMNamespace(PMAPI_NS, "deployapi");
+        OMNamespace depns = _factory.createOMNamespace(Namespaces.ODE_PMAPI, 
"deployapi");
         OMElement root = _factory.createOMElement("undeploy", depns);
         OMElement part = _factory.createOMElement("processName", null);
         part.setText("DynPartner");
@@ -131,59 +127,22 @@
         // Undeploy
         sendToDeployment(root);
 
-        OMElement listRoot = buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
+        OMElement listRoot = _client.buildMessage("listProcesses", new 
String[] {"filter", "orderKeys"},
                 new String[] {"name=DynPartnerMain", ""});
         OMElement result = sendToPM(listRoot);
         assert(result.toString().indexOf("process-info") < 0);
     }
 
     private OMElement sendToPM(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/ProcessManagement";);
+        return _client.send(msg, 
"http://localhost:8080/ode/services/ProcessManagement";);
     }
 
     private OMElement sendToIM(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/InstanceManagement";);
+        return _client.send(msg, 
"http://localhost:8080/ode/services/InstanceManagement";);
     }
 
     private OMElement sendToDeployment(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/DeploymentService";);
-    }
-
-    private OMElement send(OMElement msg, String url) throws AxisFault {
-        Options options = new Options();
-        EndpointReference target = new EndpointReference(url);
-        options.setTo(target);
-
-        ServiceClient serviceClient = new ServiceClient();
-        serviceClient.setOptions(options);
-
-        return serviceClient.sendReceive(msg);
-    }
-
-    private OMElement buildMessage(String operation, String[] params, Object[] 
values) {
-        OMNamespace pmns = _factory.createOMNamespace(PMAPI_NS, "pmapi");
-        OMElement root = _factory.createOMElement(operation, pmns);
-        for (int m = 0; m < params.length; m++) {
-            OMElement omelmt = _factory.createOMElement(params[m], null);
-            if (values[m] instanceof String)
-                omelmt.setText((String) values[m]);
-            else if (values[m] instanceof QName)
-                omelmt.setText((QName) values[m]);
-            else if (values[m] instanceof OMElement)
-                omelmt.addChild((OMElement) values[m]);
-            else if (values[m] instanceof Object[]) {
-                Object[] subarr = (Object[]) values[m];
-                String elmtName = (String) subarr[0];
-                for (int p = 1; p < subarr.length; p++) {
-                    OMElement omarrelmt = _factory.createOMElement(elmtName, 
null);
-                    omarrelmt.setText(subarr[p].toString());
-                    omelmt.addChild(omarrelmt);
-                }
-            } else throw new UnsupportedOperationException("Type " + 
values[m].getClass() + "isn't supported as " +
-                    "a parameter type (only String and QName are).");
-            root.addChild(omelmt);
-        }
-        return root;
+        return _client.send(msg, 
"http://localhost:8080/ode/services/DeploymentService";);
     }
 
 }

Modified: 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java?rev=432678&r1=432677&r2=432678&view=diff
==============================================================================
--- 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java
 (original)
+++ 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/InstanceManagementTest.java
 Fri Aug 18 11:54:03 2006
@@ -27,10 +27,9 @@
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.util.Base64;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
+import org.apache.ode.axis2.service.ServiceClientUtil;
 import org.apache.ode.tools.sendsoap.cline.HttpSoapSender;
+import org.apache.ode.utils.Namespaces;
 
 import javax.xml.namespace.QName;
 import java.io.ByteArrayOutputStream;
@@ -42,13 +41,12 @@
 
 public class InstanceManagementTest extends TestCase {
 
-    public static final String PMAPI_NS = 
"http://www.apache.org/ode/pmapi/types/2006/08/02/";;
-
     private OMFactory _factory;
     private DateFormat xsdDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
+    private ServiceClientUtil _client;
 
     public void testListInstances() throws Exception {
-        OMElement listRoot = buildMessage("listInstances", new String[] 
{"filter", "order", "limit"},
+        OMElement listRoot = _client.buildMessage("listInstances", new 
String[] {"filter", "order", "limit"},
                 new String[] {"name=DynPartnerMain", "", "10"});
         OMElement result = sendToIM(listRoot);
         // Ensures that there's only 2 process-info string (ending and closing 
tags) and hence only one process
@@ -58,7 +56,7 @@
         Calendar notSoLongAgo = Calendar.getInstance();
         notSoLongAgo.add(Calendar.MINUTE, -2);
         String notSoLongAgoStr = xsdDF.format(notSoLongAgo.getTime());
-        listRoot = buildMessage("listInstances", new String[] {"filter", 
"order", "limit"},
+        listRoot = _client.buildMessage("listInstances", new String[] 
{"filter", "order", "limit"},
                 new String[] {"name=DynPartnerResponder 
namespace=http://ode/bpel/responder " +
                         "started>=" + notSoLongAgoStr, "", "10"});
         result = sendToIM(listRoot);
@@ -66,7 +64,7 @@
     }
 
     public void testListAllInstances() throws Exception {
-        OMElement root = buildMessage("listAllInstancesWithLimit", new 
String[] {"limit"}, new String[] {"1"});
+        OMElement root = _client.buildMessage("listAllInstancesWithLimit", new 
String[] {"limit"}, new String[] {"1"});
         OMElement result = sendToIM(root);
         // We shold have only one instance (so 2 opening/closing elmts)
         assert(result.toString().split("instance-info").length == 3);
@@ -76,22 +74,22 @@
     }
 
     public void testGetInstanceInfo() throws Exception {
-        OMElement root = buildMessage("listAllInstances", new String[] {}, new 
String[] {});
+        OMElement root = _client.buildMessage("listAllInstances", new String[] 
{}, new String[] {});
         OMElement result = sendToIM(root);
-        String iid = result.getFirstChildWithName(new QName(PMAPI_NS, 
"instance-info"))
-                .getFirstChildWithName(new QName(PMAPI_NS, "iid")).getText();
-        root = buildMessage("getInstanceInfo", new String[] {"iid"}, new 
String[] {iid});
+        String iid = result.getFirstChildWithName(new 
QName(Namespaces.ODE_PMAPI, "instance-info"))
+                .getFirstChildWithName(new QName(Namespaces.ODE_PMAPI, 
"iid")).getText();
+        root = _client.buildMessage("getInstanceInfo", new String[] {"iid"}, 
new String[] {iid});
         result = sendToIM(root);
         assert(result.toString().split("instance-info").length == 3);
     }
 
     public void testGetScopeInfo() throws Exception {
-        OMElement root = buildMessage("listAllInstances", new String[] {}, new 
String[] {});
+        OMElement root = _client.buildMessage("listAllInstances", new String[] 
{}, new String[] {});
         OMElement result = sendToIM(root);
-        String siid = result.getFirstChildWithName(new QName(PMAPI_NS, 
"instance-info"))
-                .getFirstChildWithName(new QName(PMAPI_NS, "root-scope"))
+        String siid = result.getFirstChildWithName(new 
QName(Namespaces.ODE_PMAPI, "instance-info"))
+                .getFirstChildWithName(new QName(Namespaces.ODE_PMAPI, 
"root-scope"))
                 .getAttributeValue(new QName(null, "siid"));
-        root = buildMessage("getScopeInfoWithActivity", new String[] {"siid", 
"activityInfo"},
+        root = _client.buildMessage("getScopeInfoWithActivity", new String[] 
{"siid", "activityInfo"},
                 new String[] {siid, "true"});
         result = sendToIM(root);
         assert(result.toString().split("scope-info").length == 3);
@@ -99,26 +97,26 @@
     }
 
     public void testGetVariableInfo() throws Exception {
-        OMElement root = buildMessage("listInstances", new String[] {"filter", 
"order", "limit"},
+        OMElement root = _client.buildMessage("listInstances", new String[] 
{"filter", "order", "limit"},
                 new String[] {"name=DynPartnerMain", "", "10"});
         OMElement result = sendToIM(root);
-        String siid = result.getFirstChildWithName(new QName(PMAPI_NS, 
"instance-info"))
-                .getFirstChildWithName(new QName(PMAPI_NS, "root-scope"))
+        String siid = result.getFirstChildWithName(new 
QName(Namespaces.ODE_PMAPI, "instance-info"))
+                .getFirstChildWithName(new QName(Namespaces.ODE_PMAPI, 
"root-scope"))
                 .getAttributeValue(new QName(null, "siid"));
-        root = buildMessage("getVariableInfo", new String[] {"sid", 
"varName"}, new String[] {siid, "dummy"});
+        root = _client.buildMessage("getVariableInfo", new String[] {"sid", 
"varName"}, new String[] {siid, "dummy"});
         result = sendToIM(root);
         assert(result.toString().indexOf("fire!") >= 0);
     }
 
     public void testListEvents() throws Exception {
-        OMElement root = buildMessage("listEvents", new String[] 
{"instanceFilter", "eventFilter", "maxCount"},
+        OMElement root = _client.buildMessage("listEvents", new String[] 
{"instanceFilter", "eventFilter", "maxCount"},
                 new String[] {"", "", "0"});
         OMElement result = sendToIM(root);
         assert(result.toString().split("event-info").length > 10);
     }
 
     public void testGetEventTimeline() throws Exception {
-        OMElement root = buildMessage("getEventTimeline", new String[] 
{"instanceFilter", "eventFilter"},
+        OMElement root = _client.buildMessage("getEventTimeline", new String[] 
{"instanceFilter", "eventFilter"},
                 new String[] {"", ""});
         OMElement result = sendToIM(root);
         assert(result.toString().split("element").length > 10);
@@ -127,9 +125,10 @@
     protected void setUp() throws Exception {
         // Create a factory
         _factory = OMAbstractFactory.getOMFactory();
+        _client = new ServiceClientUtil();
 
         // Use the factory to create three elements
-        OMNamespace depns = _factory.createOMNamespace(PMAPI_NS, "deployapi");
+        OMNamespace depns = _factory.createOMNamespace(Namespaces.ODE_PMAPI, 
"deployapi");
         OMElement root = _factory.createOMElement("deploy", null);
         OMElement namePart = _factory.createOMElement("name", depns);
         namePart.setText("DynPartner");
@@ -162,7 +161,7 @@
 
     protected void tearDown() throws Exception {
         // Prepare undeploy message
-        OMNamespace depns = _factory.createOMNamespace(PMAPI_NS, "deployapi");
+        OMNamespace depns = _factory.createOMNamespace(Namespaces.ODE_PMAPI, 
"deployapi");
         OMElement root = _factory.createOMElement("undeploy", depns);
         OMElement part = _factory.createOMElement("processName", null);
         part.setText("DynPartner");
@@ -171,59 +170,22 @@
         // Undeploy
         sendToDeployment(root);
 
-        OMElement listRoot = buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
+        OMElement listRoot = _client.buildMessage("listProcesses", new 
String[] {"filter", "orderKeys"},
                 new String[] {"name=DynPartnerMain", ""});
         OMElement result = sendToPM(listRoot);
         assert(result.toString().indexOf("process-info") < 0);
     }
 
     private OMElement sendToPM(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/ProcessManagement";);
+        return _client.send(msg, 
"http://localhost:8080/ode/services/ProcessManagement";);
     }
 
     private OMElement sendToIM(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/InstanceManagement";);
+        return _client.send(msg, 
"http://localhost:8080/ode/services/InstanceManagement";);
     }
 
     private OMElement sendToDeployment(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/DeploymentService";);
-    }
-
-    private OMElement send(OMElement msg, String url) throws AxisFault {
-        Options options = new Options();
-        EndpointReference target = new EndpointReference(url);
-        options.setTo(target);
-
-        ServiceClient serviceClient = new ServiceClient();
-        serviceClient.setOptions(options);
-
-        return serviceClient.sendReceive(msg);
-    }
-
-    private OMElement buildMessage(String operation, String[] params, Object[] 
values) {
-        OMNamespace pmns = _factory.createOMNamespace(PMAPI_NS, "pmapi");
-        OMElement root = _factory.createOMElement(operation, pmns);
-        for (int m = 0; m < params.length; m++) {
-            OMElement omelmt = _factory.createOMElement(params[m], null);
-            if (values[m] instanceof String)
-                omelmt.setText((String) values[m]);
-            else if (values[m] instanceof QName)
-                omelmt.setText((QName) values[m]);
-            else if (values[m] instanceof OMElement)
-                omelmt.addChild((OMElement) values[m]);
-            else if (values[m] instanceof Object[]) {
-                Object[] subarr = (Object[]) values[m];
-                String elmtName = (String) subarr[0];
-                for (int p = 1; p < subarr.length; p++) {
-                    OMElement omarrelmt = _factory.createOMElement(elmtName, 
null);
-                    omarrelmt.setText(subarr[p].toString());
-                    omelmt.addChild(omarrelmt);
-                }
-            } else throw new UnsupportedOperationException("Type " + 
values[m].getClass() + "isn't supported as " +
-                    "a parameter type (only String and QName are).");
-            root.addChild(omelmt);
-        }
-        return root;
+        return _client.send(msg, 
"http://localhost:8080/ode/services/DeploymentService";);
     }
 
 }

Modified: 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ProcessManagementTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ProcessManagementTest.java?rev=432678&r1=432677&r2=432678&view=diff
==============================================================================
--- 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ProcessManagementTest.java
 (original)
+++ 
incubator/ode/trunk/axis2/src/test/java/org/apache/ode/axis2/management/ProcessManagementTest.java
 Fri Aug 18 11:54:03 2006
@@ -27,9 +27,8 @@
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.util.Base64;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
+import org.apache.ode.axis2.service.ServiceClientUtil;
+import org.apache.ode.utils.Namespaces;
 
 import javax.xml.namespace.QName;
 import java.io.ByteArrayOutputStream;
@@ -42,13 +41,12 @@
 
 public class ProcessManagementTest extends TestCase {
 
-    public static final String PMAPI_NS = 
"http://www.apache.org/ode/pmapi/types/2006/08/02/";;
-
     private OMFactory _factory;
     private DateFormat xsdDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
+    private ServiceClientUtil _client;
 
     public void testListProcesses() throws Exception {
-        OMElement listRoot = buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
+        OMElement listRoot = _client.buildMessage("listProcesses", new 
String[] {"filter", "orderKeys"},
                 new String[] {"name=DynPartnerMain", ""});
         OMElement result = sendToPM(listRoot);
         // Ensures that there's only 2 process-info string (ending and closing 
tags) and hence only one process
@@ -58,7 +56,7 @@
         Calendar notSoLongAgo = Calendar.getInstance();
         notSoLongAgo.add(Calendar.MINUTE, -2);
         String notSoLongAgoStr = xsdDF.format(notSoLongAgo.getTime());
-        listRoot = buildMessage("listProcesses", new String[] {"filter", 
"orderKeys"},
+        listRoot = _client.buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
                 new String[] {"name=DynPartnerResponder 
namespace=http://ode/bpel/responder " +
                         "deployed>=" + notSoLongAgoStr, ""});
         result = sendToPM(listRoot);
@@ -66,15 +64,15 @@
     }
 
     public void testProcessFiles() throws Exception {
-        OMElement listRoot = buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
+        OMElement listRoot = _client.buildMessage("listProcesses", new 
String[] {"filter", "orderKeys"},
                 new String[] {"name=DynPartnerMain", ""});
         OMElement result = sendToPM(listRoot);
         System.out.println("=> " + result);
         ArrayList<String> filenames = new ArrayList<String>();
-        Iterator docs = result.getFirstElement().getFirstChildWithName(new 
QName(PMAPI_NS, "documents")).getChildElements();
+        Iterator docs = result.getFirstElement().getFirstChildWithName(new 
QName(Namespaces.ODE_PMAPI, "documents")).getChildElements();
         while (docs.hasNext()) {
             OMElement docElmt = (OMElement) docs.next();
-            filenames.add(docElmt.getFirstChildWithName(new QName(PMAPI_NS, 
"name")).getText());
+            filenames.add(docElmt.getFirstChildWithName(new 
QName(Namespaces.ODE_PMAPI, "name")).getText());
         }
         // Checking that all necessary files are really there
         assert(filenames.contains("deploy.xml"));
@@ -85,7 +83,7 @@
     }
 
     public void testListAllProcesses() throws Exception {
-        OMElement root = buildMessage("listAllProcesses", new String[] {}, new 
String[] {});
+        OMElement root = _client.buildMessage("listAllProcesses", new String[] 
{}, new String[] {});
         OMElement result = sendToPM(root);
         // Hopefully we have at least two processes (so 4 opening/closing 
elmts)
         assert(result.toString().split("process-info").length >= 5);
@@ -95,7 +93,7 @@
     }
 
     public void testSetProcessProperty() throws Exception {
-        OMElement root = buildMessage("setProcessProperty",
+        OMElement root = _client.buildMessage("setProcessProperty",
                 new String[] {"pid", "propertyName", "propertyValue"},
                 new Object[] { new QName("http://ode/bpel/unit-test";, 
"DynPartnerMain"),
                         new QName("http://ode/custom/ns";, "someprop"), 
"somevalue" });
@@ -107,7 +105,7 @@
     public void testSetProcessPropertyNode() throws Exception {
         OMElement propElmt = _factory.createOMElement("testprop", null);
         propElmt.setText("propvalue");
-        OMElement root = buildMessage("setProcessPropertyNode",
+        OMElement root = _client.buildMessage("setProcessPropertyNode",
                 new String[] {"pid", "propertyName", "propertyValue"},
                 new Object[] { new QName("http://ode/bpel/unit-test";, 
"DynPartnerMain"),
                         new QName("http://ode/custom/ns";, "someprop"), 
propElmt });
@@ -118,7 +116,7 @@
     }
 
     public void testGetExtensibilityElements() throws Exception {
-        OMElement root = buildMessage("getExtensibilityElements",
+        OMElement root = _client.buildMessage("getExtensibilityElements",
                 new String[] {"pid", "aids"},
                 new Object[] { new QName("http://ode/bpel/unit-test";, 
"DynPartnerMain"),
                         new String[] {"aid", "12", "14"} });
@@ -129,9 +127,10 @@
     protected void setUp() throws Exception {
         // Create a factory
         _factory = OMAbstractFactory.getOMFactory();
+        _client = new ServiceClientUtil();
 
         // Use the factory to create three elements
-        OMNamespace depns = _factory.createOMNamespace(PMAPI_NS, "deployapi");
+        OMNamespace depns = _factory.createOMNamespace(Namespaces.ODE_PMAPI, 
"deployapi");
         OMElement root = _factory.createOMElement("deploy", null);
         OMElement namePart = _factory.createOMElement("name", depns);
         namePart.setText("DynPartner");
@@ -157,7 +156,7 @@
 
     protected void tearDown() throws Exception {
         // Prepare undeploy message
-        OMNamespace depns = _factory.createOMNamespace(PMAPI_NS, "deployapi");
+        OMNamespace depns = _factory.createOMNamespace(Namespaces.ODE_PMAPI, 
"deployapi");
         OMElement root = _factory.createOMElement("undeploy", depns);
         OMElement part = _factory.createOMElement("processName", null);
         part.setText("DynPartner");
@@ -166,56 +165,18 @@
         // Undeploy
         sendToDeployment(root);
 
-        OMElement listRoot = buildMessage("listProcesses", new String[] 
{"filter", "orderKeys"},
+        OMElement listRoot = _client.buildMessage("listProcesses", new 
String[] {"filter", "orderKeys"},
                 new String[] {"name=DynPartnerMain", ""});
         OMElement result = sendToPM(listRoot);
         assert(result.toString().indexOf("process-info") < 0);
     }
 
     private OMElement sendToPM(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/ProcessManagement";);
+        return _client.send(msg, 
"http://localhost:8080/ode/services/ProcessManagement";);
     }
 
     private OMElement sendToDeployment(OMElement msg) throws AxisFault {
-        return send(msg, 
"http://localhost:8080/ode/services/DeploymentService";);
-    }
-
-    private OMElement send(OMElement msg, String url) throws AxisFault {
-        Options options = new Options();
-        EndpointReference target = new EndpointReference(url);
-        options.setTo(target);
-
-        ServiceClient serviceClient = new ServiceClient();
-        serviceClient.setOptions(options);
-
-        return serviceClient.sendReceive(msg);
-    }
-
-    private OMElement buildMessage(String operation, String[] params, Object[] 
values) {
-        //use the factory to create three elements
-        OMNamespace pmns = _factory.createOMNamespace(PMAPI_NS, "pmapi");
-        OMElement root = _factory.createOMElement(operation, pmns);
-        for (int m = 0; m < params.length; m++) {
-            OMElement omelmt = _factory.createOMElement(params[m], null);
-            if (values[m] instanceof String)
-                omelmt.setText((String) values[m]);
-            else if (values[m] instanceof QName)
-                omelmt.setText((QName) values[m]);
-            else if (values[m] instanceof OMElement)
-                omelmt.addChild((OMElement) values[m]);
-            else if (values[m] instanceof Object[]) {
-                Object[] subarr = (Object[]) values[m];
-                String elmtName = (String) subarr[0];
-                for (int p = 1; p < subarr.length; p++) {
-                    OMElement omarrelmt = _factory.createOMElement(elmtName, 
null);
-                    omarrelmt.setText(subarr[p].toString());
-                    omelmt.addChild(omarrelmt);
-                }
-            } else throw new UnsupportedOperationException("Type " + 
values[m].getClass() + "isn't supported as " +
-                    "a parameter type (only String and QName are).");
-            root.addChild(omelmt);
-        }
-        return root;
+        return _client.send(msg, 
"http://localhost:8080/ode/services/DeploymentService";);
     }
 
 }

Modified: 
incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java?rev=432678&r1=432677&r2=432678&view=diff
==============================================================================
--- 
incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java 
(original)
+++ 
incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java 
Fri Aug 18 11:54:03 2006
@@ -26,24 +26,26 @@
  */
 public class Namespaces {
 
-  public static final String INTALIO_SESSION_NS = 
"http://www.intalio.com/type/session";;
+    public static final String INTALIO_SESSION_NS = 
"http://www.intalio.com/type/session";;
 
-  public static final String WS_ADDRESSING_NS = 
"http://www.w3.org/2005/08/addressing";;
+    public static final String WS_ADDRESSING_NS = 
"http://www.w3.org/2005/08/addressing";;
 
-  public static final String WS_ADDRESSING_WSDL_NS = 
"http://www.w3.org/2006/05/addressing/wsdl";;
+    public static final String WS_ADDRESSING_WSDL_NS = 
"http://www.w3.org/2006/05/addressing/wsdl";;
 
-  public static final String SOAP_NS = "http://schemas.xmlsoap.org/wsdl/soap/";;
+    public static final String SOAP_NS = 
"http://schemas.xmlsoap.org/wsdl/soap/";;
 
-  public static final String WS_BPEL_20_NS = 
"http://schemas.xmlsoap.org/ws/2004/03/business-process/";;
+    public static final String WS_BPEL_20_NS = 
"http://schemas.xmlsoap.org/ws/2004/03/business-process/";;
 
-  public static final String WSDL_11 = "http://schemas.xmlsoap.org/wsdl/";;
+    public static final String WSDL_11 = "http://schemas.xmlsoap.org/wsdl/";;
 
-  public static final String WSDL_20 = "http://www.w3.org/2006/01/wsdl";;
+    public static final String WSDL_20 = "http://www.w3.org/2006/01/wsdl";;
 
-  public static final String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";;
-  
-  public static final String JBI_END_POINT_REFERENCE = 
"http://java.sun.com/jbi/end-point-reference";;  
+    public static final String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";;
 
-  public static final QName WS_ADDRESSING_ENDPOINT = new 
QName(WS_ADDRESSING_NS, "EndpointReference");
+    public static final String JBI_END_POINT_REFERENCE = 
"http://java.sun.com/jbi/end-point-reference";;
+
+    public static final QName WS_ADDRESSING_ENDPOINT = new 
QName(WS_ADDRESSING_NS, "EndpointReference");
+
+    public static final String ODE_PMAPI = 
"http://www.apache.org/ode/pmapi/types/2006/08/02/";;
 
 }


Reply via email to