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 2005/02/16 17:56:49 UTC
svn commit: r154045 - in
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2: ./
draft01/ draft01/porttype/ draft01/porttype/impl/
Author: scamp
Date: Wed Feb 16 08:56:47 2005
New Revision: 154045
URL: http://svn.apache.org/viewcvs?view=rev&rev=154045
Log: (empty)
Added:
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/AbstractWsrpPortTypeImplTestCase.java
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetMultipleResourcePropertiesProviderTestCase.java
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetResourcePropertyProviderTestCase.java
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/QueryResourcePropertiesProviderTestCase.java
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/SetResourcePropertiesProviderTestCase.java
Removed:
incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2/
Added: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/AbstractWsrpPortTypeImplTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/AbstractWsrpPortTypeImplTestCase.java?view=auto&rev=154045
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/AbstractWsrpPortTypeImplTestCase.java (added)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/AbstractWsrpPortTypeImplTestCase.java Wed Feb 16 08:56:47 2005
@@ -0,0 +1,84 @@
+/*=============================================================================*
+ * 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_draft01.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.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 javax.xml.namespace.QName;
+
+/**
+ * TODO
+ *
+ * @author Ian P. Springer (Hewlett-Packard Company)
+ */
+public class AbstractWsrpPortTypeImplTestCase extends AbstractResourcePropertiesTestCase
+{
+
+ protected static final String INITIAL_PROP_VALUE_FUGU = "dangerous!";
+ protected static final QName BOGUS_PROP_NAME = new QName( "http://blah.com/", "Bogus" );
+ protected static final QName ANOTHER_BOGUS_PROP_NAME = new QName( "http://blah.com/", "EvenMoreBogus" );
+
+ 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;
+ }
+
+ protected void insertXsdAnyPropElem()
+ throws XmlException
+ {
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ InsertDocument insertDoc = InsertDocument.Factory.newInstance();
+ InsertType insertType = insertDoc.addNewInsert();
+ XmlObject anyXBean = createXsdAnyPropElem();
+ XmlBeanUtils.addChildElement( insertType, anyXBean );
+ set_provider.insertResourceProperty( insertType );
+ }
+
+ 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 );
+ }
+
+ 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;
+ }
+
+
+
+}
Added: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetMultipleResourcePropertiesProviderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetMultipleResourcePropertiesProviderTestCase.java?view=auto&rev=154045
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetMultipleResourcePropertiesProviderTestCase.java (added)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetMultipleResourcePropertiesProviderTestCase.java Wed Feb 16 08:56:47 2005
@@ -0,0 +1,127 @@
+/*=============================================================================*
+ * 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_draft01.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 )
+ {
+ GetMultipleResourcePropertiesPortTypeImpl provider = new GetMultipleResourcePropertiesPortTypeImpl( 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;
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetResourcePropertyProviderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetResourcePropertyProviderTestCase.java?view=auto&rev=154045
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetResourcePropertyProviderTestCase.java (added)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/GetResourcePropertyProviderTestCase.java Wed Feb 16 08:56:47 2005
@@ -0,0 +1,111 @@
+/*=============================================================================*
+ * 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_draft01.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;
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/QueryResourcePropertiesProviderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/QueryResourcePropertiesProviderTestCase.java?view=auto&rev=154045
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/QueryResourcePropertiesProviderTestCase.java (added)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/QueryResourcePropertiesProviderTestCase.java Wed Feb 16 08:56:47 2005
@@ -0,0 +1,159 @@
+/*=============================================================================*
+ * 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_draft01.porttype.impl;
+
+import org.apache.ws.resource.ResourceContextException;
+import org.apache.ws.resource.ResourceException;
+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.QueryEvaluationErrorFaultException;
+import org.apache.ws.resource.properties.faults.UnknownQueryExpressionDialectFaultException;
+import org.apache.ws.resource.properties.query.QueryConstants;
+import org.apache.ws.util.XmlBeanUtils;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesResponseDocument;
+
+import java.net.URI;
+
+/**
+ * Test case for {@link QueryResourcePropertiesPortTypeImpl}.
+ *
+ * @author Sal Campana, Ian Springer
+ */
+public class QueryResourcePropertiesProviderTestCase
+ extends AbstractWsrpPortTypeImplTestCase
+{
+ /**
+ * DOCUMENT_ME
+ */
+ public void testQueryResourceProperties() throws Exception
+ {
+ m_resourceContext = new SushiResourceContext();
+ QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourcePropertiesResponse = queryResourceProperties( "*" );
+ XmlObject[] allPropElems = XmlBeanUtils.getChildElements( queryResourcePropertiesResponse );
+ assertNotNull( allPropElems );
+ assertTrue( allPropElems.length == 8 );
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testQueryWithInvalidDialect() throws Exception
+ {
+ m_resourceContext = new SushiResourceContext();
+ try
+ {
+ QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse response = queryResourceProperties( "*", new URI( "http://blah.com/NotADialect" ) );
+ fail( response != null ? "Expected fault, but received response." : null );
+ }
+ catch ( UnknownQueryExpressionDialectFaultException expectedFault )
+ {
+ return;
+ }
+
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testQueryWithInvalidExpr() throws Exception
+ {
+ m_resourceContext = new SushiResourceContext();
+ try
+ {
+ QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse response = queryResourceProperties( "\\/\\/\\/\\/\\/" );
+ fail( response != null ? "Expected fault, but received response." : null );
+ }
+ catch ( QueryEvaluationErrorFaultException expectedFault )
+ {
+ return;
+ }
+
+ }
+
+ public void testQueryOpenContent() throws XmlException
+ {
+ m_resourceContext = new SushiResourceContext();
+ insertXsdAnyPropElem();
+ QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourcePropertiesResponse = queryResourceProperties( "*" );
+ XmlObject[] allPropElems = XmlBeanUtils.getChildElements( queryResourcePropertiesResponse );
+ assertNotNull( allPropElems );
+ assertTrue( allPropElems.length == 9 );
+ XmlObject[] fuguPropElems = XmlBeanUtils.getChildElements( queryResourcePropertiesResponse, SushiPropertyQNames.FUGU );
+ assertNotNull( fuguPropElems );
+ assertEquals( 1, fuguPropElems.length );
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testQueryResourcePropertiesCallback()
+ throws ResourceException,
+ ResourceContextException
+ {
+ m_resourceContext = new SushiResourceContext();
+
+ //build callback obj
+ SushiPlate plate = new SushiPlate();
+ SushiCallback callback = new SushiCallback( plate );
+
+ //check whats there
+ QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourcePropertiesResponse =
+ queryResourceProperties( "*" );
+ XmlObject[] ebiPropElems =
+ XmlBeanUtils.getChildElements( queryResourcePropertiesResponse, SushiPropertyQNames.EBI );
+ String value = XmlBeanUtils.getValue( ebiPropElems[0] );
+ assertEquals( "9", value );
+
+ //setup callback to modify resource prop
+ SushiResource resource = (SushiResource) m_resourceContext.getResource();
+ ResourceProperty resourceProp = resource.getResourcePropertySet().get( SushiPropertyQNames.EBI );
+ resourceProp.setCallback( callback );
+
+ queryResourcePropertiesResponse = queryResourceProperties( "*" );
+
+ ebiPropElems = XmlBeanUtils.getChildElements( queryResourcePropertiesResponse, SushiPropertyQNames.EBI );
+ assertNotNull( ebiPropElems );
+ value = XmlBeanUtils.getValue( ebiPropElems[0] );
+ assertEquals( plate.getEbi().getNumberOfPieces(), value );
+ }
+
+ private QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourceProperties( String xPathExpr )
+ {
+ return queryResourceProperties( xPathExpr, QueryConstants.DIALECT_URI__XPATH1_0 );
+ }
+
+ private QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourceProperties( String xPathExpr, URI dialect )
+ {
+ QueryResourcePropertiesPortTypeImpl provider = new QueryResourcePropertiesPortTypeImpl( m_resourceContext );
+ QueryResourcePropertiesDocument doc = QueryResourcePropertiesDocument.Factory.newInstance();
+ QueryResourcePropertiesDocument.QueryResourceProperties queryResourceProperties = doc.addNewQueryResourceProperties();
+ QueryExpressionType queryExpressionType = queryResourceProperties.addNewQueryExpression();
+ queryExpressionType.setDialect( dialect.toString() );
+ XmlBeanUtils.setValue( queryExpressionType, xPathExpr );
+ QueryResourcePropertiesResponseDocument queryResourcePropertiesResponseDocument = provider.queryResourceProperties( doc );
+ QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourcePropertiesResponse =
+ queryResourcePropertiesResponseDocument.getQueryResourcePropertiesResponse();
+ return queryResourcePropertiesResponse;
+ }
+}
\ No newline at end of file
Added: incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/SetResourcePropertiesProviderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/SetResourcePropertiesProviderTestCase.java?view=auto&rev=154045
==============================================================================
--- incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/SetResourcePropertiesProviderTestCase.java (added)
+++ incubator/apollo/trunk/src/test/org/apache/ws/resource/properties/v1_2_draft01/porttype/impl/SetResourcePropertiesProviderTestCase.java Wed Feb 16 08:56:47 2005
@@ -0,0 +1,283 @@
+/*=============================================================================*
+ * 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_draft01.porttype.impl;
+
+import org.apache.ws.resource.ResourceContextException;
+import org.apache.ws.resource.ResourceException;
+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.resource.properties.faults.InvalidSetResourcePropertiesRequestContentFaultException;
+import org.apache.ws.util.XmlBeanUtils;
+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.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 javax.xml.namespace.QName;
+import java.io.IOException;
+
+/**
+ * @author Sal Campana, Ian Springer
+ */
+public class SetResourcePropertiesProviderTestCase
+ extends AbstractWsrpPortTypeImplTestCase
+{
+ private SushiCallback m_callback;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ m_callback = new SushiCallback( new SushiPlate() );
+ }
+ /* ===================================== TESTS FOR 'INSERT' ====================================== */
+
+ public void testInsertResourcePropertiesCallback() throws XmlException, ResourceException, ResourceContextException
+ {
+ m_resourceContext = new SushiResourceContext();
+ //build callback obj
+ //setup callback on resource prop
+ SushiResource resource = (SushiResource) m_resourceContext.getResource();
+ ResourceProperty resourceProp = resource.getResourcePropertySet().get( SushiPropertyQNames.EBI );
+ resourceProp.setCallback( m_callback );
+
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ 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\">"
+ + "0" + "</foo:Ebi>" );
+ XmlBeanUtils.addChildElement( insertType, xmlObject );
+
+ set_provider.insertResourceProperty( insertType );
+ GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty( SushiPropertyQNames.EBI );
+
+ assertNotNull( getResourcePropertyResponse );
+ XmlObject[] childElements = XmlBeanUtils.getChildElements( getResourcePropertyResponse, SushiPropertyQNames.EBI );
+ assertEquals( 2, childElements.length );
+ assertTrue( m_callback.insertWasInvoked() );
+ }
+
+ public void testInsertResourceProperty()
+ throws XmlException
+ {
+ m_resourceContext = new SushiResourceContext();
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ 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\">"
+ + "0" + "</foo:Ebi>" );
+ XmlBeanUtils.addChildElement( insertType, xmlObject );
+
+ set_provider.insertResourceProperty( insertType );
+ GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty( SushiPropertyQNames.EBI );
+
+ assertNotNull( getResourcePropertyResponse );
+ XmlObject[] childElements = XmlBeanUtils.getChildElements( getResourcePropertyResponse, SushiPropertyQNames.EBI );
+ assertEquals( 2, childElements.length );
+ }
+
+ public void testInsertAnyIntoOpenContent() throws XmlException
+ {
+ m_resourceContext = new SushiResourceContext();
+ insertXsdAnyPropElem();
+ assertPropHasOneElemWithGivenValue( SushiPropertyQNames.FUGU, INITIAL_PROP_VALUE_FUGU );
+ }
+
+ public void testInsertAnyIntoNonOpenContent() throws Exception
+ {
+ m_resourceContext = new SushiResourceContext( false );
+ try
+ {
+ insertXsdAnyPropElem();
+ fail();
+ }
+ catch ( InvalidResourcePropertyQNameFaultException expectedFault )
+ {
+ return;
+ }
+ }
+
+ /* ===================================== 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 );
+ }
+
+ public void testDeleteNonExistingOptionalProp()
+ throws Exception
+ {
+ m_resourceContext = new SushiResourceContext();
+ deleteResourceProperty( SushiPropertyQNames.UNI );
+ }
+
+ public void testDeleteExistingNonOptionalProp()
+ throws Exception
+ {
+ m_resourceContext = new SushiResourceContext();
+ try
+ {
+ deleteResourceProperty( SushiPropertyQNames.EBI );
+ fail();
+ }
+ catch ( InvalidSetResourcePropertiesRequestContentFaultException expectedFault )
+ {
+ return;
+ }
+ }
+
+ public void testDeleteOpenContent() throws IOException, XmlException
+ {
+ m_resourceContext = new SushiResourceContext( true );
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ DeleteDocument deleteDoc = DeleteDocument.Factory.newInstance();
+ DeleteType deleteType = deleteDoc.addNewDelete();
+ deleteType.setResourceProperty( SushiPropertyQNames.FUGU );
+ set_provider.deleteResourceProperty( deleteType );
+ GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty( SushiPropertyQNames.OHTORO );
+ //todo better way to validate
+ assertNotNull( getResourcePropertyResponse );
+ }
+
+ public void testDeleteResourcePropertiesCallback() throws ResourceException, ResourceContextException, XmlException
+ {
+ m_resourceContext = new SushiResourceContext();
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ 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) m_resourceContext.getResource();
+ ResourceProperty resourceProp = resource.getResourcePropertySet().get( SushiPropertyQNames.IKA );
+ resourceProp.setCallback( m_callback );
+
+ DeleteDocument deleteDoc = DeleteDocument.Factory.newInstance();
+ DeleteType deleteType = deleteDoc.addNewDelete();
+ deleteType.setResourceProperty( SushiPropertyQNames.IKA );
+
+ set_provider.deleteResourceProperty( deleteType );
+ GetResourcePropertyResponseDocument.GetResourcePropertyResponse getResourcePropertyResponse = getResourceProperty( SushiPropertyQNames.OHTORO );
+
+ assertNotNull( getResourcePropertyResponse );
+ assertTrue( m_callback.deleteWasInvoked() );
+ }
+
+ /* ===================================== TESTS FOR 'UPDATE' ====================================== */
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testUpdateResourcePropertiesCallback() throws ResourceException, ResourceContextException, XmlException
+ {
+ 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 );
+
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ 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\">"
+ + newValue + "</foo:Ebi>" );
+ XmlBeanUtils.addChildElement( update, xmlObject );
+
+ set_provider.updateResourceProperty( updateDoc.getUpdate() );
+
+ assertPropHasOneElemWithGivenValue( SushiPropertyQNames.EBI, newValue );
+ assertTrue( callback.updateWasInvoked() );
+ }
+
+ public void testUpdateOpenContent() throws XmlException
+ {
+ m_resourceContext = new SushiResourceContext( true );
+ insertXsdAnyPropElem();
+ assertPropHasOneElemWithGivenValue( SushiPropertyQNames.FUGU, INITIAL_PROP_VALUE_FUGU );
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ UpdateDocument updateDoc = UpdateDocument.Factory.newInstance();
+ UpdateType update = updateDoc.addNewUpdate();
+ XmlObject anyXBean = createXsdAnyPropElem();
+ final String newValue = "yummy!";
+ XmlBeanUtils.setValue( anyXBean, newValue );
+ XmlBeanUtils.addChildElement( update, anyXBean );
+ set_provider.updateResourceProperty( updateDoc.getUpdate() );
+ assertPropHasOneElemWithGivenValue( SushiPropertyQNames.FUGU, newValue );
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testUpdateResourceProperty()
+ throws XmlException
+ {
+ final String newValue = "99";
+ m_resourceContext = new SushiResourceContext();
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ 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\">"
+ + newValue + "</foo:Ebi>" );
+ XmlBeanUtils.addChildElement( update, xmlObject );
+
+ set_provider.updateResourceProperty( updateDoc.getUpdate() );
+
+ assertPropHasOneElemWithGivenValue( SushiPropertyQNames.EBI, newValue );
+ }
+
+ private void deleteResourceProperty( QName propName )
+ {
+ SetResourcePropertiesPortTypeImpl set_provider = new SetResourcePropertiesPortTypeImpl( m_resourceContext );
+ DeleteDocument deleteDoc = DeleteDocument.Factory.newInstance();
+ DeleteType deleteType = deleteDoc.addNewDelete();
+ deleteType.setResourceProperty( propName );
+ set_provider.deleteResourceProperty( deleteType );
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: apollo-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: apollo-dev-help@ws.apache.org