You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2006/12/02 16:34:40 UTC

svn commit: r481567 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java test/org/apache/axis2/jaxws/proxy/GorillaDLWProxyTests.java

Author: scheu
Date: Sat Dec  2 07:34:39 2006
New Revision: 481567

URL: http://svn.apache.org/viewvc?view=rev&rev=481567
Log:
AXIS2-1792
Contributor:Rich Scheuerle
Upgraded the doc/literal wrapped Gorilla test to validate various "xsd:list string" and "maxOccurs=unbounded" string scenarios.  In both of these
cases, the java parameter type is a List<String>, but the underlying semantics of xs:list and maxOccurs="unbounded" affect the semantics for the corner cases.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/GorillaDLWProxyTests.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java?view=diff&rev=481567&r1=481566&r2=481567
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/wrapper/impl/PropertyInfo.java Sat Dec  2 07:34:39 2006
@@ -20,6 +20,7 @@
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.Collection;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -65,20 +66,37 @@
 	 */
 	public void set(Object targetBean, Object propValue)throws InvocationTargetException, IllegalAccessException, JAXBWrapperException{
 		Method method = descriptor.getWriteMethod();
-		Object[] object = new Object[]{propValue};
-		Class[] paramTypes = method.getParameterTypes();
-		if(paramTypes !=null && paramTypes.length ==1){
-			Class paramType = paramTypes[0];
-			if(paramType.isPrimitive() && propValue == null){
-				//Ignoring null value for primitive type, this could potentially be the way of a customer indicating to set
-				//default values defined in JAXBObject/xmlSchema.
-				if(log.isDebugEnabled()){
-					log.debug("Ignoring null value for primitive type, this is the way to set default values defined in JAXBObject/xmlSchema. for primitive types");
-				}
-				return;
+        // JAXB provides setters for atomic values.
+        // For non-atomic values (i.e. lists, collections), there is no setter.
+		if (method != null) {
+            // Method exists, this is the atomic case
+		    Object[] object = new Object[]{propValue};
+		    Class[] paramTypes = method.getParameterTypes();
+		    if(paramTypes !=null && paramTypes.length ==1){
+		        Class paramType = paramTypes[0];
+		        if(paramType.isPrimitive() && propValue == null){
+		            //Ignoring null value for primitive type, this could potentially be the way of a customer indicating to set
+		            //default values defined in JAXBObject/xmlSchema.
+		            if(log.isDebugEnabled()){
+		                log.debug("Ignoring null value for primitive type, this is the way to set default values defined in JAXBObject/xmlSchema. for primitive types");
+		            }
+		            return;
+                }
 			}
-		}
-		method.invoke(targetBean, object);
+            method.invoke(targetBean, object);
+		} else {
+            // There is no setter, we will assume that this is the Collection case
+            // Get the collection. (If there is no collection, the JAXB bean will construct a new one; thus 
+            // collection will always be non-null.)
+		    Collection collection = (Collection) get(targetBean);
+            
+            // Now add our our object to the collection
+            collection.clear();
+            if (propValue != null) {
+                collection.addAll((Collection) propValue);
+            }
+        }
+		
 	}
 	
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/GorillaDLWProxyTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/GorillaDLWProxyTests.java?view=diff&rev=481567&r1=481566&r2=481567
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/GorillaDLWProxyTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/proxy/GorillaDLWProxyTests.java Sat Dec  2 07:34:39 2006
@@ -90,11 +90,14 @@
     public void testEchoString() throws Exception {
         try{ 
             GorillaInterface proxy = getProxy();
+            
+            // Straight Forward Test
             String request = "Hello World";
            
             String response = proxy.echoString(request);
             assertTrue(response != null);
             assert(response.equals(request));
+            
         }catch(Exception e){ 
             e.printStackTrace(); 
             fail("Exception received" + e);
@@ -115,5 +118,129 @@
             e.printStackTrace(); 
             fail("Exception received" + e);
         }
+    }
+    
+    /**
+     * Testing of StringList (xsd:list of string)
+     */
+    public void testEchoStringList() throws Exception {
+        try{ 
+            GorillaInterface proxy = getProxy();
+            
+            // Test sending Hello World
+            List<String> request1 = new ArrayList<String>();
+            request1.add("Hello");
+            request1.add("World");
+            List<String> response1 = proxy.echoStringList(request1);
+            assertTrue(response1 != null);
+            assertTrue(compareLists(request1, response1));
+            
+            // Test with empty list
+            List<String> request2 = new ArrayList<String>();
+            List<String> response2 = proxy.echoStringList(request2);
+            assertTrue(response2 != null);
+            assertTrue(compareLists(request2, response2));
+            
+            // Test with null
+            // Note that the response will be an empty array because
+            // the JAXB bean will never represent List<String> as a null.  This is expected.
+            List<String> request3 = null;
+            List<String> response3 = proxy.echoStringList(request3);
+            assertTrue(response3 != null && response3.size() == 0);
+            
+            // Test sending Hello null World
+            // Note that the null is purged by JAXB.  This is expected.
+            List<String> request4 = new ArrayList<String>();
+            request4.add("Hello");
+            request4.add(null);
+            request4.add("World");
+            List<String> response4 = proxy.echoStringList(request4);
+            assertTrue(response4!= null);
+            assertTrue(compareLists(request1, response4));  // Response 4 should be the same as Request 1
+            
+            // Test sending "Hello World"
+            // Note that the Hello World is divided into two items.
+            // This is due to the xsd:list serialization. This is expected.
+            List<String> request5 = new ArrayList<String>();
+            request5.add("Hello World");
+            List<String> response5 = proxy.echoStringList(request5);
+            assertTrue(response5!= null);
+            assertTrue(compareLists(request1, response5)); // Response 5 should be the same as Request 1
+        }catch(Exception e){ 
+            e.printStackTrace(); 
+            fail("Exception received" + e);
+        }
+    }
+    
+    /**
+     * Test of String Array (string maxOccurs=unbounded)
+     * @throws Exception
+     */
+    public void testEchoStringArray() throws Exception {
+        try{ 
+            GorillaInterface proxy = getProxy();
+            
+            // Test sending Hello World
+            List<String> request1 = new ArrayList<String>();
+            request1.add("Hello");
+            request1.add("World");
+            List<String> response1 = proxy.echoStringArray(request1);
+            assertTrue(response1 != null);
+            assertTrue(compareLists(request1, response1));
+            
+            // Test with empty list
+            List<String> request2 = new ArrayList<String>();
+            List<String> response2 = proxy.echoStringList(request2);
+            assertTrue(response2 != null);
+            assertTrue(compareLists(request2, response2));
+            
+            // Test with null
+            // Note that the response will be an empty array because
+            // the JAXB bean will never represent List<String> as a null.  This is expected.
+            List<String> request3 = null;
+            List<String> response3 = proxy.echoStringArray(request3);
+            assertTrue(response3 != null && response3.size() == 0);
+            
+            // Test sending Hello null World
+            // Note that the null is preserved and the request and response
+            // are the same..note that this is different than the xsd:list processing (see testStringList above)
+            // This is expected.
+            List<String> request4 = new ArrayList<String>();
+            request4.add("Hello");
+            request4.add(null);
+            request4.add("World");
+            List<String> response4 = proxy.echoStringArray(request4);
+            assertTrue(response4!= null);
+            assertTrue(compareLists(request4, response4));  // Response 4 should be the same as Request 1
+            
+            // Test sending "Hello World"
+            // Note that the Hello World remains one item.
+            List<String> request5 = new ArrayList<String>();
+            request5.add("Hello World");
+            List<String> response5 = proxy.echoStringArray(request5);
+            assertTrue(response5!= null);
+            assertTrue(compareLists(request5, response5)); // Response 5 should be the same as Request 1
+        }catch(Exception e){ 
+            e.printStackTrace(); 
+            fail("Exception received" + e);
+        }
+    }
+    
+    private boolean compareLists(List in, List out) {
+        if (in.size() != out.size()) {
+            System.out.println("Size mismatch " + in.size() + "!=" + out.size());
+            return false;
+        }
+        for (int i=0; i<in.size(); i++) {
+            Object inItem = in.get(i);
+            Object outItem = out.get(i);
+            if (inItem != null && !inItem.equals(outItem) ||
+                (inItem == null && inItem != outItem)) {
+                System.out.println("Item " + i + " mismatch " + inItem + "!=" + outItem);
+                return false;
+            }
+                
+        }
+        return true;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org