/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

// $Id: StateUnitTestCase.java,v 1.1.1.1.4.1 2004/08/09 09:54:40 tdiesler Exp $

package org.jboss.test.jbossnet.state;

import org.jboss.test.jbossnet.WSTests;

import junit.framework.Test;

/**
 * Tests remote accessibility of stateful ejb bean
 * @since 2. Oktober 2002, 12:11
 * @author <a href="mailto:Christoph.Jung@infor.de">Christoph G. Jung</a>
 * @version $Revision: 1.1.1.1.4.1 $
 */

public class StateUnitTestCase extends WSTests
{

   protected String STATE_SOAP_ACTION = "State";
   protected String NOSTATE_SOAP_ACTION = "NoState";
   protected String FULLSTATE_SOAP_ACTION = "FullState";

   // Constructors --------------------------------------------------
   public StateUnitTestCase(String name)
   {
      super(name);
   }

   /** the session bean with which we interact */
   State state;
   NoState noState;
   FullState fullState;

   /** setup the bean */
   public void setUp() throws Exception
   {
      super.setUp();
      state = (State) createAxisService(State.class, STATE_SOAP_ACTION);
      noState = (NoState) createAxisService(NoState.class, NOSTATE_SOAP_ACTION);
      fullState =
         (FullState) createAxisService(FullState.class, FULLSTATE_SOAP_ACTION);
   }

   /** test stateful behaviour*/
   public void testState() throws Exception
   {
      assertEquals("Initial return value must be zero.", state.count(), 0);
      assertEquals("Next return value must be incremented.", state.count(), 1);
      assertEquals("Next return value must be incremented.", state.count(), 2);
      setUp();
      assertEquals("Fresh return value must be zero.", state.count(), 0);
      assertEquals(
         "Fresh next return value must be incremented.",
         state.count(),
         1);
      assertEquals(
         "Fresh next return value must be incremented.",
         state.count(),
         2);
   }

   /** test stateless behaviour */
   public void testNoState() throws Exception
   {
      assertEquals("Initial return value must be zero.", noState.count(), 0);
      assertEquals(
         "Next return value must not be incremented.",
         noState.count(),
         0);
      assertEquals(
         "Next return value must not be incremented.",
         noState.count(),
         0);
   }

   /** test stateful behaviour*/
   public void testFullState() throws Exception
   {
      assertEquals("Initial return value must be zero.", fullState.count(), 0);
      assertEquals(
         "Next return value must be incremented.",
         fullState.count(),
         1);
      assertEquals(
         "Next return value must be incremented.",
         fullState.count(),
         2);
      setUp();
      assertEquals(
         "Fresh return value must be incremented.",
         fullState.count(),
         3);
      assertEquals(
         "Fresh next return value must be incremented.",
         fullState.count(),
         4);
      assertEquals(
         "Fresh next return value must be incremented.",
         fullState.count(),
         5);
   }

   /** this is to deploy the whole ear */
   public static Test suite() throws Exception
   {
      return getDeploySetup(StateUnitTestCase.class, "wsstate.ear");
   }

   public static void main(String[] args)
   {
      junit.textui.TestRunner.run(StateUnitTestCase.class);
   }

}