FileDocCategorySizeDatePackage
BankDeploymentDescriptorTestCase.javaAPI DocJBoss 4.2.112344Fri Jul 13 20:53:26 BST 2007org.jboss.ejb3.test.bank.unit

BankDeploymentDescriptorTestCase

public class BankDeploymentDescriptorTestCase extends org.jboss.test.JBossTestCase
Test for EJB3 deployment of EJB2.0 Bank EJBs
version
$Revision: 60233 $
author
William DeCoste

Fields Summary
private static final Logger
log
Constructors Summary
public BankDeploymentDescriptorTestCase(String name)


     
   
      super(name);
   
Methods Summary
public static junit.framework.Testsuite()

      ClientKernelAbstraction kernel = KernelAbstractionFactory.getClientInstance();
      ObjectName propertiesServiceON = new ObjectName("jboss:type=Service,name=SystemProperties");
      kernel.invoke(
            propertiesServiceON,
            "set",
            new Object[]{"test.datasource.jndi","java:/DefaultDS"},
            new String[]{"java.lang.String", "java.lang.String"}
      );
      
      kernel.invoke(
            propertiesServiceON,
            "set",
            new Object[]{"test.transactionmanager.jndi","java:/TransactionManager"},
            new String[]{"java.lang.String", "java.lang.String"}
      );
      
      return getDeploySetup(BankDeploymentDescriptorTestCase.class, "bank.jar");
   
public voidtestCallbackListenersAndInteceptors()

      InitialContext jndiContext = new InitialContext();
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
      status.clear();
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      String id = bank.interceptCustomerId("CustomerId");
      assertEquals("CustomerId_SecondInterceptor_FirstInterceptor", id);
      assertTrue(status.postConstruct());
   
public voidtestEnvEntry()

      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      InitialContext jndiContext = new InitialContext();
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      String id = bank.getEnvEntryId();
      assertEquals(id, "5678");
   
public voidtestFieldInject()

      InitialContext jndiContext = new InitialContext();
 
      Teller teller = (Teller) jndiContext.lookup(Teller.JNDI_NAME);
      assertNotNull(teller);
      
      String greeting = teller.greetWithServiceTimer("Hello");
      assertEquals("Hello", greeting);
   
public voidtestInit()

      InitialContext jndiContext = new InitialContext();
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      String initialized = bank.isInitialized();
      assertEquals("YESYES", initialized);
   
public voidtestInjectionAnnotations()

      InitialContext jndiContext = new InitialContext();
      Teller teller = (Teller) jndiContext.lookup(Teller.JNDI_NAME);
      assertNotNull(teller);
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("customer"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      String greeting = teller.greetChecked("Hello");
      assertNotNull(greeting);
      assertEquals("Hello", greeting);
      assertTrue(teller.isConstructed());

   
public voidtestRemoteBindingInterceptorStack()

      Teller teller = (Teller)getInitialContext().lookup(Teller.JNDI_NAME);
      assertNotNull(teller);
      assertTrue(TellerInterceptor.accessed);
   
public voidtestRemoteBindingProxyFactory()

      ProxyFactoryInterface teller = (ProxyFactoryInterface)getInitialContext().lookup(Teller.JNDI_NAME);
      assertNotNull(teller);
   
public voidtestRemove()

      InitialContext jndiContext = new InitialContext();
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      bank.remove();
      
      try {
         bank.testResource();
         assertTrue(false);
      }
      catch (NoSuchEJBException e)
      {
         // correct exception
      }
   
public voidtestResource()

      InitialContext jndiContext = new InitialContext();
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      bank.testResource();
   
public voidtestRunAs()

      InitialContext jndiContext = new InitialContext();
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("rolefail"));
      SecurityAssociation.setCredential("password".toCharArray());
 
      String customerId = "CustomerId";
      String greeting;
      Teller teller = (Teller) jndiContext.lookup(Teller.JNDI_NAME);
      assertNotNull(teller);
      
      String tmpId = teller.retrieveCustomerId();
      assertEquals("defaultId", tmpId);
   
public voidtestStatefulBank()

      InitialContext jndiContext = new InitialContext();
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      String customerId = "CustomerId";
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("customer"));
      SecurityAssociation.setCredential("password".toCharArray());
      try {
         bank.storeCustomerId(customerId);
         assertTrue(false);
      } catch (Exception e){
         assertTrue(e instanceof EJBAccessException);
      }
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      bank.storeCustomerId(customerId);
      String tmpId = bank.retrieveCustomerId();
      assertEquals(customerId, tmpId);
   
public voidtestStatefulBank21()

      InitialContext jndiContext = new InitialContext();
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME + "21");
      assertNotNull(bank);
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      String activated = bank.isActivated();
      assertEquals(activated, "_CREATED");
   
public voidtestStatefulState()

      InitialContext jndiContext = new InitialContext();
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      String customerId = "CustomerId";
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      bank.storeCustomerId(customerId);
      String tmpId = bank.retrieveCustomerId();
      assertEquals(customerId, tmpId);
      
      bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      tmpId = bank.retrieveCustomerId();
      assertEquals("defaultId", tmpId);
   
public voidtestStatefulTransactionTimeout()

      InitialContext jndiContext = new InitialContext();
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("teller"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME);
      assertNotNull(bank);
      
      try{
         bank.testTransactionTimeout();
         String state = bank.getTransactionState();
         assertEquals("failed", state);
      } catch (Exception e){
      }
   
public voidtestStatelessTeller()

      InitialContext jndiContext = new InitialContext();
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("rolefail"));
      SecurityAssociation.setCredential("password".toCharArray());
 
      String greeting;
      Teller teller = (Teller) jndiContext.lookup(Teller.JNDI_NAME);
      assertNotNull(teller);
      
      greeting = teller.greetWithRequiredTransaction("Hello");
      assertNotNull(greeting);
      assertEquals("Hello", greeting);
      greeting = teller.greetWithNotSupportedTransaction("Hello");
      assertNotNull(greeting);
      assertEquals("Hello", greeting);
      greeting = teller.greetUnchecked("Hello");
      assertNotNull(greeting);
      assertEquals("Hello", greeting);
      
      try {
         greeting = teller.greetChecked("Hello");
         assertTrue(false);
      } catch (Exception e){
         assertTrue(e instanceof EJBAccessException);
      }
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("customer"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      try{
         greeting = teller.greetChecked("Hello");
         assertNotNull(greeting);
         assertEquals("Hello", greeting);
      } catch (Exception e){
         e.printStackTrace();
      }
   
public voidtestTeller()

      InitialContext jndiContext = new InitialContext();
      Teller teller = (Teller) jndiContext.lookup(Teller.JNDI_NAME);
      assertNotNull(teller);
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("customer"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      try {
         teller.excludedMethod();
         assertTrue(false);
      } catch (Exception e){
         assertTrue(e instanceof EJBAccessException);
      }
   
public voidtestTransactionTimeout()

      InitialContext jndiContext = new InitialContext();
      
      SecurityAssociation.setPrincipal(new SimplePrincipal("customer"));
      SecurityAssociation.setCredential("password".toCharArray());
      
      Teller teller = (Teller) jndiContext.lookup(Teller.JNDI_NAME);
      assertNotNull(teller);

      boolean exceptionThrown = false;
      try
      {
         teller.testTransactionTimeout();
      }
      catch (Exception e)
      {
         exceptionThrown = true;
      }
      assertTrue(exceptionThrown);