/*=============================================================================*
* 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.impl;
import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.ws.resource.properties.AbstractResourcePropertiesTestCase;
import org.apache.ws.resource.properties.ResourceProperty;
import org.apache.ws.resource.properties.ResourcePropertyMetaData;
import org.apache.ws.resource.properties.SushiPropertyQNames;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlInt;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlString;
/**
* Test case for {@link XmlBeansResourceProperty}.
*
* @author Ian P. Springer
*/
public class XmlBeansResourcePropertyTestCase
extends AbstractResourcePropertiesTestCase
{
/**
* @throws Exception
*/
public void setUp()
throws Exception
{
initResourcePropsDoc();
}
/**
* DOCUMENT_ME
*
* @param args DOCUMENT_ME
*/
public static void main( String[] args )
{
TestResult result = TestRunner.run( XmlBeansResourcePropertyTestCase.suite() );
if ( !result.wasSuccessful() )
{
System.exit( 1 );
}
}
/**
* DOCUMENT_ME
*
* @return DOCUMENT_ME
*/
public static Test suite()
{
return new TestSuite( XmlBeansResourcePropertyTestCase.class );
}
/**
* Test for XmlBeansResourceProperty#add.
*/
public void testAdd()
throws Exception
{
ResourceProperty prop = m_resourcePropSet.get( SushiPropertyQNames.IKA );
final String stringValue = "somethang";
prop.add( XmlObject.Factory.parse( "<" + SushiPropertyQNames.IKA.getLocalPart() + " xmlns=\"" + SushiPropertyQNames.IKA.getNamespaceURI() + "\">" + stringValue + "</" + SushiPropertyQNames.IKA.getLocalPart() + ">" ) );
assertEquals( 2,
prop.size() );
XmlString xString = (XmlString) prop.get( 1 );
assertEquals( stringValue,
xString.getStringValue() );
}
/**
* Test for XmlBeansResourceProperty#clear.
*/
public void testClear()
throws Exception
{
ResourceProperty manufacturerProp = m_resourcePropSet.get( SushiPropertyQNames.IKA );
manufacturerProp.clear();
assertTrue( manufacturerProp.isEmpty() );
}
/**
* Test for XmlBeansResourceProperty#get.
*/
public void testGet()
throws Exception
{
ResourceProperty manufacturerProp = m_resourcePropSet.get( SushiPropertyQNames.AKAGI );
Object propObj = manufacturerProp.get( 0 );
assertTrue( propObj instanceof XmlInt );
XmlInt xInt = (XmlInt) propObj;
assertEquals( "24",
xInt.getStringValue() );
}
/**
* Test for XmlBeansResourceProperty#getMetaData.
*/
public void testGetMetaData()
throws Exception
{
ResourceProperty blockSize = m_resourcePropSet.get( SushiPropertyQNames.EBI );
ResourcePropertyMetaData metaData = blockSize.getMetaData();
assertNotNull( metaData );
assertEquals( SushiPropertyQNames.EBI,
metaData.getName() );
assertEquals( 1,
metaData.getMinOccurs() );
assertEquals( -1,
metaData.getMaxOccurs() );
assertFalse( metaData.isNillable() );
assertFalse( metaData.isReadOnly() );
// TODO: add some more cases to test props that are nillable and/or read-only
}
/**
* Test for XmlBeansResourceProperty#isEmpty.
*/
public void testIsEmpty()
throws Exception
{
ResourceProperty prop = m_resourcePropSet.get( SushiPropertyQNames.IKA );
assertFalse( prop.isEmpty() );
prop.clear();
assertTrue( prop.isEmpty() );
assertEquals( 0,
prop.size() );
}
/**
* Test for XmlBeansResourceProperty#remove.
*/
public void testRemoveExistingElement()
throws Exception
{
ResourceProperty prop = m_resourcePropSet.get( SushiPropertyQNames.HAMACHI );
prop.remove( prop.get( 0 ) );
assertTrue( prop.isEmpty() );
assertEquals( 0, XmlBeanUtils.getChildElements( m_resourcePropSet.toXmlObject(), SushiPropertyQNames.HAMACHI ).length );
}
/**
* Another test for XmlBeansResourceProperty#remove.
*/
public void testRemoveAddedElement()
throws Exception
{
ResourceProperty prop = m_resourcePropSet.get( SushiPropertyQNames.HAMACHI );
prop.clear();
XmlObject hamachiDoc = XmlObject.Factory.parse( "<Hamachi xmlns=\"http://ws.apache.org/resource/properties/test/sushi\">\n" +
" <Flavor>disgusting</Flavor>\n" +
"</Hamachi>" );
prop.add( hamachiDoc );
assertEquals( 1, prop.size() );
assertEquals( 1, XmlBeanUtils.getChildElements( m_resourcePropSet.toXmlObject(), SushiPropertyQNames.HAMACHI ).length );
prop.remove( prop.get( 0 ) );
assertTrue( prop.isEmpty() );
assertEquals( 0, XmlBeanUtils.getChildElements( m_resourcePropSet.toXmlObject(), SushiPropertyQNames.HAMACHI ).length );
}
/**
* Test for XmlBeansResourceProperty#set.
*/
public void testSet()
throws Exception
{
ResourceProperty prop = m_resourcePropSet.get( SushiPropertyQNames.IKA );
final String stringValue = "somethang";
prop.set( 0,
XmlObject.Factory.parse( "<" + SushiPropertyQNames.IKA.getLocalPart() + " xmlns=\"" + SushiPropertyQNames.IKA.getNamespaceURI() + "\">" + stringValue + "</" + SushiPropertyQNames.IKA.getLocalPart() + ">" ) );
XmlString xString = (XmlString) prop.get( 0 );
assertEquals( stringValue,
xString.getStringValue() );
}
/**
* Test for XmlBeansResourceProperty#size.
*/
public void testSize()
throws Exception
{
ResourceProperty prop = m_resourcePropSet.get( SushiPropertyQNames.IKA );
assertEquals( 1,
prop.size() );
final String stringValue = "somethang";
prop.add( XmlObject.Factory.parse( "<" + SushiPropertyQNames.IKA.getLocalPart() + " xmlns=\"" + SushiPropertyQNames.IKA.getNamespaceURI() + "\">" + stringValue + "</" + SushiPropertyQNames.IKA.getLocalPart() + ">" ) );
prop.add( XmlObject.Factory.parse( "<" + SushiPropertyQNames.IKA.getLocalPart() + " xmlns=\"" + SushiPropertyQNames.IKA.getNamespaceURI() + "\">" + stringValue + "</" + SushiPropertyQNames.IKA.getLocalPart() + ">" ) );
assertEquals( 3,
prop.size() );
prop.remove( prop.get( 0 ) );
prop.remove( prop.get( 0 ) );
assertEquals( 1,
prop.size() );
}
/**
* Test for XmlBeansResourceProperty#toElements.
*/
public void testToElement()
throws Exception
{
//TODO: Test goes here...
}
/**
* Test for XmlBeansResourceProperty#toSOAPElements.
*/
public void testToSOAPElement()
throws Exception
{
//TODO: Test goes here...
}
}