Package de.netseeker.ejoe.test.wsif

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

/*********************************************************************
* WSIFTypeTest.java
* created on 12.10.2006 by netseeker
* $Id: WSIFTypeTest.java,v 1.3 2006/11/05 16:59:52 netseeker Exp $
* $Log: WSIFTypeTest.java,v $
* Revision 1.3  2006/11/05 16:59:52  netseeker
* *** empty log message ***
*
* Revision 1.2  2006/10/12 23:21:27  netseeker
* *** empty log message ***
*
* Revision 1.1  2006/10/12 16:53:27  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 java.math.BigDecimal;

import junit.framework.TestCase;

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;

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

    static EJServer server;

    /*
     * (non-Javadoc)
     *
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        super.setUp();
        if ( server == null || port == null || !server.isRunning() )
        {
            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( WSIFTypeTest.class.getResource( "SimpleTypes.wsdl" )
                        .toString(), null, null, "http://wsifservice.simpletypes/", "SimplePT" );

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

    private Object invokeOperation( WSIFPort port, String name, Object partVal ) throws Exception
    {
        Object result = null;
        WSIFOperation operation = port.createOperation( name );

        WSIFMessage inputMessage = operation.createInputMessage();
        WSIFMessage outputMessage = operation.createOutputMessage();
        WSIFMessage faultMessage = operation.createFaultMessage();
        inputMessage.setObjectPart( "dummy", partVal );

        assertTrue( operation.executeRequestResponseOperation( inputMessage, outputMessage, faultMessage ) );

        result = outputMessage.getObjectPart( "return" );
        assertNotNull( result );

        return result;
    }

    public void testGetString()
    {
        try
        {
            Object o = invokeOperation( port, "getString", "abcd" );
            assertTrue( o instanceof String );
            assertTrue( ((String) o).length() > 0 );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }

    public void testGetBoolean()
    {
        try
        {
            Object o = invokeOperation( port, "getBoolean", new Boolean( true ) );
            assertTrue( o instanceof Boolean );
            assertTrue( ((Boolean) o).booleanValue() );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }

    public void testGetFloat()
    {
        try
        {
            Object o = invokeOperation( port, "getFloat", new Float( 4321 ) );
            assertTrue( o instanceof Float );
            assertEquals( o, new Float( 1234.0 ) );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }

    public void testGetDouble()
    {
        try
        {
            Object o = invokeOperation( port, "getDouble", new Double( 4321 ) );
            assertTrue( o instanceof Double );
            assertEquals( o, new Double( 1234.0 ) );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }

    public void testGetDecimal()
    {
        try
        {
            Object o = invokeOperation( port, "getDecimal", new BigDecimal( 4321 ) );
            assertTrue( o instanceof BigDecimal );
            assertEquals( o, new BigDecimal( 1234.0 ) );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }

    public void testGetInteger()
    {
        try
        {
            Object o = invokeOperation( port, "getInteger", new Integer( 4321 ) );
            assertTrue( o instanceof Integer );
            assertEquals( o, new Integer( 1234 ) );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }

    public void testGetShort()
    {
        try
        {
            Object o = invokeOperation( port, "getShort", new Short( "4321" ) );
            assertTrue( o instanceof Short );
            assertEquals( o, new Short( (short) 1234 ) );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }

    public void testGetByte()
    {
        try
        {
            Object o = invokeOperation( port, "getByte", new Byte( (byte) 10 ) );
            assertTrue( o instanceof Byte );
            assertEquals( o, new Byte( (byte) 11 ) );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }

    public void testGetBase64()
    {
        try
        {
            Object o = invokeOperation( port, "getBase64", new byte[] { (byte) 10 } );
            assertTrue( o instanceof byte[] );
            assertEquals( ((byte[]) o)[0], (byte) 11 );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            fail();
        }
    }
}
TOP

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

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.