001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.mock; 018 019import org.apache.wicket.Page; 020import org.apache.wicket.RuntimeConfigurationType; 021import org.apache.wicket.Session; 022import org.apache.wicket.protocol.http.WebApplication; 023import org.apache.wicket.request.resource.caching.NoOpResourceCachingStrategy; 024 025/** 026 * {@link WebApplication} used for testing. 027 */ 028public class MockApplication extends WebApplication 029{ 030 /** 031 * Construct. 032 */ 033 public MockApplication() 034 { 035 } 036 037 @Override 038 public Class<? extends Page> getHomePage() 039 { 040 return MockHomePage.class; 041 } 042 043 @Override 044 public RuntimeConfigurationType getConfigurationType() 045 { 046 return RuntimeConfigurationType.DEVELOPMENT; 047 } 048 049 /** 050 * @return the session 051 */ 052 public Session getSession() 053 { 054 return getSessionStore().lookup(null); 055 } 056 057 @Override 058 public final String getInitParameter(String key) 059 { 060 return null; 061 } 062 063 @Override 064 protected void internalInit() 065 { 066 super.internalInit(); 067 068 // set page and session store providers 069 setSessionStoreProvider(MockSessionStore::new); 070 setPageManagerProvider(() -> new MockPageManager()); 071 072 // for test cases we usually want stable resource names 073 getResourceSettings().setCachingStrategy(NoOpResourceCachingStrategy.INSTANCE); 074 // disable nonces, CSP is not needed anyway during tests 075 getCspSettings().blocking().disabled(); 076 } 077}