Package de.netseeker.ejoe.test.wsif

Source Code of de.netseeker.ejoe.test.wsif.WSIFTest

/*********************************************************************
* WSIFTest.java
* created on 10.10.2006 by netseeker
* $Id: WSIFTest.java,v 1.4 2006/11/07 00:30:53 netseeker Exp $
* $Log: WSIFTest.java,v $
* Revision 1.4  2006/11/07 00:30:53  netseeker
* *** empty log message ***
*
* Revision 1.3  2006/11/05 16:59:52  netseeker
* *** empty log message ***
*
* Revision 1.2  2006/10/11 22:40:32  netseeker
* *** empty log message ***
*
* Revision 1.1  2006/10/11 13:03:04  netseeker
* *** empty log message ***
*
*
* ====================================================================
*
*  Copyright 2005-2006 netseeker aka Michael Manske
*
*  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.
* ====================================================================
*
* This file is part of the EJOE framework.
* For more information on the author, please see
* <http://www.manskes.de/>.
*
*********************************************************************/
package de.netseeker.ejoe.test.wsif;

import java.io.IOException;

import junit.framework.TestCase;

import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.WSIFPort;
import org.apache.wsif.WSIFService;
import org.apache.wsif.WSIFServiceFactory;
import org.apache.wsif.base.WSIFServiceImpl;

import de.netseeker.ejoe.EJServer;
import de.netseeker.ejoe.ext.wsif.WSIFDynamicProvider_EJOE;
import de.netseeker.ejoe.ext.wsif.wsdl.EJOEExtensionsRegistry;
import de.netseeker.ejoe.handler.DefaultRemotingHandler;
import de.netseeker.ejoe.test.client.stub.addressbook.wsiftypes.Address;
import de.netseeker.ejoe.test.client.stub.addressbook.wsiftypes.Phone;

/**
* @author netseeker
* @since 0.3.9.1
*/
public class WSIFTest extends TestCase
{
    WSIFPort port;

    EJServer server;

    /*
     * (non-Javadoc)
     *
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        super.setUp();
        server = new EJServer( new DefaultRemotingHandler() );
        server.enablePersistentConnections( true );

        try
        {
            server.start();
        }
        catch ( IOException e )
        {
            e.printStackTrace();
            fail( e.toString() );
        }

        // create a service factory
        WSIFServiceFactory factory = WSIFServiceFactory.newInstance();

        WSIFServiceImpl
                .setDynamicWSIFProvider( "http://schemas.xmlsoap.org/wsdl/ejoe/", new WSIFDynamicProvider_EJOE() );
        WSIFServiceImpl.addExtensionRegistry( new EJOEExtensionsRegistry() );

        try
        {
            WSIFService service = factory.getService( WSIFTest.class.getResource( "AddressBook.wsdl" ).toString(),
                                                      null, null, "http://wsifservice.addressbook/", "AddressBook" );

            // get the port
            port = service.getPort();
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail( e.toString() );
        }
    }

    public void testAddAddress()
    {
        try
        {
            // create the operation
            // note that we have two operations with the same name, so we need
            // to specify the
            // name of the input and output messages as well
            WSIFOperation operation = port.createOperation( "addEntry", "AddEntryFirstAndLastNamesRequest", null );

            assertNotNull( operation );

            // create the input message associated with this operation
            WSIFMessage input = operation.createInputMessage();

            // populate the input message
            input.setObjectPart( "firstName", "John" );
            input.setObjectPart( "lastName", "Smith" );

            // create an address object to populate the input
            Address address = new Address();
            address.setStreetNum( 20 );
            address.setStreetName( "Peachtree Avenue" );
            address.setCity( "Atlanta" );
            address.setState( "GA" );
            address.setZip( 39892 );
            Phone phone = new Phone();
            phone.setAreaCode( 701 );
            phone.setExchange( "555" );
            phone.setNumber( "8721" );
            address.setPhoneNumber( phone );

            input.setObjectPart( "address", address );

            // do the invocation
            System.out.println( "Adding address for John Smith..." );
            operation.executeInputOnlyOperation( input );

        }
        catch ( WSIFException we )
        {
            System.out.println( "Got exception from WSIF, details:" );
            we.printStackTrace();
            fail( we.toString() );
        }
    }

    public void testQueryAddresses()
    {
        try
        {
            // create the operation
            WSIFOperation operation = port.createOperation( "getAddressFromName" );

            assertNotNull( operation );

            // create the input message associated with this operation
            WSIFMessage input = operation.createInputMessage();
            WSIFMessage output = operation.createOutputMessage();
            WSIFMessage fault = operation.createFaultMessage();

            // populate the input message
            input.setObjectPart( "name", "John Smith" );

            // do the invocation
            System.out.println( "Querying address for John Smith..." );
            if ( operation.executeRequestResponseOperation( input, output, fault ) )
            {
                // invocation succeeded
                // extract the address from the output message
                Address address = (Address) output.getObjectPart( "address" );
                assertNotNull( address );
                System.out.println( "Service returned the following address:" );
                System.out.println( address.getStreetNum() + " " + address.getStreetName() + ", " + address.getCity()
                        + " " + address.getState() + " " + address.getZip() + "; Phone: ("
                        + address.getPhoneNumber().getAreaCode() + ") " + address.getPhoneNumber().getExchange() + "-"
                        + address.getPhoneNumber().getNumber() );
            }
            else
            {
                fail( "invocation failed, check fault message" );
            }
        }
        catch ( WSIFException we )
        {
            System.out.println( "Got exception from WSIF, details:" );
            we.printStackTrace();
            fail( we.toString() );
        }
    }
}
TOP

Related Classes of de.netseeker.ejoe.test.wsif.WSIFTest

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.