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.LinkedList; 020import java.util.List; 021 022import org.apache.wicket.page.IManageablePage; 023import org.apache.wicket.pageStore.IPageContext; 024import org.apache.wicket.pageStore.IPageStore; 025 026public class MockPageStore implements IPageStore 027{ 028 private final LinkedList<IManageablePage> pages = new LinkedList<>(); 029 030 @Override 031 public boolean supportsVersioning() 032 { 033 // pretend versioning support, although pages are not actually serialized 034 return true; 035 } 036 037 @Override 038 public void destroy() 039 { 040 pages.clear(); 041 } 042 043 public List<IManageablePage> getPages() 044 { 045 return pages; 046 } 047 048 @Override 049 public IManageablePage getPage(IPageContext context, int id) 050 { 051 for (IManageablePage page : pages) { 052 if (page.getPageId() == id) { 053 return page; 054 } 055 } 056 return null; 057 } 058 059 @Override 060 public void removePage(IPageContext context, final IManageablePage page) 061 { 062 for (IManageablePage candidate : pages) { 063 if (candidate.getPageId() == page.getPageId()) { 064 pages.remove(candidate); 065 return; 066 } 067 } 068 } 069 070 @Override 071 public void removeAllPages(IPageContext context) 072 { 073 pages.clear(); 074 } 075 076 @Override 077 public boolean canBeAsynchronous(IPageContext context) 078 { 079 return true; 080 } 081 082 @Override 083 public void addPage(IPageContext context, IManageablePage page) 084 { 085 removePage(context, page); 086 087 pages.addLast(page); 088 } 089}