PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 29package org.opennms.web;
 30
 31import javax.servlet.Filter;
 32import javax.servlet.ServletContextEvent;
 33import javax.servlet.ServletException;
 34
 35import junit.framework.TestCase;
 36
 37import org.opennms.core.db.DataSourceFactory;
 38import org.opennms.core.test.MockLogAppender;
 39import org.opennms.core.test.db.MockDatabase;
 40import org.opennms.test.DaoTestConfigBean;
 41import org.springframework.mock.web.MockFilterConfig;
 42import org.springframework.mock.web.MockServletConfig;
 43import org.springframework.mock.web.MockServletContext;
 44import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
 45import org.springframework.web.context.ContextLoaderListener;
 46
 47/**
 48 * Test the Spring context for the http-remoting project by loading it with a
 49 * {@link org.springframework.mock.web.MockServletContext}.
 50 * 
 51 * @author <a href="mailto:brozow@opennms.org">Mathew Brozowski</a>
 52 * @author Seth
 53 */
 54public class HttpRemotingContextTest extends TestCase {
 55
 56	private String contextPath = "/opennms/http-remoting";
 57
 58	private MockServletConfig servletConfig;
 59	private MockServletContext servletContext;
 60	private ContextLoaderListener contextListener;
 61	private Filter filter;
 62	
 63	@Override
 64	public void setUp() throws Exception {
 65		MockLogAppender.setupLogging();
 66	}
 67
 68	public void testLoadContext() throws Throwable {
 69
 70		DaoTestConfigBean bean = new DaoTestConfigBean();
 71		bean.afterPropertiesSet();
 72
 73		MockDatabase db = new MockDatabase(true);
 74		DataSourceFactory.setInstance(db);
 75
 76		servletContext = new MockServletContext("file:src/main/webapp");
 77
 78		servletContext.addInitParameter(
 79				"contextConfigLocation", 
 80				"classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " +
 81				"classpath:/META-INF/opennms/applicationContext-soa.xml " +
 82				"classpath:/META-INF/opennms/applicationContext-dao.xml " +
 83				"classpath*:/META-INF/opennms/component-service.xml " +
 84				"classpath*:/META-INF/opennms/component-dao.xml " +
 85				"/WEB-INF/applicationContext-svclayer.xml " +
 86				"/WEB-INF/applicationContext-spring-security.xml "
 87		);
 88
 89		servletContext.addInitParameter("parentContextKey", "daoContext");
 90
 91		ServletContextEvent e = new ServletContextEvent(servletContext);
 92		contextListener = new ContextLoaderListener();
 93		contextListener.contextInitialized(e);
 94
 95		servletContext.setContextPath(contextPath);
 96		servletConfig = new MockServletConfig(servletContext, "dispatcher");    
 97		servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
 98		servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");
 99
100		try {
101
102			MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
103			filter = new OpenSessionInViewFilter();
104			filter.init(filterConfig);
105		} catch (ServletException se) {
106			throw se.getRootCause();
107		}
108	}
109}