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 java.util.HashMap;
020import java.util.Map;
021
022import org.apache.wicket.page.IManageablePage;
023import org.apache.wicket.page.IPageManager;
024import org.apache.wicket.pageStore.IPageStore;
025
026/**
027 * Simple {@link IPageManager} used for testing.
028 * 
029 * @author Matej Knopp
030 */
031public class MockPageManager implements IPageManager
032{
033        private final Map<Integer, IManageablePage> pages = new HashMap<>();
034
035        @Override
036        public boolean supportsVersioning()
037        {
038                return true;
039        }
040        
041        @Override
042        public void destroy()
043        {
044                pages.clear();
045        }
046
047        @Override
048        public IManageablePage getPage(int id)
049        {
050                return pages.get(id);
051        }
052
053        @Override
054        public void removePage(final IManageablePage page) {
055                pages.remove(page.getPageId());
056        }
057
058        @Override
059        public void touchPage(IManageablePage page)
060        {
061                pages.put(page.getPageId(), page);
062        }
063
064        @Override
065        public void clear()
066        {
067                pages.clear();
068        }
069
070        @Override
071        public void untouchPage(IManageablePage page)
072        {
073                pages.remove(page.getPageId());
074        }
075        
076        @Override
077        public void detach()
078        {
079        }
080
081        @Override
082        public IPageStore getPageStore()
083        {
084                throw new UnsupportedOperationException();
085        }
086}