Package org.apache.ws.resource.properties.v2004_06.porttype.impl

Source Code of org.apache.ws.resource.properties.v2004_06.porttype.impl.SetResourcePropertiesProviderTestCase

/*=============================================================================*
*  Copyright 2004 The Apache Software Foundation
*
*  Licensed 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.ws.resource.properties.v2004_06.porttype.impl;

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.resource.properties.ThrowsCallback;
import org.apache.ws.resource.properties.faults.InvalidResourcePropertyQNameFaultException;
import org.apache.ws.resource.properties.faults.InvalidSetResourcePropertiesRequestContentFaultException;
import org.apache.ws.resource.properties.faults.SetResourcePropertyRequestFailedFaultException;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlObject;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyResponseDocument;

/**
* Test case for {@link SetResourcePropertiesPortTypeImpl}.
*
* @author Sal Campana, Ian Springer
*/
public class SetResourcePropertiesProviderTestCase
   extends AbstractWsrpPortTypeImplTestCase
{
   private SushiCallback m_callback;

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testDeleteAnyPropFromOpenContentPropsDoc(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext( true );
      deleteResourceProperty( SushiPropertyQNames.FUGU );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testDeleteExistingNonOptionalProp(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      try
      {
         deleteResourceProperty( SushiPropertyQNames.EBI );
         fail(  );
      }
      catch ( InvalidSetResourcePropertiesRequestContentFaultException expectedFault )
      {
         return; // success
      }
   }

   /* ===================================== TESTS FOR 'DELETE' ====================================== */
   public void testDeleteExistingOptionalProp(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      deleteResourceProperty( SushiPropertyQNames.OHTORO );
      GetResourcePropertyResponseDocument.GetResourcePropertyResponse response =
         getResourceProperty( SushiPropertyQNames.OHTORO );
      XmlObject[]                                                     ohtoroPropElems =
         XmlBeanUtils.getChildElements( response, SushiPropertyQNames.OHTORO );
      assertNotNull( ohtoroPropElems );
      assertEquals( 0, ohtoroPropElems.length );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testDeleteNonExistingOptionalProp(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      deleteResourceProperty( SushiPropertyQNames.UNI );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testDeleteResourcePropertiesCallback(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      XmlObject xBean =
         XmlObject.Factory.parse( "<foo:Ika xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
                                  + "my favorite!" + "</foo:Ika>" );
      insertResourceProperty( new XmlObject[]
                              {
                                 xBean
                              } );
      SushiResource    resource     = (SushiResource) m_resourceContext.getResource(  );
      ResourceProperty resourceProp = resource.getResourcePropertySet(  ).get( SushiPropertyQNames.IKA );
      resourceProp.setCallback( m_callback );
      deleteResourceProperty( SushiPropertyQNames.IKA );
      GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse =
         getResourceProperty( SushiPropertyQNames.OHTORO );
      assertNotNull( getResourcePropertyResponse );
      assertTrue( m_callback.deleteWasInvoked(  ) );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testDeleteResourcePropertiesFailedCallback(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      XmlObject xBean =
         XmlObject.Factory.parse( "<foo:Ika xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
                                  + "my favorite!" + "</foo:Ika>" );
      insertResourceProperty( new XmlObject[]
                              {
                                 xBean
                              } );
      SushiResource    resource     = (SushiResource) m_resourceContext.getResource(  );
      ResourceProperty resourceProp = resource.getResourcePropertySet(  ).get( SushiPropertyQNames.IKA );
      resourceProp.setCallback( new ThrowsCallback(  ) );
      try
      {
         deleteResourceProperty( SushiPropertyQNames.IKA );
      }
      catch ( RuntimeException e )
      {
         assertEquals( SetResourcePropertyRequestFailedFaultException.class.getName(  ),
                       e.getClass(  ).getName(  ) );
         return;
      }

      fail(  );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testInsertAnyIntoNonOpenContent(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext( false );
      try
      {
         insertXsdAnyPropElem(  );
         fail(  );
      }
      catch ( InvalidResourcePropertyQNameFaultException expectedFault )
      {
         return; // success
      }
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testInsertAnyIntoOpenContent(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      insertXsdAnyPropElem(  );
      assertPropHasOneElemWithGivenValue( SushiPropertyQNames.FUGU, INITIAL_PROP_VALUE_FUGU );
   }

   /* ===================================== TESTS FOR 'INSERT' ====================================== */
   public void testInsertResourcePropertiesCallback(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      SushiResource    resource     = (SushiResource) m_resourceContext.getResource(  );
      ResourceProperty resourceProp = resource.getResourcePropertySet(  ).get( SushiPropertyQNames.EBI );
      resourceProp.setCallback( m_callback );

      XmlObject xBean =
         XmlObject.Factory.parse( "<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
                                  + "0" + "</foo:Ebi>" );
      insertResourceProperty( new XmlObject[]
                              {
                                 xBean
                              } );
      GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse =
         getResourceProperty( SushiPropertyQNames.EBI );

      assertNotNull( getResourcePropertyResponse );
      XmlObject[] childElements =
         XmlBeanUtils.getChildElements( getResourcePropertyResponse, SushiPropertyQNames.EBI );
      assertEquals( 2, childElements.length );
      assertTrue( m_callback.insertWasInvoked(  ) );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testInsertResourcePropertiesFailedCallback(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      SushiResource    resource     = (SushiResource) m_resourceContext.getResource(  );
      ResourceProperty resourceProp = resource.getResourcePropertySet(  ).get( SushiPropertyQNames.EBI );
      resourceProp.setCallback( new ThrowsCallback(  ) );

      XmlObject xBean =
         XmlObject.Factory.parse( "<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
                                  + "0" + "</foo:Ebi>" );
      try
      {
         insertResourceProperty( new XmlObject[]
                                 {
                                    xBean
                                 } );
      }
      catch ( RuntimeException e )
      {
         assertEquals( SetResourcePropertyRequestFailedFaultException.class.getName(  ),
                       e.getClass(  ).getName(  ) );
         return;
      }

      fail(  );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testInsertResourceProperty(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext(  );
      XmlObject xBean =
         XmlObject.Factory.parse( "<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
                                  + "0" + "</foo:Ebi>" );
      insertResourceProperty( new XmlObject[]
                              {
                                 xBean
                              } );
      GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse =
         getResourceProperty( SushiPropertyQNames.EBI );
      assertNotNull( getResourcePropertyResponse );
      XmlObject[] childElements =
         XmlBeanUtils.getChildElements( getResourcePropertyResponse, SushiPropertyQNames.EBI );
      assertEquals( 2, childElements.length );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   public void testUpdateOpenContent(  )
   throws Exception
   {
      m_resourceContext = new SushiResourceContext( true );
      insertXsdAnyPropElem(  );
      assertPropHasOneElemWithGivenValue( SushiPropertyQNames.FUGU, INITIAL_PROP_VALUE_FUGU );
      XmlObject    anyXBean = createXsdAnyPropElem(  );
      final String newValue = "yummy!";
      XmlBeanUtils.setValue( anyXBean, newValue );
      updateResourceProperty( new XmlObject[]
                              {
                                 anyXBean
                              } );
      assertPropHasOneElemWithGivenValue( SushiPropertyQNames.FUGU, newValue );
   }

   /* ===================================== TESTS FOR 'UPDATE' ====================================== */

   /**
    * DOCUMENT_ME
    */
   public void testUpdateResourcePropertiesCallback(  )
   throws Exception
   {
      String newValue = "99";
      m_resourceContext = new SushiResourceContext(  );
      SushiPlate    plate    = new SushiPlate(  );
      SushiCallback callback = new SushiCallback( plate );

      //setup callback on resource prop
      SushiResource    resource     = (SushiResource) m_resourceContext.getResource(  );
      ResourceProperty resourceProp = resource.getResourcePropertySet(  ).get( SushiPropertyQNames.EBI );
      resourceProp.setCallback( callback );
      XmlObject xBean =
         XmlObject.Factory.parse( "<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
                                  + newValue + "</foo:Ebi>" );
      updateResourceProperty( new XmlObject[]
                              {
                                 xBean
                              } );
      assertPropHasOneElemWithGivenValue( SushiPropertyQNames.EBI, newValue );
      assertTrue( callback.updateWasInvoked(  ) );
   }

   /**
    * DOCUMENT_ME
    */
   public void testUpdateResourceProperty(  )
   throws Exception
   {
      final String newValue = "99";
      m_resourceContext = new SushiResourceContext(  );
      XmlObject xBean =
         XmlObject.Factory.parse( "<foo:Ebi xmlns:foo=\"http://ws.apache.org/resource/properties/test/sushi\">"
                                  + newValue + "</foo:Ebi>" );
      updateResourceProperty( new XmlObject[]
                              {
                                 xBean
                              } );
      assertPropHasOneElemWithGivenValue( SushiPropertyQNames.EBI, newValue );
   }

   /**
    * DOCUMENT_ME
    *
    * @throws Exception DOCUMENT_ME
    */
   protected void setUp(  )
   throws Exception
   {
      super.setUp(  );
      m_callback = new SushiCallback( new SushiPlate(  ) );
   }
}
TOP

Related Classes of org.apache.ws.resource.properties.v2004_06.porttype.impl.SetResourcePropertiesProviderTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.