/opennms-assemblies/http-remoting/src/test/java/org/opennms/web/HttpRemotingContextTest.java

https://github.com/ajakubo1/opennms · Java · 109 lines · 57 code · 18 blank · 34 comment · 0 complexity · ee5cd30103d2e0109cfeebc6291002b0 MD5 · raw file

  1. /*******************************************************************************
  2. * This file is part of OpenNMS(R).
  3. *
  4. * Copyright (C) 2012 The OpenNMS Group, Inc.
  5. * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
  6. *
  7. * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
  8. *
  9. * OpenNMS(R) is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published
  11. * by the Free Software Foundation, either version 3 of the License,
  12. * or (at your option) any later version.
  13. *
  14. * OpenNMS(R) is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with OpenNMS(R). If not, see:
  21. * http://www.gnu.org/licenses/
  22. *
  23. * For more information contact:
  24. * OpenNMS(R) Licensing <license@opennms.org>
  25. * http://www.opennms.org/
  26. * http://www.opennms.com/
  27. *******************************************************************************/
  28. package org.opennms.web;
  29. import javax.servlet.Filter;
  30. import javax.servlet.ServletContextEvent;
  31. import javax.servlet.ServletException;
  32. import junit.framework.TestCase;
  33. import org.opennms.core.db.DataSourceFactory;
  34. import org.opennms.core.test.MockLogAppender;
  35. import org.opennms.core.test.db.MockDatabase;
  36. import org.opennms.test.DaoTestConfigBean;
  37. import org.springframework.mock.web.MockFilterConfig;
  38. import org.springframework.mock.web.MockServletConfig;
  39. import org.springframework.mock.web.MockServletContext;
  40. import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
  41. import org.springframework.web.context.ContextLoaderListener;
  42. /**
  43. * Test the Spring context for the http-remoting project by loading it with a
  44. * {@link org.springframework.mock.web.MockServletContext}.
  45. *
  46. * @author <a href="mailto:brozow@opennms.org">Mathew Brozowski</a>
  47. * @author Seth
  48. */
  49. public class HttpRemotingContextTest extends TestCase {
  50. private String contextPath = "/opennms/http-remoting";
  51. private MockServletConfig servletConfig;
  52. private MockServletContext servletContext;
  53. private ContextLoaderListener contextListener;
  54. private Filter filter;
  55. @Override
  56. public void setUp() throws Exception {
  57. MockLogAppender.setupLogging();
  58. }
  59. public void testLoadContext() throws Throwable {
  60. DaoTestConfigBean bean = new DaoTestConfigBean();
  61. bean.afterPropertiesSet();
  62. MockDatabase db = new MockDatabase(true);
  63. DataSourceFactory.setInstance(db);
  64. servletContext = new MockServletContext("file:src/main/webapp");
  65. servletContext.addInitParameter(
  66. "contextConfigLocation",
  67. "classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " +
  68. "classpath:/META-INF/opennms/applicationContext-soa.xml " +
  69. "classpath:/META-INF/opennms/applicationContext-dao.xml " +
  70. "classpath*:/META-INF/opennms/component-service.xml " +
  71. "classpath*:/META-INF/opennms/component-dao.xml " +
  72. "/WEB-INF/applicationContext-svclayer.xml " +
  73. "/WEB-INF/applicationContext-spring-security.xml "
  74. );
  75. servletContext.addInitParameter("parentContextKey", "daoContext");
  76. ServletContextEvent e = new ServletContextEvent(servletContext);
  77. contextListener = new ContextLoaderListener();
  78. contextListener.contextInitialized(e);
  79. servletContext.setContextPath(contextPath);
  80. servletConfig = new MockServletConfig(servletContext, "dispatcher");
  81. servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
  82. servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");
  83. try {
  84. MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
  85. filter = new OpenSessionInViewFilter();
  86. filter.init(filterConfig);
  87. } catch (ServletException se) {
  88. throw se.getRootCause();
  89. }
  90. }
  91. }