View Javadoc

1   package org.kuali.student.core.test;
2   
3   import java.util.Map;
4   
5   import org.junit.After;
6   import org.junit.AfterClass;
7   import org.junit.Assert;
8   import org.junit.Before;
9   import org.junit.BeforeClass;
10  
11  import org.kuali.rice.core.api.config.property.Config;
12  import org.kuali.rice.core.api.config.property.ConfigContext;
13  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
14  import org.kuali.rice.core.api.resourceloader.ResourceLoader;
15  import org.mortbay.jetty.webapp.WebAppClassLoader;
16       //  import org.kuali.rice.core.web
17  /**
18   * A base test class which adds the following capabilities to the test harness:
19   * 
20   * <li>
21   *   <ol>Automatically starts an embedded Jetty server which loads the application.</ol>
22   *   <ol>Starts a transaction before the test begins and rolls the transaction back after 
23   *       the test completes so that nothing is written to the database.</ol>
24   * </li>
25   * 
26   * @author Eric Westfall
27   */
28  public class BaseCase extends Assert {
29  
30  	private static final int DEFAULT_PORT = 8090;
31  	private static final String CONTEXT_NAME = "/ks-test-dev";
32  	private static final String WEBAPP_ROOT = "/src/main/webapp";
33  	
34  	//private static JettyServer server;
35  	
36  	//private TransactionalLifecycle transactionalLifecycle;
37  	
38  	@Before
39  	public void setUp() throws Exception {
40  		//transactionalLifecycle = new TransactionalLifecycle();
41  		//transactionalLifecycle.start();
42  	}
43  	
44  	@After
45  	public void tearDown() throws Exception {
46  		//try {
47  		//	if (transactionalLifecycle != null) {
48  		//		transactionalLifecycle.stop();
49  		//	}
50  		//} finally {
51  		//	transactionalLifecycle = null;
52  		//}
53  	}
54  	
55  	@BeforeClass
56  	public static void startJettyServer() throws Exception {
57  	    System.setProperty("kew.bootstrap.spring.file", "SpringBeans.xml");
58  	    
59  	//	BaseCase.server = new JettyServer(DEFAULT_PORT, CONTEXT_NAME, WEBAPP_ROOT);
60  	//	server.setFailOnContextFailure(true);
61  	//	server.setTestMode(true);
62  	//	server.start();
63  		// establish the GlobalResourceLoader and ConfigContext for the classloader of the test harness
64  	//	addWebappsToContext();
65  	}
66  	
67      /**
68       * Adds all ResourceLoaders registered to WebAppClassLoaders to the GlobalResourceLoader.
69       * Overrides the current context config with the Config registered to the (last) WebAppClassLoader
70       */
71      public static void addWebappsToContext() {
72          for (Map.Entry<ClassLoader, Config> configEntry : ConfigContext.getConfigs()) {
73              if (configEntry.getKey() instanceof WebAppClassLoader) {
74                  ResourceLoader rl = GlobalResourceLoader.getResourceLoader(configEntry.getKey());
75                  if (rl == null) {
76                      Assert.fail("didn't find resource loader for workflow test harness web app");
77                  }
78                  ConfigContext.overrideConfig(Thread.currentThread().getContextClassLoader(), configEntry.getValue());
79                  GlobalResourceLoader.addResourceLoader(rl);
80              }
81          }
82      }
83  	
84  	@AfterClass
85  	public static void stopJettyServer() throws Exception {
86  	//	try {
87  	//		if (server != null) {
88  	//			server.stop();
89  	//		}
90  	//	} finally {
91  	//		server = null;
92  	//	}
93  	}
94  	
95  }