Package org.apache.ws.resource.properties.v2004_06.porttype.impl

Source Code of org.apache.ws.resource.properties.v2004_06.porttype.impl.QueryResourcePropertiesProviderTestCase

/*=============================================================================*
*  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.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}.
* 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 XmlException
    {
        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 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;
    }
}
TOP

Related Classes of org.apache.ws.resource.properties.v2004_06.porttype.impl.QueryResourcePropertiesProviderTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.