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

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

//import java.rmi.*;


import javax.naming.InitialContext;
import javax.naming.NamingException;

import junit.framework.Test;

import org.jboss.ejb3.test.ssladvanced.BusinessInterface;
import org.jboss.test.JBossTestCase;

/**
 * Sample client for the jboss container.
 *
 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
 * @version $Id$
 */

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


   public SSLUnitTestCase(String name)
   {
      super(name);
   }

   public void testNoDefaultBinding() throws Exception
   {
      System.out.println("*** TEST No default binding");
      InitialContext ctx = new InitialContext();
      try
      {
         BusinessInterface bi = (BusinessInterface)ctx.lookup(BusinessInterface.class.getName());
         throw new Exception("Nothing should be bound to the default name");
      }
      catch(NamingException e)
      {
         
      }
      System.out.println("*** success");
   }

   public void testSSLBindings() throws Exception
   {
      System.out.println("*** TEST SSL Bindings");
      InitialContext ctx = new InitialContext();
      BusinessInterface sf = (BusinessInterface)ctx.lookup("StatefulSSL");
      assertEquals(sf.echo("123"), "*** 123 ***");
      
      BusinessInterface sfc = (BusinessInterface)ctx.lookup("StatefulClusteredSSL");
      assertEquals(sfc.echo("123"), "*** 123 ***");
      
      BusinessInterface sl = (BusinessInterface)ctx.lookup("StatelessSSL");
      assertEquals(sl.echo("123"), "*** 123 ***");

      BusinessInterface slc = (BusinessInterface)ctx.lookup("StatelessClusteredSSL");
      assertEquals(slc.echo("123"), "*** 123 ***");
      System.out.println("*** success");
   }
   
   public void testNormalBindings() throws Exception
   {
      System.out.println("*** TEST Normal Bindings");
      InitialContext ctx = new InitialContext();
      BusinessInterface sf = (BusinessInterface)ctx.lookup("StatefulNormal");
      assertEquals(sf.echo("123"), "*** 123 ***");
      
      BusinessInterface sfc = (BusinessInterface)ctx.lookup("StatefulClusteredNormal");
      assertEquals(sfc.echo("123"), "*** 123 ***");
      
      BusinessInterface sl = (BusinessInterface)ctx.lookup("StatelessNormal");
      assertEquals(sl.echo("123"), "*** 123 ***");

      BusinessInterface slc = (BusinessInterface)ctx.lookup("StatelessClusteredNormal");
      assertEquals(slc.echo("123"), "*** 123 ***");

      System.out.println("*** success");
   }
   

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


}
