You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-commits@ws.apache.org by sc...@apache.org on 2005/08/02 18:30:44 UTC
svn commit: r227033 [27/27] - in /webservices/wsrf/trunk: ./
src/java/org/apache/ws/ src/java/org/apache/ws/addressing/
src/java/org/apache/ws/addressing/v2003_03/
src/java/org/apache/ws/addressing/v2004_08_10/
src/java/org/apache/ws/resource/ src/java...
Modified: webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java?rev=227033&r1=227032&r2=227033&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java (original)
+++ webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/QueryResourcePropertiesProviderTestCase.java Tue Aug 2 09:28:49 2005
@@ -1,157 +1,179 @@
-/*=============================================================================*
- * 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.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.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}.
- * TODO: add some tests with query expressions that contain prefixes
- *
- * @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 Exception
- {
- m_resourceContext = new SushiResourceContext();
- insertXsdAnyPropElem();
- QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourcePropertiesResponse = queryResourceProperties( "*" );
- XmlObject[] allPropElems = XmlBeanUtils.getChildElements( queryResourcePropertiesResponse );
- assertNotNull( allPropElems );
- assertEquals( 9, allPropElems.length );
- XmlObject[] fuguPropElems = XmlBeanUtils.getChildElements( queryResourcePropertiesResponse, SushiPropertyQNames.FUGU );
- assertNotNull( fuguPropElems );
- assertEquals( 1, fuguPropElems.length );
- }
-
- /**
- * DOCUMENT_ME
- */
- public void testQueryResourcePropertiesCallback()
- throws Exception
- {
- 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;
- }
+/*=============================================================================*
+ * 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.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.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}.
+ * TODO: add some tests with query expressions that contain prefixes
+ *
+ * @author Sal Campana, Ian Springer
+ */
+public class QueryResourcePropertiesProviderTestCase
+ extends AbstractWsrpPortTypeImplTestCase
+{
+ /**
+ * DOCUMENT_ME
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ public void testQueryOpenContent( )
+ throws Exception
+ {
+ m_resourceContext = new SushiResourceContext( );
+ insertXsdAnyPropElem( );
+ QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse queryResourcePropertiesResponse =
+ queryResourceProperties( "*" );
+ XmlObject[] allPropElems =
+ XmlBeanUtils.getChildElements( queryResourcePropertiesResponse );
+ assertNotNull( allPropElems );
+ assertEquals( 9, allPropElems.length );
+ XmlObject[] fuguPropElems =
+ XmlBeanUtils.getChildElements( queryResourcePropertiesResponse, SushiPropertyQNames.FUGU );
+ assertNotNull( fuguPropElems );
+ assertEquals( 1, fuguPropElems.length );
+ }
+
+ /**
+ * 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 testQueryResourcePropertiesCallback( )
+ throws Exception
+ {
+ 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 );
+ }
+
+ /**
+ * 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;
+ }
+ }
+
+ 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;
+ }
}
Modified: webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/SetResourcePropertiesProviderTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/SetResourcePropertiesProviderTestCase.java?rev=227033&r1=227032&r2=227033&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/SetResourcePropertiesProviderTestCase.java (original)
+++ webservices/wsrf/trunk/src/test/org/apache/ws/resource/properties/v2004_06/porttype/impl/SetResourcePropertiesProviderTestCase.java Tue Aug 2 09:28:49 2005
@@ -1,262 +1,353 @@
-/*=============================================================================*
- * 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;
-
- protected void setUp() throws Exception
- {
- super.setUp();
- m_callback = new SushiCallback( new SushiPlate() );
- }
- /* ===================================== 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() );
- }
-
- 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 );
- }
-
- public void testInsertAnyIntoOpenContent() throws Exception
- {
- 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; // success
- }
- }
-
- 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();
- }
-
-
-
- /* ===================================== 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; // success
- }
- }
-
- public void testDeleteAnyPropFromOpenContentPropsDoc() throws Exception
- {
- m_resourceContext = new SushiResourceContext( true );
- deleteResourceProperty( SushiPropertyQNames.FUGU );
- }
-
- 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() );
- }
-
- 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();
- }
-
- /* ===================================== 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() );
- }
-
- 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 );
- }
-
- /**
- * 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 );
- }
-
+/*=============================================================================*
+ * 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( ) );
+ }
}
Modified: webservices/wsrf/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java?rev=227033&r1=227032&r2=227033&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java (original)
+++ webservices/wsrf/trunk/src/test/org/apache/ws/util/XmlBeanUtilsTestCase.java Tue Aug 2 09:28:49 2005
@@ -32,7 +32,6 @@
import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument;
import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
import org.xmlsoap.schemas.ws.x2003.x03.addressing.ReferencePropertiesType;
-
import javax.xml.namespace.QName;
import java.util.Calendar;
@@ -42,213 +41,243 @@
* @author Ian Springer
*/
public class XmlBeanUtilsTestCase
- extends AbstractResourcePropertiesTestCase
+ extends AbstractResourcePropertiesTestCase
{
+ private XmlObject m_propsDoc;
- private XmlObject m_propsDoc;
-
- /**
- * DOCUMENT_ME
- *
- * @throws Exception DOCUMENT_ME
- */
- public void setUp()
- throws Exception
- {
- initResourcePropsDoc();
- m_propsDoc = ( (XmlBeansResourcePropertySet) m_resourcePropSet ).toXmlObject();
- }
-
- /**
- * Test for {@link XmlBeanUtils#addChildElement(org.apache.xmlbeans.XmlObject, org.apache.xmlbeans.XmlObject)}.
- * NOTE: This test relies on {@link XmlBeanUtils#getChildElements(org.apache.xmlbeans.XmlObject, javax.xml.namespace.QName)},
- * so it assumes that method has been tested elsewhere.
- *
- * @throws Exception on error
- */
- public void testAddChildElement()
- throws Exception
- {
- ResourcePropertyValueChangeNotificationType resourcePropertyValueChangeNotificationType = ResourcePropertyValueChangeNotificationType.Factory.newInstance();
- ResourcePropertyValueChangeNotificationType.OldValue oldValue = resourcePropertyValueChangeNotificationType.addNewOldValue();
- XmlBeanUtils.addChildElement( oldValue, XmlObject.Factory.parse( "<fo>fum</fo>" ) );
- // add a second one, so we can make sure they get added in the right order...
- XmlBeanUtils.addChildElement( oldValue, XmlObject.Factory.parse( "<fo>nub</fo>" ) );
- XmlObject[] childElems = XmlBeanUtils.getChildElements( oldValue, new QName( "fo" ) );
- assertEquals( 2, childElems.length );
- XmlObject[] grandchildElems = XmlBeanUtils.getChildElements( childElems[0], new QName( "fo" ) );
- assertEquals( 0, grandchildElems.length ); // this tests the nefarious "redundant grandchild" cursor bug
- assertEquals( "fum", XmlBeanUtils.getValue( childElems[0] ) );
- assertEquals( "nub", XmlBeanUtils.getValue( childElems[1] ) );
-
- resourcePropertyValueChangeNotificationType = ResourcePropertyValueChangeNotificationType.Factory.newInstance();
- oldValue = resourcePropertyValueChangeNotificationType.addNewOldValue();
- CurrentTimeDocument currentTimeDocument = CurrentTimeDocument.Factory.newInstance();
- currentTimeDocument.setCurrentTime( Calendar.getInstance( ) );
- XmlObject newXBean = XmlBeanUtils.copyXmlBean( currentTimeDocument.xgetCurrentTime() );
- XmlBeanUtils.addChildElement( oldValue, newXBean );
- childElems = XmlBeanUtils.getChildElements( oldValue, new QName( "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd", "CurrentTime" ) );
- assertEquals( 1, childElems.length );
- XmlObject currentTimeElem = childElems[0];
- childElems = XmlBeanUtils.getChildElements( currentTimeElem, new QName( "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd", "CurrentTime" ) );
- assertEquals( 0, childElems.length );
-
- QName elemName = SushiPropertyQNames.IKA;
- String elemValue = "whatever";
- XmlObject xBean = XmlObject.Factory.parse(
- "<" + elemName.getLocalPart() + " xmlns=\"" + elemName.getNamespaceURI() + "\">" + elemValue + "</" +
- elemName.getLocalPart() +
- ">" );
- // first test adding to an element that already has children...
- XmlBeanUtils.addChildElement( m_propsDoc, xBean );
- childElems = XmlBeanUtils.getChildElements( m_propsDoc, elemName );
- assertEquals( 2, childElems.length );
- assertTrue( childElems[1] instanceof XmlString );
-
- // now test adding to a childless element...
- EndpointReferenceDocument eprDoc = EndpointReferenceDocument.Factory.newInstance();
- EndpointReferenceType epr = eprDoc.addNewEndpointReference();
- ReferencePropertiesType refPropsType = epr.addNewReferenceProperties();
- XmlBeanUtils.addChildElement( refPropsType, xBean );
- childElems = XmlBeanUtils.getChildElements( refPropsType, elemName );
- assertEquals( 1, childElems.length );
- assertTrue( childElems[0] instanceof XmlString );
- }
-
- /**
- * Test for {@link XmlBeanUtils#addChildElement(org.apache.xmlbeans.XmlObject, QName)}.
- * NOTE: This test relies on {@link XmlBeanUtils#getChildElements(org.apache.xmlbeans.XmlObject, javax.xml.namespace.QName)},
- * so it assumes that method has been tested elsewhere.
- *
- * @throws Exception on error
- */
- public void testAddChildElementByName()
- throws Exception
- {
- final QName elemName = SushiPropertyQNames.IKA;
- // first test adding to an element that already has children...
- XmlBeanUtils.addChildElement( m_propsDoc, elemName );
- XmlObject[] childElems = XmlBeanUtils.getChildElements( m_propsDoc, elemName );
- assertEquals( 2, childElems.length );
- // now test adding to a childless element...
- EndpointReferenceDocument eprDoc = EndpointReferenceDocument.Factory.newInstance();
- EndpointReferenceType epr = eprDoc.addNewEndpointReference();
- ReferencePropertiesType refPropsType = epr.addNewReferenceProperties();
- XmlBeanUtils.addChildElement( refPropsType, elemName );
- childElems = XmlBeanUtils.getChildElements( refPropsType, elemName );
- assertEquals( 1, childElems.length );
- }
-
- /**
- * DOCUMENT_ME
- */
- public void testGetChildElements()
- {
- XmlObject[] childElems = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.IKA );
- assertEquals( 1, childElems.length );
- assertTrue( childElems[0] instanceof XmlString );
- }
-
- /**
- * DOCUMENT_ME
- */
- public void testGetName()
- {
- assertEquals( SushiPropertyQNames.OPEN_SUSHI_PROPERTIES, XmlBeanUtils.getName( m_propsDoc ) );
- }
-
- /**
- * DOCUMENT_ME
- */
- public void testRemoveChildElements()
- {
- XmlObject[] ebiChildElems = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.EBI );
- assertEquals( 1, ebiChildElems.length );
- int totalChildElemsBefore = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.EBI ).length;
- XmlBeanUtils.removeChildElements( m_propsDoc, SushiPropertyQNames.EBI );
- ebiChildElems = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.EBI );
- assertEquals( 0, ebiChildElems.length );
- int totalChildElemsAfter = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.EBI ).length;
- assertEquals( 1, totalChildElemsBefore - totalChildElemsAfter );
- }
-
- /**
- * Test for {@link XmlBeanUtils#setValueAsQName(XmlObject, QName)}.
- */
- public void testSetValueAsQName()
- {
- QueryExpressionDocument queryExpressionDocument = QueryExpressionDocument.Factory.newInstance();
- QueryExpressionType queryExpressionType = queryExpressionDocument.addNewQueryExpression();
- XmlBeanUtils.setValueAsQName( queryExpressionType, SushiPropertyQNames.AKAGI );
- XmlCursor xCursor = queryExpressionType.newCursor();
- String prefix = xCursor.prefixForNamespace( SushiPropertyQNames.AKAGI.getNamespaceURI() );
- String value = xCursor.getTextValue();
- assertEquals( prefix + ":" + SushiPropertyQNames.AKAGI.getLocalPart(), value );
- }
-
- /**
- * Test for {@link XmlBeanUtils#copyXmlBean(XmlObject)}.
- */
- public void testCopyXmlBean()
- {
- // TODO: write this test
- }
-
- /**
- * DOCUMENT_ME
- */
- public void testSet()
- {
- XmlString xString1 = XmlString.Factory.newInstance();
- xString1.setStringValue( "one" );
- XmlString xString2 = XmlString.Factory.newInstance();
- xString2.setStringValue( "two" );
- XmlCursor xmlCursor = xString1.newCursor();
- xmlCursor.toPrevToken();
- XmlObject object = xmlCursor.getObject();
- xString1 = (XmlString) object.set( xString2 );
- System.out.println( xString1 );
-
- ResourcePropertyValueChangeNotificationDocument resourcePropertyValueChangeNotificationDocument = ResourcePropertyValueChangeNotificationDocument.Factory.newInstance();
- ResourcePropertyValueChangeNotificationType resourcePropertyValueChangeNotificationType = resourcePropertyValueChangeNotificationDocument.addNewResourcePropertyValueChangeNotification();
- ResourcePropertyValueChangeNotificationType.OldValue oldValue = resourcePropertyValueChangeNotificationType.addNewOldValue();
- XmlCursor parentCursor = oldValue.newCursor();
- if ( parentCursor.toLastChild() )
- {
- parentCursor.toEndToken();
- parentCursor.toNextToken();
- }
- parentCursor.toEndToken();
- parentCursor.insertElement( new QName( "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-BaseFaults-1.2-draft-01.xsd", "BaseFault" ));
- System.out.println( "BEFORE:\n" + oldValue.xmlText( new XmlOptions().setSaveOuter() ) );
- parentCursor.toPrevSibling();
- XmlObject childXBean = parentCursor.getObject();
- parentCursor.dispose();
- //BaseFaultDocument baseFaultDocument = BaseFaultDocument.Factory.newInstance( );
- //BaseFaultType baseFaultType = baseFaultDocument.addNewBaseFault();
- BaseFaultType baseFaultType = BaseFaultType.Factory.newInstance( );
- baseFaultType.setTimestamp( Calendar.getInstance( ) );
- childXBean.set( baseFaultType );
- System.out.println( "AFTER:\n" + oldValue.xmlText( new XmlOptions().setSaveOuter() ) );
-
- ResourcePropertyValueChangeNotificationDocument resourcePropertyValueChangeNotificationDocument1 = ResourcePropertyValueChangeNotificationDocument.Factory.newInstance();
- ResourcePropertyValueChangeNotificationType resourcePropertyValueChangeNotificationType1 = resourcePropertyValueChangeNotificationDocument.addNewResourcePropertyValueChangeNotification();
- ResourcePropertyValueChangeNotificationType.OldValue oldValue1 = resourcePropertyValueChangeNotificationType1.addNewOldValue();
- oldValue1.newCursor().setTextValue( "one" );
- System.out.println( resourcePropertyValueChangeNotificationDocument );
-
- ResourcePropertyValueChangeNotificationType resourcePropertyValueChangeNotificationType2 = ResourcePropertyValueChangeNotificationType.Factory.newInstance();
- ResourcePropertyValueChangeNotificationType.OldValue oldValue2 = resourcePropertyValueChangeNotificationType2.addNewOldValue();
- oldValue2.newCursor().setTextValue( "two" );
- oldValue1 = (ResourcePropertyValueChangeNotificationType.OldValue) oldValue1.set( oldValue2 );
- System.out.println( resourcePropertyValueChangeNotificationDocument1 );
-
- GetResourcePropertyDocument getResourcePropertyDoc1 = GetResourcePropertyDocument.Factory.newInstance();
- getResourcePropertyDoc1.setGetResourceProperty( new QName( "one" ) );
- GetResourcePropertyDocument getResourcePropertyDoc2 = GetResourcePropertyDocument.Factory.newInstance();
- getResourcePropertyDoc2.setGetResourceProperty( new QName( "two" ) );
- getResourcePropertyDoc1 = (GetResourcePropertyDocument) getResourcePropertyDoc1.set( getResourcePropertyDoc2 );
- System.out.println( getResourcePropertyDoc1 );
- }
-
+ /**
+ * DOCUMENT_ME
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ public void setUp( )
+ throws Exception
+ {
+ initResourcePropsDoc( );
+ m_propsDoc = ( (XmlBeansResourcePropertySet) m_resourcePropSet ).toXmlObject( );
+ }
+
+ /**
+ * Test for {@link XmlBeanUtils#addChildElement(org.apache.xmlbeans.XmlObject, org.apache.xmlbeans.XmlObject)}.
+ * NOTE: This test relies on {@link XmlBeanUtils#getChildElements(org.apache.xmlbeans.XmlObject, javax.xml.namespace.QName)},
+ * so it assumes that method has been tested elsewhere.
+ *
+ * @throws Exception on error
+ */
+ public void testAddChildElement( )
+ throws Exception
+ {
+ ResourcePropertyValueChangeNotificationType resourcePropertyValueChangeNotificationType =
+ ResourcePropertyValueChangeNotificationType.Factory.newInstance( );
+ ResourcePropertyValueChangeNotificationType.OldValue oldValue =
+ resourcePropertyValueChangeNotificationType.addNewOldValue( );
+ XmlBeanUtils.addChildElement( oldValue,
+ XmlObject.Factory.parse( "<fo>fum</fo>" ) );
+
+ // add a second one, so we can make sure they get added in the right order...
+ XmlBeanUtils.addChildElement( oldValue,
+ XmlObject.Factory.parse( "<fo>nub</fo>" ) );
+ XmlObject[] childElems = XmlBeanUtils.getChildElements( oldValue,
+ new QName( "fo" ) );
+ assertEquals( 2, childElems.length );
+ XmlObject[] grandchildElems = XmlBeanUtils.getChildElements( childElems[0],
+ new QName( "fo" ) );
+ assertEquals( 0, grandchildElems.length ); // this tests the nefarious "redundant grandchild" cursor bug
+ assertEquals( "fum",
+ XmlBeanUtils.getValue( childElems[0] ) );
+ assertEquals( "nub",
+ XmlBeanUtils.getValue( childElems[1] ) );
+
+ resourcePropertyValueChangeNotificationType =
+ ResourcePropertyValueChangeNotificationType.Factory.newInstance( );
+ oldValue = resourcePropertyValueChangeNotificationType.addNewOldValue( );
+ CurrentTimeDocument currentTimeDocument = CurrentTimeDocument.Factory.newInstance( );
+ currentTimeDocument.setCurrentTime( Calendar.getInstance( ) );
+ XmlObject newXBean = XmlBeanUtils.copyXmlBean( currentTimeDocument.xgetCurrentTime( ) );
+ XmlBeanUtils.addChildElement( oldValue, newXBean );
+ childElems =
+ XmlBeanUtils.getChildElements( oldValue,
+ new QName( "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd",
+ "CurrentTime" ) );
+ assertEquals( 1, childElems.length );
+ XmlObject currentTimeElem = childElems[0];
+ childElems =
+ XmlBeanUtils.getChildElements( currentTimeElem,
+ new QName( "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd",
+ "CurrentTime" ) );
+ assertEquals( 0, childElems.length );
+
+ QName elemName = SushiPropertyQNames.IKA;
+ String elemValue = "whatever";
+ XmlObject xBean =
+ XmlObject.Factory.parse( "<" + elemName.getLocalPart( ) + " xmlns=\"" + elemName.getNamespaceURI( )
+ + "\">" + elemValue + "</" + elemName.getLocalPart( ) + ">" );
+
+ // first test adding to an element that already has children...
+ XmlBeanUtils.addChildElement( m_propsDoc, xBean );
+ childElems = XmlBeanUtils.getChildElements( m_propsDoc, elemName );
+ assertEquals( 2, childElems.length );
+ assertTrue( childElems[1] instanceof XmlString );
+
+ // now test adding to a childless element...
+ EndpointReferenceDocument eprDoc = EndpointReferenceDocument.Factory.newInstance( );
+ EndpointReferenceType epr = eprDoc.addNewEndpointReference( );
+ ReferencePropertiesType refPropsType = epr.addNewReferenceProperties( );
+ XmlBeanUtils.addChildElement( refPropsType, xBean );
+ childElems = XmlBeanUtils.getChildElements( refPropsType, elemName );
+ assertEquals( 1, childElems.length );
+ assertTrue( childElems[0] instanceof XmlString );
+ }
+
+ /**
+ * Test for {@link XmlBeanUtils#addChildElement(org.apache.xmlbeans.XmlObject, QName)}.
+ * NOTE: This test relies on {@link XmlBeanUtils#getChildElements(org.apache.xmlbeans.XmlObject, javax.xml.namespace.QName)},
+ * so it assumes that method has been tested elsewhere.
+ *
+ * @throws Exception on error
+ */
+ public void testAddChildElementByName( )
+ throws Exception
+ {
+ final QName elemName = SushiPropertyQNames.IKA;
+
+ // first test adding to an element that already has children...
+ XmlBeanUtils.addChildElement( m_propsDoc, elemName );
+ XmlObject[] childElems = XmlBeanUtils.getChildElements( m_propsDoc, elemName );
+ assertEquals( 2, childElems.length );
+
+ // now test adding to a childless element...
+ EndpointReferenceDocument eprDoc = EndpointReferenceDocument.Factory.newInstance( );
+ EndpointReferenceType epr = eprDoc.addNewEndpointReference( );
+ ReferencePropertiesType refPropsType = epr.addNewReferenceProperties( );
+ XmlBeanUtils.addChildElement( refPropsType, elemName );
+ childElems = XmlBeanUtils.getChildElements( refPropsType, elemName );
+ assertEquals( 1, childElems.length );
+ }
+
+ /**
+ * Test for {@link XmlBeanUtils#copyXmlBean(XmlObject)}.
+ */
+ public void testCopyXmlBean( )
+ {
+ // TODO: write this test
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testGetChildElements( )
+ {
+ XmlObject[] childElems = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.IKA );
+ assertEquals( 1, childElems.length );
+ assertTrue( childElems[0] instanceof XmlString );
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testGetName( )
+ {
+ assertEquals( SushiPropertyQNames.OPEN_SUSHI_PROPERTIES,
+ XmlBeanUtils.getName( m_propsDoc ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testRemoveChildElements( )
+ {
+ XmlObject[] ebiChildElems = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.EBI );
+ assertEquals( 1, ebiChildElems.length );
+ int totalChildElemsBefore = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.EBI ).length;
+ XmlBeanUtils.removeChildElements( m_propsDoc, SushiPropertyQNames.EBI );
+ ebiChildElems = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.EBI );
+ assertEquals( 0, ebiChildElems.length );
+ int totalChildElemsAfter = XmlBeanUtils.getChildElements( m_propsDoc, SushiPropertyQNames.EBI ).length;
+ assertEquals( 1, totalChildElemsBefore - totalChildElemsAfter );
+ }
+
+ /**
+ * DOCUMENT_ME
+ */
+ public void testSet( )
+ {
+ XmlString xString1 = XmlString.Factory.newInstance( );
+ xString1.setStringValue( "one" );
+ XmlString xString2 = XmlString.Factory.newInstance( );
+ xString2.setStringValue( "two" );
+ XmlCursor xmlCursor = xString1.newCursor( );
+ xmlCursor.toPrevToken( );
+ XmlObject object = xmlCursor.getObject( );
+ xString1 = (XmlString) object.set( xString2 );
+ System.out.println( xString1 );
+
+ ResourcePropertyValueChangeNotificationDocument resourcePropertyValueChangeNotificationDocument =
+ ResourcePropertyValueChangeNotificationDocument.Factory.newInstance( );
+ ResourcePropertyValueChangeNotificationType resourcePropertyValueChangeNotificationType =
+ resourcePropertyValueChangeNotificationDocument.addNewResourcePropertyValueChangeNotification( );
+ ResourcePropertyValueChangeNotificationType.OldValue oldValue =
+ resourcePropertyValueChangeNotificationType.addNewOldValue( );
+ XmlCursor parentCursor =
+ oldValue.newCursor( );
+ if ( parentCursor.toLastChild( ) )
+ {
+ parentCursor.toEndToken( );
+ parentCursor.toNextToken( );
+ }
+
+ parentCursor.toEndToken( );
+ parentCursor.insertElement( new QName( "http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-BaseFaults-1.2-draft-01.xsd",
+ "BaseFault" ) );
+ System.out.println( "BEFORE:\n" + oldValue.xmlText( new XmlOptions( ).setSaveOuter( ) ) );
+ parentCursor.toPrevSibling( );
+ XmlObject childXBean = parentCursor.getObject( );
+ parentCursor.dispose( );
+
+ //BaseFaultDocument baseFaultDocument = BaseFaultDocument.Factory.newInstance( );
+ //BaseFaultType baseFaultType = baseFaultDocument.addNewBaseFault();
+ BaseFaultType baseFaultType = BaseFaultType.Factory.newInstance( );
+ baseFaultType.setTimestamp( Calendar.getInstance( ) );
+ childXBean.set( baseFaultType );
+ System.out.println( "AFTER:\n" + oldValue.xmlText( new XmlOptions( ).setSaveOuter( ) ) );
+
+ ResourcePropertyValueChangeNotificationDocument resourcePropertyValueChangeNotificationDocument1 =
+ ResourcePropertyValueChangeNotificationDocument.Factory.newInstance( );
+ ResourcePropertyValueChangeNotificationType resourcePropertyValueChangeNotificationType1 =
+ resourcePropertyValueChangeNotificationDocument.addNewResourcePropertyValueChangeNotification( );
+ ResourcePropertyValueChangeNotificationType.OldValue oldValue1 =
+ resourcePropertyValueChangeNotificationType1.addNewOldValue( );
+ oldValue1.newCursor( ).setTextValue( "one" );
+ System.out.println( resourcePropertyValueChangeNotificationDocument );
+
+ ResourcePropertyValueChangeNotificationType resourcePropertyValueChangeNotificationType2 =
+ ResourcePropertyValueChangeNotificationType.Factory.newInstance( );
+ ResourcePropertyValueChangeNotificationType.OldValue oldValue2 =
+ resourcePropertyValueChangeNotificationType2.addNewOldValue( );
+ oldValue2.newCursor( ).setTextValue( "two" );
+ oldValue1 = (ResourcePropertyValueChangeNotificationType.OldValue) oldValue1.set( oldValue2 );
+ System.out.println( resourcePropertyValueChangeNotificationDocument1 );
+
+ GetResourcePropertyDocument getResourcePropertyDoc1 = GetResourcePropertyDocument.Factory.newInstance( );
+ getResourcePropertyDoc1.setGetResourceProperty( new QName( "one" ) );
+ GetResourcePropertyDocument getResourcePropertyDoc2 = GetResourcePropertyDocument.Factory.newInstance( );
+ getResourcePropertyDoc2.setGetResourceProperty( new QName( "two" ) );
+ getResourcePropertyDoc1 =
+ (GetResourcePropertyDocument) getResourcePropertyDoc1.set( getResourcePropertyDoc2 );
+ System.out.println( getResourcePropertyDoc1 );
+ }
+
+ /**
+ * Test for {@link XmlBeanUtils#setValueAsQName(XmlObject, QName)}.
+ */
+ public void testSetValueAsQName( )
+ {
+ QueryExpressionDocument queryExpressionDocument = QueryExpressionDocument.Factory.newInstance( );
+ QueryExpressionType queryExpressionType = queryExpressionDocument.addNewQueryExpression( );
+ XmlBeanUtils.setValueAsQName( queryExpressionType, SushiPropertyQNames.AKAGI );
+ XmlCursor xCursor = queryExpressionType.newCursor( );
+ String prefix = xCursor.prefixForNamespace( SushiPropertyQNames.AKAGI.getNamespaceURI( ) );
+ String value = xCursor.getTextValue( );
+ assertEquals( prefix + ":" + SushiPropertyQNames.AKAGI.getLocalPart( ), value );
+ }
}