/*=============================================================================*
* 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.faults.InvalidResourcePropertyQNameFaultException;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlObject;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyResponseDocument;
/**
* Test case for {@link GetResourcePropertyPortTypeImpl}, which consists of only one
* operation: {@link GetResourcePropertyPortTypeImpl#getResourceProperty(org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyDocument)}
*
* @author Sal Campana, Ian Springer
*/
public class GetResourcePropertyProviderTestCase
extends AbstractWsrpPortTypeImplTestCase
{
/**
* Tests that a GetRP request for an existing prop returns a GetRPResponse elem containing that prop.
*/
public void testGetExistingProp()
{
m_resourceContext = new SushiResourceContext();
GetResourcePropertyResponseDocument.GetResourcePropertyResponse response = getResourceProperty( SushiPropertyQNames.IKA );
XmlObject[] ebiPropElems = XmlBeanUtils.getChildElements( response, SushiPropertyQNames.IKA );
assertNotNull( ebiPropElems );
assertEquals( 1, ebiPropElems.length );
assertEquals( "mamamia", XmlBeanUtils.getValue( ebiPropElems[0] ) );
}
/**
* Tests that a GetRP request for a non-existing optional prop returns an empty GetRPResponse elem.
*/
public void testGetNonexistingOptionalProp()
{
m_resourceContext = new SushiResourceContext();
GetResourcePropertyResponseDocument.GetResourcePropertyResponse response = getResourceProperty( SushiPropertyQNames.UNI );
XmlObject[] uniPropElems = XmlBeanUtils.getChildElements( response, SushiPropertyQNames.UNI );
assertNotNull( uniPropElems );
assertEquals( 0, uniPropElems.length );
}
/**
* Tests that a GetRP request for an invalid prop QName throws a fault exception,
* wether or not the RP doc permits open content.
*/
public void testGetInvalidProp()
{
m_resourceContext = new SushiResourceContext( true );
assertGetRequestForInvalidPropThrowsFault();
m_resourceContext = new SushiResourceContext( false );
assertGetRequestForInvalidPropThrowsFault();
}
/**
* Test that {@link GetResourcePropertyPortTypeImpl#getResourceProperty(org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetResourcePropertyDocument)}
* invokes a {@link org.apache.ws.resource.properties.ResourcePropertyCallback} if one is registered for the
* requested property.
*/
public void testGetPropertyTriggersCallback() throws Exception
{
m_resourceContext = new SushiResourceContext();
// create and register callback object
SushiPlate plate = new SushiPlate();
SushiCallback callback = new SushiCallback( plate );
SushiResource resource = (SushiResource) m_resourceContext.getResource();
ResourceProperty resourceProp = resource.getResourcePropertySet().get( SushiPropertyQNames.EBI );
resourceProp.setCallback( callback );
// send GetRP request and make sure prop got updated by callback.refreshProperty()
GetResourcePropertyResponseDocument.GetResourcePropertyResponse response = getResourceProperty( SushiPropertyQNames.EBI );
XmlObject[] ebiPropElems = XmlBeanUtils.getChildElements( response, SushiPropertyQNames.EBI );
assertNotNull( ebiPropElems );
assertEquals( 1, ebiPropElems.length );
assertEquals( plate.getEbi().getNumberOfPieces(), XmlBeanUtils.getValue( ebiPropElems[0] ) );
}
private void assertGetRequestForInvalidPropThrowsFault()
{
try
{
GetResourcePropertyResponseDocument.GetResourcePropertyResponse response = getResourceProperty( BOGUS_PROP_NAME );
fail( response != null ? "Expected fault, but received response." : null );
}
catch ( InvalidResourcePropertyQNameFaultException expectedFault )
{
return;
}
}
}