/*=============================================================================*
* 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.AbstractResourcePropertiesTestCase;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
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.InsertType;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.SetResourcePropertiesDocument;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.UpdateType;
import javax.xml.namespace.QName;
/**
* Base class for test cases for WSRP portType impls.
*
* @author Ian Springer
*/
public abstract class AbstractWsrpPortTypeImplTestCase
extends AbstractResourcePropertiesTestCase
{
/** DOCUMENT_ME */
protected static final String INITIAL_PROP_VALUE_FUGU = "dangerous!";
/** DOCUMENT_ME */
protected static final QName BOGUS_PROP_NAME = new QName( "http://blah.com/", "Bogus" );
/** DOCUMENT_ME */
protected static final QName ANOTHER_BOGUS_PROP_NAME = new QName( "http://blah.com/", "EvenMoreBogus" );
/**
* DOCUMENT_ME
*
* @param propName DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
protected GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourceProperty( QName propName )
{
GetResourcePropertyPortTypeImpl get_provider = new GetResourcePropertyPortTypeImpl( m_resourceContext );
GetResourcePropertyDocument get_document = GetResourcePropertyDocument.Factory.newInstance( );
get_document.setGetResourceProperty( propName );
GetResourcePropertyResponseDocument resourceProperty =
get_provider.getResourceProperty( get_document );
GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse =
resourceProperty.getGetResourcePropertyResponse( );
return getResourcePropertyResponse;
}
/**
* DOCUMENT_ME
*
* @param propName DOCUMENT_ME
* @param expectedValue DOCUMENT_ME
*/
protected void assertPropHasOneElemWithGivenValue( QName propName,
String expectedValue )
{
GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse =
getResourceProperty( propName );
XmlObject[] propElems =
XmlBeanUtils.getChildElements( getResourcePropertyResponse, propName );
assertNotNull( propElems );
String value = XmlBeanUtils.getValue( propElems[0] );
assertEquals( expectedValue, value );
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*
* @throws XmlException DOCUMENT_ME
*/
protected XmlObject createXsdAnyPropElem( )
throws XmlException
{
XmlOptions xOpts = new XmlOptions( );
XmlObject xBean =
XmlObject.Factory.parse( "<fu:Fugu xmlns:fu=\"http://ws.apache.org/resource/properties/test/sushi/blowfish\">"
+ INITIAL_PROP_VALUE_FUGU + "</fu:Fugu>", xOpts );
return xBean;
}
/**
* DOCUMENT_ME
*
* @param propName DOCUMENT_ME
*/
protected void deleteResourceProperty( QName propName )
{
SetResourcePropertiesPortTypeImpl setProvider =
new SetResourcePropertiesPortTypeImpl( m_resourceContext );
SetResourcePropertiesDocument setDocument =
SetResourcePropertiesDocument.Factory.newInstance( );
SetResourcePropertiesDocument.SetResourceProperties setType = setDocument.addNewSetResourceProperties( );
DeleteType deleteType = setType.addNewDelete( );
deleteType.setResourceProperty( propName );
setProvider.setResourceProperties( setDocument ).getSetResourcePropertiesResponse( );
}
/**
* DOCUMENT_ME
*
* @param propElems DOCUMENT_ME
*/
protected void insertResourceProperty( XmlObject[] propElems )
{
SetResourcePropertiesPortTypeImpl setProvider =
new SetResourcePropertiesPortTypeImpl( m_resourceContext );
SetResourcePropertiesDocument setDocument =
SetResourcePropertiesDocument.Factory.newInstance( );
SetResourcePropertiesDocument.SetResourceProperties setType = setDocument.addNewSetResourceProperties( );
InsertType insertType = setType.addNewInsert( );
for ( int i = 0; i < propElems.length; i++ )
{
XmlBeanUtils.addChildElement( insertType, propElems[i] );
}
setProvider.setResourceProperties( setDocument ).getSetResourcePropertiesResponse( );
}
/**
* DOCUMENT_ME
*
* @throws XmlException DOCUMENT_ME
*/
protected void insertXsdAnyPropElem( )
throws XmlException
{
XmlObject anyXBean = createXsdAnyPropElem( );
insertResourceProperty( new XmlObject[]
{
anyXBean
} );
}
/**
* DOCUMENT_ME
*
* @param propElems DOCUMENT_ME
*/
protected void updateResourceProperty( XmlObject[] propElems )
{
SetResourcePropertiesPortTypeImpl setProvider =
new SetResourcePropertiesPortTypeImpl( m_resourceContext );
SetResourcePropertiesDocument setDocument =
SetResourcePropertiesDocument.Factory.newInstance( );
SetResourcePropertiesDocument.SetResourceProperties setType = setDocument.addNewSetResourceProperties( );
UpdateType updateType = setType.addNewUpdate( );
for ( int i = 0; i < propElems.length; i++ )
{
XmlBeanUtils.addChildElement( updateType, propElems[i] );
}
setProvider.setResourceProperties( setDocument ).getSetResourcePropertiesResponse( );
}
}