/*
 * Copyright 1999 by dreamBean Software,
 * All rights reserved.
 */
package org.jboss.ejb3.test.dd.override.unit;

import javax.naming.*;

import org.jboss.ejb3.test.dd.override.Foo;
import org.jboss.ejb3.test.dd.override.LocalFoo;
import org.jboss.logging.Logger;

import junit.framework.Test;

import org.jboss.security.SecurityAssociation;
import org.jboss.security.SimplePrincipal;
import org.jboss.test.JBossTestCase;

/**
 * Test for EJB3 deployment of EJB2.0 Bank EJBs
 * 
 * @version <tt>$Revision: 1.3.2.3 $</tt>
 * @author <a href="mailto:bdecoste@jboss.com">William DeCoste</a>
 */
public class OverrideTestCase
    extends JBossTestCase {

   private static final Logger log = Logger
         .getLogger(OverrideTestCase.class);

   public OverrideTestCase(String name)
   {
      super(name);
   }
/*   
   public void testTxOverride() throws Exception
   {
      InitialContext jndiContext = new InitialContext();
      
      Foo foo = (Foo) jndiContext.lookup("Foo");
      assertNotNull(foo);
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("rolefail"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      assertFalse(foo.transactionExisted());
      
      try {
         foo.bar();
         assertTrue(false);
      } catch (Exception e){
         assertTrue(e instanceof SecurityException);
      }
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      foo.bar();
      assertFalse(foo.transactionExisted());
   }
 
   public void testRemoteOverride() throws Exception
   {
      try {
      InitialContext jndiContext = new InitialContext();
      
      LocalFoo foo = (LocalFoo) jndiContext.lookup("LocalFoo");
      assertNotNull(foo);
      
      foo.bar();
      } catch (Exception e){
         e.printStackTrace();
         throw e;
      }
   } */
   
   public void testNaming()
   {
      lookup("");
   }
   
   private void lookup(String name)
   {
      log.info("lookup " + name);
      try {
         InitialContext jndiContext = new InitialContext();
         NamingEnumeration names = jndiContext.list(name);
         if (names != null){
            while (names.hasMore()){
               log.info("  " + names.next());
            }
         }
      } catch (Exception e){
      }
   }
   
   public static Test suite() throws Exception
   {
      return getDeploySetup(OverrideTestCase.class, "dd-override1B.ejb3");
   }

}
