You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by sc...@apache.org on 2004/12/09 18:23:24 UTC

svn commit: r111406 - in incubator/apollo/trunk/src: java/org/apache/ws/resource/properties/porttype/impl test/org/apache/ws/resource/properties test/org/apache/ws/resource/properties/porttype/impl

Author: scamp
Date: Thu Dec  9 09:23:21 2004
New Revision: 111406

URL: http://svn.apache.org/viewcvs?view=rev&rev=111406
Log:
added unit tests for providers
Modified:
   incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProvider.java
   incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/Ebi.java
   incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiCallback.java
   incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProviderTest.java

Modified: incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProvider.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProvider.java?view=diff&rev=111406&p1=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProvider.java&r1=111405&p2=incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProvider.java&r2=111406
==============================================================================
--- incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProvider.java	(original)
+++ incubator/apollo/trunk/src/java/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProvider.java	Thu Dec  9 09:23:21 2004
@@ -293,7 +293,7 @@
 
     private void throwFaultIfInsertionViolatesSchema( ResourceProperty prop, XmlObject[] propElemsToBeInserted )
     {
-        if ( ( prop.size() + propElemsToBeInserted.length ) > prop.getMetaData().getMaxOccurs() )
+        if ( prop.getMetaData().getMaxOccurs() != -1 &&( prop.size() + propElemsToBeInserted.length ) > prop.getMetaData().getMaxOccurs() )
         {
             throw new InvalidSetResourcePropertiesRequestContentFaultException( MSG.getMessage( Keys.ERROR_PROPERTY_INSERT_VIOLATES_SCHEMA,
                     ( ( propElemsToBeInserted.length > 1 )

Modified: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/Ebi.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/Ebi.java?view=diff&rev=111406&p1=incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/Ebi.java&r1=111405&p2=incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/Ebi.java&r2=111406
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/Ebi.java	(original)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/Ebi.java	Thu Dec  9 09:23:21 2004
@@ -11,4 +11,9 @@
     {
         return m_pieces;
     }
+
+    public void setNumberOfPieces(String value)
+    {
+        m_pieces = value;
+    }
 }

Modified: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiCallback.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiCallback.java?view=diff&rev=111406&p1=incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiCallback.java&r1=111405&p2=incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiCallback.java&r2=111406
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiCallback.java	(original)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/SushiCallback.java	Thu Dec  9 09:23:21 2004
@@ -1,6 +1,7 @@
 package org.apache.ws.resource.properties;
 
 import org.apache.xmlbeans.impl.values.XmlStringImpl;
+import org.apache.xmlbeans.XmlObject;
 import org.apache.ws.util.XmlBeanUtils;
 
 import javax.xml.namespace.QName;
@@ -60,6 +61,18 @@
     public void updateProperty(Object[] prop)
     {
        m_updateInvoked = true;
+        Object o = prop[0];
+        if(o instanceof XmlObject)
+        {
+            XmlObject xmlObject = (XmlObject)o;
+            QName name = XmlBeanUtils.getName(xmlObject);
+            if(name.getLocalPart().equals("Ebi"))
+            {
+                m_plate.getEbi().setNumberOfPieces(XmlBeanUtils.getValue(xmlObject));
+            }
+        }
+
+
     }
 
     public boolean isDeleteInvoked()

Modified: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProviderTest.java
Url: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProviderTest.java?view=diff&rev=111406&p1=incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProviderTest.java&r1=111405&p2=incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProviderTest.java&r2=111406
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProviderTest.java	(original)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/porttype/impl/SetResourcePropertiesProviderTest.java	Thu Dec  9 09:23:21 2004
@@ -15,19 +15,26 @@
  *=============================================================================*/
 package org.apache.ws.resource.properties.porttype.impl;
 
+import org.apache.ws.resource.ResourceContextException;
+import org.apache.ws.resource.ResourceException;
 import org.apache.ws.resource.properties.AbstractResourcePropertiesTestCase;
+import org.apache.ws.resource.properties.ResourceProperty;
+import org.apache.ws.resource.properties.SushiCallback;
+import org.apache.ws.resource.properties.SushiPlate;
 import org.apache.ws.resource.properties.SushiPropertyQNames;
+import org.apache.ws.resource.properties.SushiResource;
 import org.apache.ws.resource.properties.SushiResourceContext;
 import org.apache.ws.util.XmlBeanUtils;
-import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.DeleteDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.DeleteType;
 import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyDocument;
 import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyResponseDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.InsertDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.InsertType;
 import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.UpdateDocument;
 import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.UpdateType;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.DeleteDocument;
-import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.DeleteType;
 
 import javax.xml.namespace.QName;
 
@@ -35,97 +42,192 @@
  * @author Sal Campana
  */
 public class SetResourcePropertiesProviderTest
-   extends AbstractResourcePropertiesTestCase
+        extends AbstractResourcePropertiesTestCase
 {
-   /**
-    * DOCUMENT_ME
-    */
-   public void testUpdateResourcePropertiesCallback(  )
-   {
-   }
-
-    public void testInsertResourcePropertiesCallback(  )
-   {
-   }
-
-   public void testDeleteResourcePropertiesCallback(  )
-   {
-   }
-   public void testInsertResourceProperty(  )
-   throws XmlException
-   {
-
-   }
-   public void testDeleteResourceProperty(  )
-   throws XmlException
-   {
-      String                        expectedValue = "thisisatest";
-      SushiResourceContext          context      = new SushiResourceContext(  );
-      SetResourcePropertiesProvider set_provider = new SetResourcePropertiesProvider( context );
-      DeleteDocument                deleteDoc    = DeleteDocument.Factory.newInstance(  );
-       DeleteType deleteType = deleteDoc.addNewDelete();
-       deleteType.setResourceProperty(SushiPropertyQNames.OHTORO);
-
-      set_provider.deleteResourceProperty( deleteType );
-      GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty(context, SushiPropertyQNames.OHTORO);
-
-      assertNull(getResourcePropertyResponse);
-   }
-
-   /**
-    * DOCUMENT_ME
-    */
-   public void testUpdateResourceProperty(  )
-   throws XmlException
-   {
-      String                        expectedValue = "thisisatest";
-      SushiResourceContext          context      = new SushiResourceContext(  );
-      SetResourcePropertiesProvider set_provider = new SetResourcePropertiesProvider( context );
-      UpdateDocument                updateDoc    = UpdateDocument.Factory.newInstance(  );
-      UpdateType                    update       = updateDoc.addNewUpdate(  );
-
-      XmlObject                     xmlObject =
-         XmlObject.Factory.parse( "<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
-                                  + expectedValue + "</foo:Ebi>" );
-      XmlBeanUtils.addChildElement( update, xmlObject );
-
-      set_provider.updateResourceProperty( updateDoc.getUpdate(  ) );
-
-      verifyViaGet( context, expectedValue, SushiPropertyQNames.EBI );
-   }
-
-   /**
-    * DOCUMENT_ME
-    *
-    * @throws Exception DOCUMENT_ME
-    */
-   protected void setUp(  )
-   throws Exception
-   {
-      initResourcePropsDoc(  );
-   }
-
-   private void verifyViaGet( SushiResourceContext context,
-                              String               expectedVariable,
-                              QName                nameToFind )
-   {
-       GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty(context, nameToFind);
-       XmlObject[]                                                     childElements =
-         XmlBeanUtils.getChildElements( getResourcePropertyResponse, nameToFind );
-      assertNotNull( childElements );
-      String value = XmlBeanUtils.getValue( childElements[0] );
-      assertEquals( value, expectedVariable );
-   }
+    /**
+     * DOCUMENT_ME
+     */
+    public void testUpdateResourcePropertiesCallback() throws ResourceException, ResourceContextException, XmlException
+    {
+        String expectedValue = "thisisatest";
+        SushiResourceContext context = new SushiResourceContext();
+        SushiPlate plate = new SushiPlate();
+        SushiCallback callback = new SushiCallback(plate);
+
+        //setup callback on resource prop
+        SushiResource resource = (SushiResource) context.getResource();
+        ResourceProperty resourceProp = resource.getResourcePropertySet().get(SushiPropertyQNames.EBI);
+        resourceProp.setCallback(callback);
+
+        SetResourcePropertiesProvider set_provider = new SetResourcePropertiesProvider(context);
+        UpdateDocument updateDoc = UpdateDocument.Factory.newInstance();
+        UpdateType update = updateDoc.addNewUpdate();
+
+        XmlObject xmlObject =
+                XmlObject.Factory.parse("<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
+                                        + expectedValue + "</foo:Ebi>");
+        XmlBeanUtils.addChildElement(update, xmlObject);
+
+        set_provider.updateResourceProperty(updateDoc.getUpdate());
+
+        verifyViaGet(context, expectedValue, SushiPropertyQNames.EBI);
+         assertTrue(callback.isUpdateInvoked());
+    }
+
+    public void testInsertResourcePropertiesCallback() throws XmlException, ResourceException, ResourceContextException
+    {
+        SushiResourceContext context = new SushiResourceContext();
+        //build callback obj
+        SushiPlate plate = new SushiPlate();
+        SushiCallback callback = new SushiCallback(plate);
+        //setup callback on resource prop
+        SushiResource resource = (SushiResource) context.getResource();
+        ResourceProperty resourceProp = resource.getResourcePropertySet().get(SushiPropertyQNames.EBI);
+        resourceProp.setCallback(callback);
+
+        SetResourcePropertiesProvider set_provider = new SetResourcePropertiesProvider(context);
+        InsertDocument insertDoc = InsertDocument.Factory.newInstance();
+        InsertType insertType = insertDoc.addNewInsert();
+
+        XmlObject xmlObject =
+                XmlObject.Factory.parse("<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
+                                        + "my favorite!" + "</foo:Ebi>");
+        XmlBeanUtils.addChildElement(insertType, xmlObject);
+
+        set_provider.insertResourceProperty(insertType);
+        GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty(context, SushiPropertyQNames.EBI);
+
+        assertNotNull(getResourcePropertyResponse);
+        XmlObject[] childElements = XmlBeanUtils.getChildElements(getResourcePropertyResponse, SushiPropertyQNames.EBI);
+        assertTrue(childElements.length == 2);
+        assertTrue(callback.isInsertInvoked());
+    }
+
+    public void testDeleteResourcePropertiesCallback() throws ResourceException, ResourceContextException, XmlException
+    {
+        SushiResourceContext context = new SushiResourceContext();
+        //build callback obj
+        SushiPlate plate = new SushiPlate();
+        SushiCallback callback = new SushiCallback(plate);
+
+        //insert a prop
+        SetResourcePropertiesProvider set_provider = new SetResourcePropertiesProvider(context);
+        InsertDocument insertDoc = InsertDocument.Factory.newInstance();
+        InsertType insertType = insertDoc.addNewInsert();
+
+        XmlObject xmlObject =
+                XmlObject.Factory.parse("<foo:Ika xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
+                                        + "my favorite!" + "</foo:Ika>");
+        XmlBeanUtils.addChildElement(insertType, xmlObject);
+
+        set_provider.insertResourceProperty(insertType);
+
+        //setup callback on resource prop
+        SushiResource resource = (SushiResource) context.getResource();
+        ResourceProperty resourceProp = resource.getResourcePropertySet().get(SushiPropertyQNames.IKA);
+        resourceProp.setCallback(callback);
+
+        DeleteDocument deleteDoc = DeleteDocument.Factory.newInstance();
+        DeleteType deleteType = deleteDoc.addNewDelete();
+        deleteType.setResourceProperty(SushiPropertyQNames.IKA);
+
+        set_provider.deleteResourceProperty(deleteType);
+        GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty(context, SushiPropertyQNames.OHTORO);
+
+        assertNotNull(getResourcePropertyResponse);
+        assertTrue(callback.isDeleteInvoked());
+    }
+
+    public void testInsertResourceProperty()
+            throws XmlException
+    {
+        SushiResourceContext context = new SushiResourceContext();
+        SetResourcePropertiesProvider set_provider = new SetResourcePropertiesProvider(context);
+        InsertDocument insertDoc = InsertDocument.Factory.newInstance();
+        InsertType insertType = insertDoc.addNewInsert();
+
+        XmlObject xmlObject =
+                XmlObject.Factory.parse("<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
+                                        + "my favorite!" + "</foo:Ebi>");
+        XmlBeanUtils.addChildElement(insertType, xmlObject);
+
+        set_provider.insertResourceProperty(insertType);
+        GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty(context, SushiPropertyQNames.EBI);
+
+        assertNotNull(getResourcePropertyResponse);
+        XmlObject[] childElements = XmlBeanUtils.getChildElements(getResourcePropertyResponse, SushiPropertyQNames.EBI);
+        assertTrue(childElements.length == 2);
+    }
+
+    public void testDeleteResourceProperty()
+            throws XmlException
+    {
+        SushiResourceContext context = new SushiResourceContext();
+        SetResourcePropertiesProvider set_provider = new SetResourcePropertiesProvider(context);
+        DeleteDocument deleteDoc = DeleteDocument.Factory.newInstance();
+        DeleteType deleteType = deleteDoc.addNewDelete();
+        deleteType.setResourceProperty(SushiPropertyQNames.OHTORO);
+
+        set_provider.deleteResourceProperty(deleteType);
+        GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty(context, SushiPropertyQNames.OHTORO);
+
+        assertNotNull(getResourcePropertyResponse);
+    }
+
+    /**
+     * DOCUMENT_ME
+     */
+    public void testUpdateResourceProperty()
+            throws XmlException
+    {
+        String expectedValue = "thisisatest";
+        SushiResourceContext context = new SushiResourceContext();
+        SetResourcePropertiesProvider set_provider = new SetResourcePropertiesProvider(context);
+        UpdateDocument updateDoc = UpdateDocument.Factory.newInstance();
+        UpdateType update = updateDoc.addNewUpdate();
+
+        XmlObject xmlObject =
+                XmlObject.Factory.parse("<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
+                                        + expectedValue + "</foo:Ebi>");
+        XmlBeanUtils.addChildElement(update, xmlObject);
+
+        set_provider.updateResourceProperty(updateDoc.getUpdate());
+
+        verifyViaGet(context, expectedValue, SushiPropertyQNames.EBI);
+    }
+
+    /**
+     * DOCUMENT_ME
+     *
+     * @throws Exception DOCUMENT_ME
+     */
+    protected void setUp()
+            throws Exception
+    {
+        initResourcePropsDoc();
+    }
+
+    private void verifyViaGet(SushiResourceContext context,
+                              String expectedVariable,
+                              QName nameToFind)
+    {
+        GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty(context, nameToFind);
+        XmlObject[] childElements =
+                XmlBeanUtils.getChildElements(getResourcePropertyResponse, nameToFind);
+        assertNotNull(childElements);
+        String value = XmlBeanUtils.getValue(childElements[0]);
+        assertEquals(expectedVariable,value );
+    }
 
     private GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourceProperty(SushiResourceContext context, QName nameToFind)
     {
-        GetResourcePropertyProvider get_provider = new GetResourcePropertyProvider( context );
-        GetResourcePropertyDocument get_document = GetResourcePropertyDocument.Factory.newInstance(  );
-        get_document.setGetResourceProperty( nameToFind );
-        GetResourcePropertyResponseDocument                             resourceProperty =
-           get_provider.getResourceProperty( get_document );
+        GetResourcePropertyProvider get_provider = new GetResourcePropertyProvider(context);
+        GetResourcePropertyDocument get_document = GetResourcePropertyDocument.Factory.newInstance();
+        get_document.setGetResourceProperty(nameToFind);
+        GetResourcePropertyResponseDocument resourceProperty =
+                get_provider.getResourceProperty(get_document);
         GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse =
-           resourceProperty.getGetResourcePropertyResponse(  );
+                resourceProperty.getGetResourcePropertyResponse();
         return getResourcePropertyResponse;
     }
 }

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