Package de.netseeker.ejoe.test.crispy

Source Code of de.netseeker.ejoe.test.crispy.EJCrispyTest

package de.netseeker.ejoe.test.crispy;

import java.math.BigDecimal;
import java.util.Properties;

import junit.framework.TestCase;
import net.sf.crispy.Property;
import net.sf.crispy.impl.ServiceManager;
import net.sf.crispy.interceptor.LogInterceptor;
import test.crispy.compatibility.CompatibilityKit;
import test.crispy.example.service.Calculator;
import test.crispy.example.service.CalculatorImpl;
import test.crispy.example.service.Echo;
import test.crispy.example.service.EchoImpl;
import de.netseeker.ejoe.adapter.XStreamAdapter;
import de.netseeker.ejoe.ext.crispy.EJExecutor;
import de.netseeker.ejoe.test.service.ISimpleTypes;
import de.netseeker.ejoe.test.service.SimpleTypes;

public class EJCrispyTest extends TestCase
{
    private static ServiceManager manager;

    private static ISimpleTypes   stService;

    private static EJMiniServer   server;

    /*
     * (non-Javadoc)
     *
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        super.setUp();
        if ( manager == null )
        {
            server = new EJMiniServer();
            server.addService( ISimpleTypes.class.getName(), SimpleTypes.class.getName() );
            server.addService( Echo.class.getName(), EchoImpl.class.getName() );
            server.addService( Calculator.class.getName(), CalculatorImpl.class.getName() );
            server.start();
            Properties prop = new Properties();
            prop.put( Property.EXECUTOR_CLASS, EJExecutor.class.getName() );
            prop.put( EJExecutor.EJOE_SERIALIZATION_ADAPTER, XStreamAdapter.class.getName() );
            prop.put( EJExecutor.EJOE_USE_PERSISTENT_CONNECTION, Boolean.toString( true ) );
            manager = new ServiceManager( prop );
            stService = (ISimpleTypes) manager.createService( ISimpleTypes.class );
        }
    }

    public void testCrispyCompatibility()
    {
        // net.sf.crispy.util.Util.initJdkLogger();
        CompatibilityKit compatibilityKit = new CompatibilityKit();
        compatibilityKit.addProperty( Property.DEBUG_MODE_ON, Boolean.toString( true ) );
        compatibilityKit.addProperty( Property.INTERCEPTOR_CLASS, LogInterceptor.class.getName() );
        compatibilityKit.addProperty( Property.EXECUTOR_CLASS, EJExecutor.class.getName() );
        compatibilityKit.addProperty( EJExecutor.EJOE_SERIALIZATION_ADAPTER, XStreamAdapter.class.getName() );
        compatibilityKit.addProperty( EJExecutor.EJOE_USE_PERSISTENT_CONNECTION, Boolean.toString( true ) );
        // compatibilityKit.makeAllTests("EJOE", server);
        compatibilityKit.makeCalculatorTest( manager );
        compatibilityKit.makeComplexEchoTest( manager );
        compatibilityKit.makeCreateService( manager );
        compatibilityKit.makeModifyServiceTest( manager );
        compatibilityKit.makeCycleDetectionTest( manager );
        compatibilityKit.makeMultipleServiceTest();
        // compatibilityKit.makeMultiProxyInterceptorTest();
        compatibilityKit.makeOverloadingTest( manager );
        // compatibilityKit.makeSimpleEchoTest(manager);
        // compatibilityKit.makeSimpleProxyInterceptorTest();
        compatibilityKit.makeThrowException( manager );
    }

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

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

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

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

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

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

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

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

    public void testGetBase64()
    {
        try
        {
            Object o = stService.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.crispy.EJCrispyTest

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.