/*=============================================================================*
* 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.v1_2.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.GetMultipleResourcePropertiesDocument;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.GetMultipleResourcePropertiesResponseDocument;
import javax.xml.namespace.QName;
/**
* @author Sal Campana, Ian Springer
*/
public class GetMultipleResourcePropertiesProviderTestCase
extends AbstractWsrpPortTypeImplTestCase
{
/**
* DOCUMENT_ME
*/
public void testGetMultiExistingProps()
{
m_resourceContext = new SushiResourceContext();
final QName[] propNames = new QName[]{SushiPropertyQNames.EBI, SushiPropertyQNames.IKA};
GetMultipleResourcePropertiesResponseDocument.GetMultipleResourcePropertiesResponse response = getMultipleResourceProperties( propNames );
XmlObject[] propElems = XmlBeanUtils.getChildElements( response, null );
assertNotNull( propElems );
assertEquals( propNames.length, propElems.length );
assertEquals( propNames[0], XmlBeanUtils.getName( propElems[0] ) );
assertEquals( "9", XmlBeanUtils.getValue( propElems[0] ) );
assertEquals( propNames[1], XmlBeanUtils.getName( propElems[1] ) );
assertEquals( "mamamia", XmlBeanUtils.getValue( propElems[1] ) );
}
/**
* DOCUMENT_ME
*/
public void testGetMultiWithAllInvalidPropNames()
{
m_resourceContext = new SushiResourceContext( true );
assertGetMultiRequestThrowsFault( new QName[]{BOGUS_PROP_NAME, ANOTHER_BOGUS_PROP_NAME} );
m_resourceContext = new SushiResourceContext( false );
assertGetMultiRequestThrowsFault( new QName[]{BOGUS_PROP_NAME, ANOTHER_BOGUS_PROP_NAME} );
}
/**
* DOCUMENT_ME
*/
public void testGetMultiWithSomeInvalidPropNames()
{
m_resourceContext = new SushiResourceContext( true );
assertGetMultiRequestThrowsFault( new QName[]{SushiPropertyQNames.OHTORO, BOGUS_PROP_NAME} );
m_resourceContext = new SushiResourceContext( false );
assertGetMultiRequestThrowsFault( new QName[]{SushiPropertyQNames.OHTORO, BOGUS_PROP_NAME} );
}
/**
* DOCUMENT_ME
*/
public void testGetMultipleResourcePropertiesCallback()
throws Exception
{
m_resourceContext = new SushiResourceContext();
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 );
final QName[] propNames = new QName[]{SushiPropertyQNames.EBI, SushiPropertyQNames.IKA};
GetMultipleResourcePropertiesResponseDocument.GetMultipleResourcePropertiesResponse response = getMultipleResourceProperties( propNames );
XmlObject[] propElems = XmlBeanUtils.getChildElements( response );
assertNotNull( propElems );
assertEquals( propNames[0], XmlBeanUtils.getName( propElems[0] ) );
assertEquals( plate.getEbi().getNumberOfPieces(), XmlBeanUtils.getValue( propElems[0] ) );
}
private GetMultipleResourcePropertiesResponseDocument.GetMultipleResourcePropertiesResponse getMultipleResourceProperties( QName[] propNames )
{
GetMultipleResourcePropertiesProvider provider = new GetMultipleResourcePropertiesProvider( m_resourceContext );
GetMultipleResourcePropertiesDocument doc = GetMultipleResourcePropertiesDocument.Factory.newInstance();
GetMultipleResourcePropertiesDocument.GetMultipleResourceProperties getMultipleResourceProperties = doc.addNewGetMultipleResourceProperties();
for ( int i = 0; i < propNames.length; i++ )
{
getMultipleResourceProperties.addResourceProperty( propNames[i] );
}
GetMultipleResourcePropertiesResponseDocument responseDoc = provider.getMultipleResourceProperties( doc );
GetMultipleResourcePropertiesResponseDocument.GetMultipleResourcePropertiesResponse response =
responseDoc.getGetMultipleResourcePropertiesResponse();
return response;
}
private void assertGetMultiRequestThrowsFault( QName[] propNames )
{
GetMultipleResourcePropertiesResponseDocument.GetMultipleResourcePropertiesResponse response = null;
try
{
response = getMultipleResourceProperties( propNames );
fail( response != null ? "Expected fault, but received response." : null );
}
catch ( InvalidResourcePropertyQNameFaultException expectedFault )
{
return;
}
}
}