View Javadoc

1   /*
2    * SymmetricDS is an open source database synchronization solution.
3    *   
4    * Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, see
18   * <http://www.gnu.org/licenses/>.
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  }