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

package org.jboss.ejb3.test.stateful.unit;


import junit.framework.Test;
import org.jboss.test.JBossTestCase;
import org.jboss.ejb3.test.stateful.ExtendedState;
import org.jboss.ejb3.test.stateful.ProxyFactoryInterface;
import org.jboss.ejb3.test.stateful.RemoteBindingInterceptor;
import org.jboss.ejb3.test.stateful.StatefulHome;
import org.jboss.ejb3.test.stateful.Stateful;
import org.jboss.ejb3.test.stateful.Tester;

import javax.naming.InitialContext;

/**
 * Sample client for the jboss container.
 *
 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
 * @version $Id: RemoteUnitTestCase.java,v 1.1.6.4 2005/09/14 22:19:17 bill Exp $
 */

public class RemoteUnitTestCase
extends JBossTestCase
{
   org.apache.log4j.Category log = getLog();

   static boolean deployed = false;
   static int test = 0;

   public RemoteUnitTestCase(String name)
   {

      super(name);

   }

   public void testStatefulSynchronization() throws Exception
   {
      Tester test = (Tester) getInitialContext().lookup(Tester.class.getName());
      test.testSessionSynchronization();

   }
   
   public void testNotSerialableSFSB() throws Exception
   {
      Stateful stateful = (Stateful)getInitialContext().lookup("Stateful");
      assertNotNull(stateful);
      stateful.setState("state");
      String state = stateful.getState();
      assertEquals("state", state);
   }
   
   public void testSFSBInit() throws Exception
   {
      StatefulHome home = (StatefulHome)getInitialContext().lookup("Stateful");
      assertNotNull(home);
      ExtendedState state = new ExtendedState("init");
      Stateful stateful = home.create(state);
      assertNotNull(stateful);
      String s = stateful.getState();
      assertEquals("Extended_init", s);
   }
   
   public void testRemoteBindingProxyFactory() throws Exception
   {
      ProxyFactoryInterface stateful = (ProxyFactoryInterface)getInitialContext().lookup("Stateful");
      assertNotNull(stateful);
   }
   
   public void testRemoteBindingInterceptorStack() throws Exception
   {
      Stateful stateful = (Stateful)getInitialContext().lookup("Stateful");
      assertNotNull(stateful);
      assertFalse(stateful.interceptorAccessed());
      assertTrue(RemoteBindingInterceptor.accessed);
   }

   public static Test suite() throws Exception
   {
      return getDeploySetup(RemoteUnitTestCase.class, "stateful-test.ejb3");
   }

}
