1 22 package org.jboss.ejb3.test.standalone.unit; 23 24 import junit.extensions.TestSetup; 25 import junit.framework.Test; 26 import junit.framework.TestCase; 27 import junit.framework.TestSuite; 28 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap; 29 import org.jboss.ejb3.test.standalone.CalculatorBean; 30 import org.jboss.ejb3.test.standalone.CalculatorRemote; 31 import org.jboss.ejb3.test.standalone.Customer; 32 import org.jboss.ejb3.test.standalone.CustomerDAO; 33 import org.jboss.ejb3.test.standalone.ShoppingCart; 34 import org.jboss.ejb3.test.standalone.StupidInterceptor; 35 36 import javax.ejb.NoSuchEJBException ; 37 import javax.naming.InitialContext ; 38 import javax.naming.NamingException ; 39 import java.util.Hashtable ; 40 41 47 public class JavaClassPathTestCase extends TestCase 48 { 49 public JavaClassPathTestCase(String name) 50 { 51 super(name); 52 } 53 54 public static Test suite() throws Exception 55 { 56 TestSuite suite = new TestSuite(); 57 suite.addTestSuite(JavaClassPathTestCase.class); 58 59 TestSetup wrapper = new TestSetup(suite) 61 { 62 protected void setUp() 63 { 64 startupEmbeddedJboss(); 65 } 66 67 protected void tearDown() 68 { 69 shutdownEmbeddedJboss(); 70 } 71 }; 72 73 return wrapper; 74 } 75 76 public static void startupEmbeddedJboss() 77 { 78 EJB3StandaloneBootstrap.boot(null); 79 EJB3StandaloneBootstrap.scanClasspath("standalone.jar"); 80 } 81 82 public static void shutdownEmbeddedJboss() 83 { 84 EJB3StandaloneBootstrap.shutdown(); 85 } 86 87 protected InitialContext getInitialContext() throws Exception 88 { 89 return new InitialContext (getInitialContextProperties()); 90 } 91 92 protected Hashtable getInitialContextProperties() 93 { 94 return EJB3StandaloneBootstrap.getInitialContextProperties(); 95 } 96 97 98 public void testJavaClassPath() throws Throwable 99 { 100 InitialContext ctx = getInitialContext(); 101 102 executeEJBs(ctx); 103 } 104 105 private void executeEJBs(InitialContext ctx) 106 throws NamingException 107 { 108 CustomerDAO local = (CustomerDAO) ctx.lookup("CustomerDAOBean/local"); 109 long id = local.createCustomer(); 110 Customer cust = local.findCustomer(id); 111 assertEquals("Bill", cust.getName()); 112 113 ShoppingCart cart = (ShoppingCart) ctx.lookup("ShoppingCartBean/local"); 114 cart.getCart().add("beer"); 115 cart.getCart().add("wine"); 116 assertEquals(2, cart.getCart().size()); 117 118 cart.checkout(); 119 120 boolean exceptionThrown = false; 121 try 122 { 123 cart.getCart(); 124 } 125 catch (NoSuchEJBException e) 126 { 127 exceptionThrown = true; 128 } 129 130 assertTrue(exceptionThrown); 131 132 CalculatorRemote calc = (CalculatorRemote) ctx.lookup("CalculatorBean/remote"); 133 StupidInterceptor.count = 0; 134 CalculatorBean.test = true; 135 try 136 { 137 assertEquals(2, calc.add(1, 1)); 138 assertEquals(1, StupidInterceptor.count); 139 StupidInterceptor.count = 0; 140 CalculatorBean.test = true; 141 assertEquals(0, calc.sub(1, 1)); 142 assertEquals(1, StupidInterceptor.count); 143 } 144 finally 145 { 146 CalculatorBean.test = false; 147 } 148 } 149 150 protected void configureLoggingAfterBootstrap() 151 { 152 } 154 } | Popular Tags |