1 22 package org.jboss.ejb3.test.standalone.unit; 23 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.net.URL ; 27 import java.util.Hashtable ; 28 import java.util.Properties ; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap; 32 import org.jboss.ejb3.embedded.EJB3StandaloneDeployer; 33 import org.jboss.ejb3.test.standalone.DependsRemote; 34 import junit.framework.TestCase; 35 import junit.framework.Test; 36 import junit.framework.TestSuite; 37 import junit.extensions.TestSetup; 38 39 43 public class DependencyTestCase extends TestCase 44 { 45 private static boolean booted = false; 46 47 public DependencyTestCase(String name) 48 { 49 super(name); 50 } 51 52 public static Test suite() throws Exception 53 { 54 TestSuite suite = new TestSuite(); 55 suite.addTestSuite(DeployerTestCase.class); 56 57 58 TestSetup wrapper = new TestSetup(suite) 60 { 61 protected void setUp() 62 { 63 startupEmbeddedJboss(); 64 } 65 66 protected void tearDown() 67 { 68 shutdownEmbeddedJboss(); 69 } 70 }; 71 72 return wrapper; 73 } 74 75 public static void startupEmbeddedJboss() 76 { 77 EJB3StandaloneBootstrap.boot(null); 78 } 79 80 public static void shutdownEmbeddedJboss() 81 { 82 EJB3StandaloneBootstrap.shutdown(); 83 } 84 85 86 protected InitialContext getInitialContext() throws Exception 87 { 88 return new InitialContext (getInitialContextProperties()); 89 } 90 91 protected Hashtable getInitialContextProperties() 92 { 93 return EJB3StandaloneBootstrap.getInitialContextProperties(); 94 } 95 96 private Properties getDefaultPersistenceProperties() 97 throws IOException 98 { 99 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("default.persistence.properties"); 100 assertNotNull(is); 101 Properties defaults = new Properties (); 102 defaults.load(is); 103 return defaults; 104 } 105 106 public void testDepends() throws Throwable 107 { 108 InitialContext ctx = getInitialContext(); 109 110 URL res = Thread.currentThread().getContextClassLoader().getResource("marker.txt"); 111 URL archive = EJB3StandaloneDeployer.getContainingUrlFromResource(res, "marker.txt"); 112 EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer(); 113 deployer.setKernel(EJB3StandaloneBootstrap.getKernel()); 114 deployer.setJndiProperties(getInitialContextProperties()); 115 deployer.getArchives().add(archive); 116 117 completeTest(deployer, ctx); 118 119 } 120 121 public void testCleanup() throws Throwable 122 { 123 boolean exceptionThrown = false; 124 try 125 { 126 executeEJBs(getInitialContext()); 127 } 128 catch (Exception e) 129 { 130 exceptionThrown = true; 131 } 132 assertTrue(exceptionThrown); 133 134 } 135 136 private void completeTest(EJB3StandaloneDeployer deployer, InitialContext ctx) 137 throws Exception 138 { 139 deployer.create(); 140 deployer.start(); 141 142 executeEJBs(ctx); 143 144 deployer.stop(); 145 deployer.destroy(); 146 } 147 148 private void executeEJBs(InitialContext ctx) 149 throws NamingException 150 { 151 DependsRemote stateless = (DependsRemote)ctx.lookup("DependsBean/remote"); 152 assertNotNull(stateless); 153 stateless.test(); 154 155 } 156 } | Popular Tags |