svn commit: r547526 - in /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test: AbstractXmlRpcTestCase.java XmlRpcTests.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r547526 - in /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test: AbstractXmlRpcTestCase.java XmlRpcTests.java

jaz-3
Author: jaz
Date: Thu Jun 14 21:55:45 2007
New Revision: 547526

URL: http://svn.apache.org/viewvc?view=rev&rev=547526
Log:
added new abstract class for making xml-rpc tests easier; refactored the sample (glue) test to use the new abstract test (also used as an example)

Added:
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java   (with props)
Modified:
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/XmlRpcTests.java

Added: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java?view=auto&rev=547526
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java (added)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java Thu Jun 14 21:55:45 2007
@@ -0,0 +1,78 @@
+/*
+ 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.ofbiz.webapp.test;
+
+import junit.framework.TestCase;
+import org.ofbiz.webapp.xmlrpc.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * AbstractXmlRpcTestCase
+ */
+public class AbstractXmlRpcTestCase extends TestCase {
+
+    public static final String module = AbstractXmlRpcTestCase.class.getName();
+
+    protected String keyStoreComponent;
+    protected String keyStoreName;
+    protected String keyAlias;
+
+    public AbstractXmlRpcTestCase(String name, String keyStoreComponent, String keyStoreName, String keyAlias) {
+        super(name);
+        this.keyStoreComponent = keyStoreComponent;
+        this.keyStoreName = keyStoreName;
+        this.keyAlias = keyAlias;
+    }
+
+    public AbstractXmlRpcTestCase(String name) {
+        super(name);
+        this.keyStoreComponent = null;
+        this.keyStoreName = null;
+        this.keyAlias = null;
+    }
+
+    private AbstractXmlRpcTestCase() {
+        //super();
+    }
+
+    public org.apache.xmlrpc.client.XmlRpcClient getRpcClient(String url) throws MalformedURLException {
+        return getRpcClient(url, null, null);    
+    }
+
+    public org.apache.xmlrpc.client.XmlRpcClient getRpcClient(String url, String login, String password) throws MalformedURLException {
+        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+        config.setServerURL(new URL(url));
+        if (login != null) {
+            config.setBasicUserName(login);
+        }
+        if (password != null) {
+            config.setBasicPassword(password);
+        }
+
+        if (keyStoreComponent != null && keyStoreName != null && keyAlias != null) {
+            return new XmlRpcClient(config, keyStoreComponent, keyStoreName, keyAlias);
+        } else {
+            return new XmlRpcClient(config);
+        }
+    }
+}

Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/XmlRpcTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/XmlRpcTests.java?view=diff&rev=547526&r1=547525&r2=547526
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/XmlRpcTests.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/XmlRpcTests.java Thu Jun 14 21:55:45 2007
@@ -19,49 +19,26 @@
 
 package org.ofbiz.webapp.test;
 
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.service.GenericDispatcher;
-import org.ofbiz.service.ModelService;
-import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.webapp.xmlrpc.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.XmlRpcClient;
 
 import java.util.Map;
-import java.net.URL;
-
-import junit.framework.TestCase;
 
 /**
  * XmlRpcTests
  */
-public class XmlRpcTests extends TestCase {
+public class XmlRpcTests extends AbstractXmlRpcTestCase {
 
     public static final String module = XmlRpcTests.class.getName();
-    protected LocalDispatcher dispatcher = null;
+    public static final String url = "http://localhost:8080/webtools/control/xmlrpc";
 
     public XmlRpcTests(String name) {
         super(name);
     }
 
-    protected void setUp() throws Exception {
-        GenericDelegator delegator = GenericDelegator.getGenericDelegator("test");
-        dispatcher = GenericDispatcher.getLocalDispatcher("test-dispatcher", delegator);
-    }
-
-    protected void tearDown() throws Exception {
-    }
-
     public void testXmlRpcRequest() throws Exception {
-        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
-        config.setServerURL(new URL("http://localhost:8080/webtools/control/xmlrpc"));
-        config.setBasicUserName("admin");
-        config.setBasicPassword("ofbiz");
-
-        XmlRpcClient client = new XmlRpcClient(config);
-        client.setConfig(config);
-
+        XmlRpcClient client = this.getRpcClient(url, "admin", "ofbiz");
         Object[] params = new Object[] { 55.00, "message from xml-rpc client" };
-        Map result = (Map) client.execute("testScv", params);
-        assertEquals("XML-RPC Service result success", "service done", result.get("resp"));        
+        Map result = (Map) client.execute("testScv", params);        
+        assertEquals("XML-RPC Service result success", "service done", result.get("resp"));
     }
 }