blob: c06bb93f6bfe4ba43b8f8999d2e6e18ae8d63514 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ki.spring;
import org.apache.ki.mgt.SecurityManager;
import org.apache.ki.web.servlet.KiFilter;
import static org.easymock.EasyMock.*;
import org.junit.Test;
import org.springframework.web.context.WebApplicationContext;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import java.util.HashMap;
import java.util.Map;
/**
* @author Les Hazlewood
* @since Jul 28, 2008 1:34:33 PM
*/
public class SpringKiFilterTest {
@Test
public void testDefaultConfig() throws Exception {
SpringKiFilter filter = new SpringKiFilter();
FilterConfig mockConfig = createMock(FilterConfig.class);
expect(mockConfig.getInitParameter(KiFilter.CONFIG_CLASS_NAME_INIT_PARAM_NAME)).andReturn(null);
expect(mockConfig.getInitParameter(KiFilter.CONFIG_INIT_PARAM_NAME)).andReturn(null);
expect(mockConfig.getInitParameter(KiFilter.CONFIG_URL_INIT_PARAM_NAME)).andReturn(null);
expect(mockConfig.getInitParameter(SpringIniWebConfiguration.SECURITY_MANAGER_BEAN_NAME_PARAM_NAME)).andReturn(null);
ServletContext mockContext = createMock(ServletContext.class);
WebApplicationContext appCtx = createMock(WebApplicationContext.class);
SecurityManager secMgr = createMock(SecurityManager.class);
Map<String, org.apache.ki.mgt.SecurityManager> beansOfType = new HashMap<String, SecurityManager>(1);
beansOfType.put("securityManager", secMgr);
expect(mockContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).andReturn(appCtx);
expect(appCtx.getBeansOfType(SecurityManager.class)).andReturn(beansOfType);
expect(mockConfig.getServletContext()).andReturn(mockContext).anyTimes();
replay(mockContext);
replay(appCtx);
replay(mockConfig);
filter.init(mockConfig);
}
}