1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.jumpmind.symmetric.test;
21
22 import javax.servlet.ServletContext;
23
24 import org.jumpmind.symmetric.common.Constants;
25 import org.jumpmind.symmetric.service.IBootstrapService;
26 import org.jumpmind.symmetric.util.AppUtils;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.springframework.mock.web.MockServletContext;
30 import org.springframework.web.context.ConfigurableWebApplicationContext;
31 import org.springframework.web.context.WebApplicationContext;
32 import org.springframework.web.context.support.XmlWebApplicationContext;
33
34 public class AbstractWebTest {
35
36 protected static ConfigurableWebApplicationContext applicationContext;
37 protected static ServletContext servletContext;
38
39 @BeforeClass
40 public static void springTestContextBeforeTestMethod() throws Exception {
41 servletContext = new MockServletContext();
42 applicationContext = new XmlWebApplicationContext();
43 TestSetupUtil.setup(DatabaseTestSuite.DEFAULT_TEST_PREFIX, TestConstants.TEST_CONTINUOUS_SETUP_SCRIPT,
44 null, "hsqldb");
45 IBootstrapService bootstrapService = AppUtils
46 .find(Constants.BOOTSTRAP_SERVICE, TestSetupUtil.getRootEngine());
47 bootstrapService.setupDatabase();
48 applicationContext.setParent(TestSetupUtil.getRootEngine().getApplicationContext());
49 applicationContext.setServletContext(servletContext);
50 applicationContext.setConfigLocations(new String[0]);
51 applicationContext.refresh();
52 servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
53 }
54
55 @AfterClass
56 public static void cleanup() throws Exception {
57 TestSetupUtil.cleanup();
58 }
59 }