1 22 package org.jboss.ejb3.test.standalone.unit; 23 24 import java.util.Hashtable ; 25 import javax.ejb.NoSuchEJBException ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NamingException ; 28 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap; 29 import org.jboss.ejb3.test.standalone.CalculatorRemote; 30 import org.jboss.ejb3.test.standalone.Customer; 31 import org.jboss.ejb3.test.standalone.CustomerDAO; 32 import org.jboss.ejb3.test.standalone.ShoppingCart; 33 import junit.framework.TestCase; 34 35 41 public class XmlDeployerTestCase extends TestCase 42 { 43 private static boolean booted = false; 44 45 public XmlDeployerTestCase(String name) 46 { 47 super(name); 48 } 49 50 protected void setUp() throws Exception 51 { 52 56 super.setUp(); 57 long start = System.currentTimeMillis(); 58 try 59 { 60 if (!booted) 61 { 62 booted = true; 63 EJB3StandaloneBootstrap.boot(""); 64 } 65 } 66 catch (Exception e) 67 { 68 throw e; 69 } 70 catch (Throwable t) 71 { 72 throw new RuntimeException (t); 73 } 74 } 75 76 @Override 77 protected void tearDown() throws Exception 78 { 79 super.tearDown(); 80 EJB3StandaloneBootstrap.shutdown(); 81 } 82 83 protected InitialContext getInitialContext() throws Exception 84 { 85 return new InitialContext (getInitialContextProperties()); 86 } 87 88 protected Hashtable getInitialContextProperties() 89 { 90 return EJB3StandaloneBootstrap.getInitialContextProperties(); 91 } 92 93 94 public void testXmlDeployer() throws Throwable 95 { 96 InitialContext ctx = getInitialContext(); 97 EJB3StandaloneBootstrap.deployXmlResource("deployer.xml"); 98 99 executeEJBs(ctx); 100 101 EJB3StandaloneBootstrap.getKernel().getController().uninstall("EJBDeployment"); 102 } 103 104 public void testCleanup() throws Throwable 105 { 106 boolean exceptionThrown = false; 107 try 108 { 109 executeEJBs(getInitialContext()); 110 } 111 catch (Exception e) 112 { 113 exceptionThrown = true; 114 } 115 assertTrue(exceptionThrown); 116 117 } 118 119 private void executeEJBs(InitialContext ctx) 120 throws NamingException 121 { 122 CustomerDAO local = (CustomerDAO)ctx.lookup("CustomerDAOBean/local"); 123 long id = local.createCustomer(); 124 Customer cust = local.findCustomer(id); 125 assertEquals("Bill", cust.getName()); 126 127 ShoppingCart cart = (ShoppingCart)ctx.lookup("ShoppingCartBean/local"); 128 cart.getCart().add("beer"); 129 cart.getCart().add("wine"); 130 assertEquals(2, cart.getCart().size()); 131 132 cart.checkout(); 133 134 boolean exceptionThrown = false; 135 try 136 { 137 cart.getCart(); 138 } 139 catch (NoSuchEJBException e) 140 { 141 exceptionThrown = true; 142 } 143 144 assertTrue(exceptionThrown); 145 146 CalculatorRemote calc = (CalculatorRemote)ctx.lookup("CalculatorBean/remote"); 147 assertEquals(2, calc.add(1, 1)); 148 } 149 150 protected void configureLoggingAfterBootstrap() 151 { 152 } 154 } | Popular Tags |