Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java?rev=917331&view=auto ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java (added) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java Mon Mar 1 00:01:57 2010 @@ -0,0 +1,566 @@ +/* + * 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.wicket.protocol.http.mock; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; + +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.apache.wicket.Application; +import org.apache.wicket.util.value.ValueMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Mock implementation of the servlet context for testing purposes. This implementation supports all + * of the standard context methods except that request dispatching just indicates what is being + * dispatched to, rather than doing the actual dispatch. + * <p> + * The context can be configured with a path parameter that should point to an absolute directory + * location that represents the place where the contents of the WAR bundle are located. Setting this + * value allows all of the resource location functionality to work as in a fully functioning web + * application. This value is not set then not resource location functionality will work and instead + * null will always be returned. + * + * @author Chris Turner + */ +public class MockServletContext implements ServletContext +{ + private static final Logger log = LoggerFactory.getLogger(MockServletContext.class); + + private final Application application; + + private final ValueMap attributes = new ValueMap(); + + private final ValueMap initParameters = new ValueMap(); + + /** Map of mime types */ + private final ValueMap mimeTypes = new ValueMap(); + + private File webappRoot; + + /** + * Create the mock object. As part of the creation, the context sets the root directory where + * web application content is stored. This must be an ABSOLUTE directory relative to where the + * tests are being executed. For example: <code>System.getProperty("user.dir") + + * "/src/webapp"</code> + * + * @param application + * The application that this context is for + * @param path + * The path to the root of the web application + */ + public MockServletContext(final Application application, final String path) + { + this.application = application; + + webappRoot = null; + if (path != null) + { + webappRoot = new File(path); + if (!webappRoot.exists() || !webappRoot.isDirectory()) + { + log.warn("WARNING: The webapp root directory is invalid: " + path); + webappRoot = null; + } + } + + // assume we're running in maven or an eclipse project created by maven, + // so the sessions directory will be created inside the target directory, + // and will be cleaned up with a mvn clean + + File file = new File("target/work/"); + file.mkdirs(); + attributes.put("javax.servlet.context.tempdir", file); + + mimeTypes.put("html", "text/html"); + mimeTypes.put("htm", "text/html"); + mimeTypes.put("css", "text/css"); + mimeTypes.put("xml", "text/xml"); + mimeTypes.put("js", "text/plain"); + mimeTypes.put("gif", "image/gif"); + mimeTypes.put("jpg", "image/jpeg"); + mimeTypes.put("png", "image/png"); + } + + /** + * Add an init parameter. + * + * @param name + * The parameter name + * @param value + * The parameter value + */ + public void addInitParameter(final String name, final String value) + { + initParameters.put(name, value); + } + + // Configuration methods + + /** + * Add a new recognized mime type. + * + * @param fileExtension + * The file extension (e.g. "jpg") + * @param mimeType + * The mime type (e.g. "image/jpeg") + */ + public void addMimeType(final String fileExtension, final String mimeType) + { + mimeTypes.put(fileExtension, mimeType); + } + + /** + * Get an attribute with the given name. + * + * @param name + * The attribute name + * @return The value, or null + */ + public Object getAttribute(final String name) + { + return attributes.get(name); + } + + /** + * Get all of the attribute names. + * + * @return The attribute names + */ + public Enumeration<String> getAttributeNames() + { + return Collections.enumeration(attributes.keySet()); + } + + // ServletContext interface methods + + /** + * Get the context for the given URL path + * + * @param name + * The url path + * @return Always returns this + */ + public ServletContext getContext(String name) + { + return this; + } + + /** + * Get the init parameter with the given name. + * + * @param name + * The name + * @return The parameter, or null if no such parameter + */ + public String getInitParameter(final String name) + { + return initParameters.getString(name); + } + + /** + * Get the name of all of the init parameters. + * + * @return The init parameter names + */ + public Enumeration<String> getInitParameterNames() + { + return Collections.enumeration(initParameters.keySet()); + } + + /** + * @return Always 2 + */ + public int getMajorVersion() + { + return 2; + } + + /** + * Get the mime type for the given file. Uses a hardcoded map of mime types set at + * Initialization time. + * + * @param name + * The name to get the mime type for + * @return The mime type + */ + public String getMimeType(final String name) + { + int index = name.lastIndexOf('.'); + if (index == -1 || index == (name.length() - 1)) + { + return null; + } + else + { + return mimeTypes.getString(name.substring(index + 1)); + } + } + + /** + * @return Always 3 + */ + public int getMinorVersion() + { + return 3; + } + + /** + * Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value. + * + * @param name + * The name of the servlet or JSP + * @return The dispatcher + */ + public RequestDispatcher getNamedDispatcher(final String name) + { + return getRequestDispatcher(name); + } + + /** + * Get the real file path of the given resource name. + * + * @param name + * The name + * @return The real path or null + */ + public String getRealPath(String name) + { + if (webappRoot == null) + { + return null; + } + + if (name.startsWith("/")) + { + name = name.substring(1); + } + + File f = new File(webappRoot, name); + if (!f.exists()) + { + return null; + } + else + { + return f.getPath(); + } + } + + /** + * Wicket does not use the RequestDispatcher, so this implementation just returns a dummy value. + * + * @param name + * The name of the resource to get the dispatcher for + * @return The dispatcher + */ + public RequestDispatcher getRequestDispatcher(final String name) + { + return new RequestDispatcher() + { + public void forward(ServletRequest servletRequest, ServletResponse servletResponse) + throws IOException + { + servletResponse.getWriter().write("FORWARD TO RESOURCE: " + name); + } + + public void include(ServletRequest servletRequest, ServletResponse servletResponse) + throws IOException + { + servletResponse.getWriter().write("INCLUDE OF RESOURCE: " + name); + } + }; + } + + /** + * Get the URL for a particular resource that is relative to the web app root directory. + * + * @param name + * The name of the resource to get + * @return The resource, or null if resource not found + * @throws MalformedURLException + * If the URL is invalid + */ + public URL getResource(String name) throws MalformedURLException + { + if (webappRoot == null) + { + return null; + } + + if (name.startsWith("/")) + { + name = name.substring(1); + } + + File f = new File(webappRoot, name); + if (!f.exists()) + { + return null; + } + else + { + return f.toURI().toURL(); + } + } + + /** + * Get an input stream for a particular resource that is relative to the web app root directory. + * + * @param name + * The name of the resource to get + * @return The input stream for the resource, or null of resource is not found + */ + public InputStream getResourceAsStream(String name) + { + if (webappRoot == null) + { + return null; + } + + if (name.startsWith("/")) + { + name = name.substring(1); + } + + File f = new File(webappRoot, name); + if (!f.exists()) + { + return null; + } + else + { + try + { + return new FileInputStream(f); + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + return null; + } + } + } + + /** + * Get the resource paths starting from the web app root directory and then relative to the the + * given name. + * + * @param name + * The starting name + * @return The set of resource paths at this location + */ + public Set<String> getResourcePaths(String name) + { + if (webappRoot == null) + { + return new HashSet<String>(); + } + + if (name.startsWith("/")) + { + name = name.substring(1); + } + if (name.endsWith("/")) + { + name = name.substring(0, name.length() - 1); + } + String[] elements = null; + if (name.trim().length() == 0) + { + elements = new String[0]; + } + else + { + elements = name.split("/"); + } + + File current = webappRoot; + for (int i = 0; i < elements.length; i++) + { + File[] files = current.listFiles(); + boolean match = false; + for (int f = 0; f < files.length; f++) + { + if (files[f].getName().equals(elements[i]) && files[f].isDirectory()) + { + current = files[f]; + match = true; + break; + } + } + if (!match) + { + return null; + } + } + + File[] files = current.listFiles(); + Set<String> result = new HashSet<String>(); + int stripLength = webappRoot.getPath().length(); + for (int f = 0; f < files.length; f++) + { + String s = files[f].getPath().substring(stripLength).replace('\\', '/'); + if (files[f].isDirectory()) + { + s = s + "/"; + } + result.add(s); + } + return result; + } + + /** + * Get the server info. + * + * @return The server info + */ + public String getServerInfo() + { + return "Wicket Mock Test Environment v1.0"; + } + + /** + * NOT USED - Servlet Spec requires that this always returns null. + * + * @param name + * Not used + * @return null + * @throws ServletException + * Not used + */ + public Servlet getServlet(String name) throws ServletException + { + return null; + } + + /** + * Return the name of the servlet context. + * + * @return The name + */ + public String getServletContextName() + { + return application.getName(); + } + + /** + * NOT USED - Servlet spec requires that this always returns null. + * + * @return null + */ + public Enumeration<String> getServletNames() + { + return null; + } + + /** + * NOT USED - Servlet spec requires that this always returns null. + * + * @return null + */ + public Enumeration<Servlet> getServlets() + { + return null; + } + + /** + * As part of testing we always log to the console. + * + * @param e + * The exception to log + * @param msg + * The message to log + */ + public void log(Exception e, String msg) + { + log.error(msg, e); + } + + /** + * As part of testing we always log to the console. + * + * @param msg + * The message to log + */ + public void log(String msg) + { + log.info(msg); + } + + /** + * As part of testing we always log to the console. + * + * @param msg + * The message to log + * @param cause + * The cause exception + */ + public void log(String msg, Throwable cause) + { + log.error(msg, cause); + } + + /** + * Remove an attribute with the given name. + * + * @param name + * The name + */ + public void removeAttribute(final String name) + { + attributes.remove(name); + } + + /** + * Set an attribute. + * + * @param name + * The name of the attribute + * @param o + * The value + */ + public void setAttribute(final String name, final Object o) + { + attributes.put(name, o); + } + + /** + * @return context path + */ + public String getContextPath() + { + return ""; + } +}
Propchange: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java ------------------------------------------------------------------------------ svn:executable = * Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java Mon Mar 1 00:01:57 2010 @@ -314,7 +314,7 @@ private Bytes defaultMaximumUploadSize = Bytes.MAX; /** escape string for '..' within resource keys */ - private CharSequence parentFolderPlaceholder = null; + private CharSequence parentFolderPlaceholder = ""; /** Default cache duration */ private int defaultCacheDuration = 3600; Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java Mon Mar 1 00:01:57 2010 @@ -21,6 +21,7 @@ import org.apache.wicket.markup.html.form.FormComponent; import org.apache.wicket.ng.request.cycle.RequestCycle; +import org.apache.wicket.protocol.http.WebRequest; import org.apache.wicket.protocol.http.WebResponse; import org.apache.wicket.protocol.http.servlet.ServletWebRequest; import org.apache.wicket.util.string.Strings; @@ -261,12 +262,12 @@ if (cookie != null) { log.debug("Found Cookie with name=" + key + " and request URI=" + - getWebRequest().getHttpServletRequest().getRequestURI()); + getWebRequest().getUrl().toString()); } else { log.debug("Unable to find Cookie with name=" + key + " and request URI=" + - getWebRequest().getHttpServletRequest().getRequestURI()); + getWebRequest().getUrl().toString()); } } @@ -301,7 +302,7 @@ if (log.isDebugEnabled()) { log.debug("Cookie saved: " + cookieToDebugString(cookie) + "; request URI=" + - getWebRequest().getHttpServletRequest().getRequestURI()); + getWebRequest().getUrl().toString()); } return cookie; @@ -327,7 +328,7 @@ cookie.setDomain(domain); } - HttpServletRequest request = getWebRequest().getHttpServletRequest(); + HttpServletRequest request = ((ServletWebRequest)getWebRequest()).getHttpServletRequest(); String path = request.getContextPath() + request.getServletPath(); if (Strings.isEmpty(path)) { @@ -343,9 +344,9 @@ * * @return WebRequest related to the RequestCycle */ - private ServletWebRequest getWebRequest() + private WebRequest getWebRequest() { - return (ServletWebRequest)RequestCycle.get().getRequest(); + return (WebRequest)RequestCycle.get().getRequest(); } /** Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/crypt/KeyInSessionSunJceCryptFactory.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/crypt/KeyInSessionSunJceCryptFactory.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/crypt/KeyInSessionSunJceCryptFactory.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/crypt/KeyInSessionSunJceCryptFactory.java Mon Mar 1 00:01:57 2010 @@ -18,12 +18,9 @@ import java.util.UUID; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; - -import org.apache.wicket.Application; +import org.apache.wicket.MetaDataKey; +import org.apache.wicket.Session; import org.apache.wicket.ng.request.cycle.RequestCycle; -import org.apache.wicket.protocol.http.servlet.ServletWebRequest; /** * Crypt factory that produces {...@link SunJceCrypt} instances based on http session-specific @@ -36,22 +33,28 @@ */ public class KeyInSessionSunJceCryptFactory implements ICryptFactory { + /** metadata-key used to store crypto-key in session metadata */ + private static MetaDataKey<String> KEY = new MetaDataKey<String>() + { + private static final long serialVersionUID = 1L; + }; + + public ICrypt newCrypt() { RequestCycle rc = RequestCycle.get(); - HttpServletRequest request = ((ServletWebRequest)rc.getRequest()).getHttpServletRequest(); - // get http session, create if necessary - HttpSession session = request.getSession(true); + Session session = Session.get(); + session.bind(); + // retrieve or generate encryption key from session - final String keyAttr = Application.get().getApplicationKey() + "." + getClass().getName(); - String key = (String)session.getAttribute(keyAttr); + String key = session.getMetaData(KEY); if (key == null) { // generate new key key = session.getId() + "." + UUID.randomUUID().toString(); - session.setAttribute(keyAttr, key); + session.setMetaData(KEY, key); } // build the crypt based on session key Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java (original) +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java Mon Mar 1 00:01:57 2010 @@ -29,6 +29,7 @@ import org.apache.wicket.Application; import org.apache.wicket.Component; +import org.apache.wicket.IPageManagerProvider; import org.apache.wicket.IPageRendererProvider; import org.apache.wicket.IRequestCycleProvider; import org.apache.wicket.IRequestHandler; @@ -64,6 +65,8 @@ import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.ng.ThreadContext; import org.apache.wicket.ng.mock.MockApplication; +import org.apache.wicket.ng.mock.MockPageManager; +import org.apache.wicket.ng.mock.MockSessionStore; import org.apache.wicket.ng.mock.MockWebRequest; import org.apache.wicket.ng.mock.MockWebResponse; import org.apache.wicket.ng.request.IRequestMapper; @@ -79,9 +82,13 @@ import org.apache.wicket.ng.request.handler.impl.ListenerInterfaceRequestHandler; import org.apache.wicket.ng.request.handler.impl.RenderPageRequestHandler; import org.apache.wicket.ng.request.handler.impl.render.PageRenderer; +import org.apache.wicket.pageStore.IPageManager; +import org.apache.wicket.pageStore.IPageManagerContext; import org.apache.wicket.protocol.http.MockServletContext; import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.session.ISessionStore; import org.apache.wicket.settings.IRequestCycleSettings.RenderStrategy; +import org.apache.wicket.util.IProvider; import org.apache.wicket.util.diff.DiffUtil; import org.apache.wicket.util.lang.Classes; import org.apache.wicket.util.string.Strings; @@ -239,6 +246,8 @@ application.getPageRendererProvider())); application.setRequestCycleProvider(new TestRequestCycleProvider( application.getRequestCycleProvider())); + application.setSessionStoreProvider(new TestSessionStoreProvider()); + application.setPageManagerProvider(new TestPageManagerProvider()); // prepare session setupNextRequestCycle(); @@ -249,16 +258,27 @@ request = new MockWebRequest(Url.parse("/")); response = new MockWebResponse(); - if (session == null) - { - session = application.newSession(request, response); - application.getSessionStore().bind(null, session); - ThreadContext.setSession(session); - } requestCycle = application.createRequestCycle(request, response); requestCycle.setCleanupFeedbackMessagesOnDetach(false); ThreadContext.setRequestCycle(requestCycle); + + + if (session == null) + { + createNewSession(); + } + } + + + /** + * + */ + private void createNewSession() + { + session = Session.get(); + application.getSessionStore().bind(null, session); + ThreadContext.setSession(session); } public MockWebRequest getRequest() @@ -366,7 +386,7 @@ forcedHandler = forcedRequestHandler; - if (!redirect && getRequest().getHeader("Wicket-Ajax-BaseURL") == null) + if (!redirect && getRequest().getHeader("Wicket-Ajax") == null) { lastRenderedPage = null; } @@ -549,6 +569,10 @@ return url; } + public String urlFor(Link link) + { + return link.urlFor(ILinkListener.INTERFACE).toString(); + } /** * Renders a <code>Page</code> defined in <code>TestPageSource</code>. This is usually used when @@ -628,6 +652,24 @@ transform(url); request.setUrl(url); request.setHeader("Wicket-Ajax-BaseURL", url.toString()); + request.setHeader("Wicket-Ajax", "Wicket-Ajax"); + processRequest(); + } + + public Url urlFor(AjaxLink link) + { + AbstractAjaxBehavior behavior = WicketTesterHelper.findAjaxEventBehavior(link, "onclick"); + Url url = Url.parse(behavior.getCallbackUrl().toString()); + transform(url); + return url; + } + + public void executeAjaxUrl(Url url) + { + transform(url); + request.setUrl(url); + request.setHeader("Wicket-Ajax-BaseURL", url.toString()); + request.setHeader("Wicket-Ajax", "Wicket-Ajax"); processRequest(); } @@ -1507,6 +1549,7 @@ Url url = Url.parse(behavior.getCallbackUrl().toString()); transform(url); request.setHeader("Wicket-Ajax-BaseURL", url.toString()); + request.setHeader("Wicket-Ajax", "Wicket-Ajax"); processRequest(request.requestWithUrl(url), null); } @@ -1632,6 +1675,14 @@ this.exposeExceptions = exposeExceptions; } + public void executeUrl(String _url) + { + Url url = Url.parse(_url); + transform(url); + getRequest().setUrl(url); + processRequest(); + } + private class LastPageRecordingPageRendererProvider implements IPageRendererProvider { @@ -1733,4 +1784,31 @@ } + private class TestSessionStore extends MockSessionStore + { + @Override + public void invalidate(Request request) + { + super.invalidate(request); + createNewSession(); + } + } + private class TestSessionStoreProvider implements IProvider<ISessionStore> + { + public ISessionStore get() + { + return new TestSessionStore(); + } + } + + private class TestPageManagerProvider implements IPageManagerProvider + { + + public IPageManager get(IPageManagerContext context) + { + return new MockPageManager(context); + } + + } + } Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/ParentResourceEscapePathTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/ParentResourceEscapePathTest.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/ParentResourceEscapePathTest.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/ParentResourceEscapePathTest.java Mon Mar 1 00:01:57 2010 @@ -16,6 +16,8 @@ */ package org.apache.wicket; +import java.io.InputStream; + import org.apache.wicket.ng.request.Url; import org.apache.wicket.ng.resource.PackageResourceReference; import org.apache.wicket.ng.resource.ResourceReference; @@ -38,10 +40,12 @@ tester.assertRenderedPage(ParentResourceEscapePathTestPage.class); tester.assertNoErrorMessage(); + System.out.println(tester.getLastResponseAsString()); + String html = tester.getLastResponseAsString(); assertContains(html, "<html><head><wicket:link><script "); assertContains(html, " type=\"text/javascript\""); - assertContains(html, "src=\"" + expectedResourceUrl() + "\""); + assertContains(html, expectedResourceUrl() + "\""); assertContains(html, "\"></script></wicket:link></head></html>"); } @@ -64,7 +68,7 @@ final ResourceReference ref = new PackageResourceReference( ParentResourceEscapePathTestPage.class, "../../../ParentResourceTest.js"); - assertEquals(expectedResourceUrl(), tester.getLastRequestCycle().urlFor(ref)); + assertContains(tester.getRequestCycle().urlFor(ref).toString(), expectedResourceUrl()); } public void testRequestHandlingOfResourceUrlWithEscapeStringInside() @@ -78,13 +82,15 @@ private void requestHandlingOfResourceUrlWithEscapeStringInside() { - tester.getRequest() - .setUrl( - Url.parse("wicket/resource/WicketTester$DummyWebApplication/WicketTester$DummyWebApplication/" + - expectedResourceUrl())); + tester.getRequest().setUrl(Url.parse("wicket/" + expectedResourceUrl())); + InputStream i = getClass().getClassLoader().getResourceAsStream("ParentResourceTest.js"); + i = getClass().getClassLoader().getResourceAsStream("/ParentResourceTest.js"); + tester.processRequest(); tester.assertNoErrorMessage(); - assertEquals("// ParentResourceTest.js", tester.getLastResponseAsString()); + + String res = new String(tester.getLastResponse().getBinaryResponse()); + assertEquals("// ParentResourceTest.js", res); } private String expectedResourceUrl() @@ -94,7 +100,7 @@ .getParentFolderPlaceholder(); final StringBuilder url = new StringBuilder(); - url.append("../wicket/resource/org.apache.wicket.ParentResourceEscapePathTestPage/"); + url.append("resource/org.apache.wicket.ParentResourceEscapePathTestPage/"); for (int i = 0; i < 3; i++) { Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/image/ImageTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/image/ImageTest.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/image/ImageTest.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/image/ImageTest.java Mon Mar 1 00:01:57 2010 @@ -58,6 +58,6 @@ { tester.getApplication().getResourceSettings().setParentFolderPlaceholder("$up$"); tester.startPage(Home.class); - tester.assertContains("resource/org.apache.wicket.markup.html.image.Home/[$]up[$]/border/test.png\""); + tester.assertContains("resource/org.apache.wicket.markup.html.image.Home/[$]up[$]/[$]up[$]/border/logo.gif\""); } } Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java Mon Mar 1 00:01:57 2010 @@ -27,7 +27,7 @@ */ public class FormPage extends WebPage { - private final int somevalue = 1; + private final Integer somevalue = 1; private boolean formSubmitted; Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/resolver/TestHomePage.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/resolver/TestHomePage.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/resolver/TestHomePage.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/resolver/TestHomePage.java Mon Mar 1 00:01:57 2010 @@ -39,7 +39,7 @@ tester.assertLabel("message", "If you see this message wicket is properly configured and running"); - String href = "href=\"resources/org.apache.wicket.markup.resolver.HomePage_1/main.css\""; + String href = "href=\"../resource/org.apache.wicket.markup.resolver.HomePage_1/main.css\""; String doc = tester.getLastResponseAsString(); tester.assertContains(href); @@ -58,7 +58,7 @@ // start and render the test page tester.startPage(HomePage_2.class); - String href = "href=\"resources/org.apache.wicket.markup.resolver.HomePage_2/main.css\""; + String href = "href=\"../resource/org.apache.wicket.markup.resolver.HomePage_2/main.css\""; String doc = tester.getLastResponseAsString(); tester.assertContains(href); Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/TestExpirePage.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/TestExpirePage.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/TestExpirePage.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/TestExpirePage.java Mon Mar 1 00:01:57 2010 @@ -16,9 +16,8 @@ */ package org.apache.wicket.protocol.http; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.link.Link; /** * Test page for session expiry (/ page not found). @@ -33,14 +32,13 @@ public TestExpirePage() { - add(new AjaxLink("link") + add(new Link("link") { private static final long serialVersionUID = 1L; @Override - public void onClick(AjaxRequestTarget target) + public void onClick() { - target.addComponent(this); } }); } Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java Mon Mar 1 00:01:57 2010 @@ -18,6 +18,8 @@ import org.apache.wicket.WicketTestCase; import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.markup.html.pages.PageExpiredErrorPage; import org.apache.wicket.settings.IExceptionSettings; import org.apache.wicket.settings.IRequestCycleSettings; @@ -60,30 +62,16 @@ String document = tester.getLastResponseAsString(); assertTrue(document.contains("Click me to get an error")); - AjaxLink link = (AjaxLink)tester.getComponentFromLastRenderedPage("link"); - - // Clear the session to remove the pages - // tester.getWicketSession().invalidateNow(); - // - // tester.setCreateAjaxRequest(true); - // tester.executeAjaxEvent(link, "onclick"); - // tester.clickLink("link"); - // - // document = tester.getServletResponse().getDocument(); - // assertTrue(document.contains("-")); - // tester.assertAjaxLocation(); - - tester.getSession().invalidateNow(); + Link<?> link = (Link<?>)tester.getComponentFromLastRenderedPage("link"); + String linkUrl = tester.urlFor(link); // Clear the session to remove the pages tester.getSession().invalidateNow(); // Invoke the call back URL of the ajax event behavior - tester.clickLink(link); - - document = tester.getLastResponseAsString(); - assertTrue(document.equals("-")); - tester.assertAjaxLocation(); + tester.setExposeExceptions(false); + tester.executeUrl(linkUrl); + assertEquals(PageExpiredErrorPage.class, tester.getLastRenderedPage().getClass()); } /** @@ -92,7 +80,7 @@ public void testInternalErrorPage() { tester.startPage(TestErrorPage.class); - tester.getRequestCycle().setExposeExceptions(false); + tester.setExposeExceptions(false); AjaxLink link = (AjaxLink)tester.getComponentFromLastRenderedPage("link"); tester.executeAjaxEvent(link, "onclick"); Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java Mon Mar 1 00:01:57 2010 @@ -42,7 +42,11 @@ import junit.framework.TestCase; import org.apache.wicket.Application; +import org.apache.wicket.ng.ThreadContext; +import org.apache.wicket.ng.mock.MockApplication; import org.apache.wicket.ng.resource.DynamicImageResource; +import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; +import org.apache.wicket.protocol.http.mock.MockHttpServletResponse; public class WicketFilterTest extends TestCase { @@ -73,41 +77,49 @@ public void testNotModifiedResponseIncludesExpiresHeader() throws IOException, ServletException, ParseException { - application = new DummyWebApplication(); - WicketFilter filter = new WicketFilter(); - filter.init(new FilterTestingConfig()); - Application.set(application); - DynamicImageResource resource = new DynamicImageResource() + try { - private static final long serialVersionUID = 1L; + application = new MockApplication(); + WicketFilter filter = new WicketFilter(); + filter.init(new FilterTestingConfig()); + application.set(); + DynamicImageResource resource = new DynamicImageResource() + { + private static final long serialVersionUID = 1L; - @Override - protected byte[] getImageData() + @Override + protected byte[] getImageData() + { + throw new UnsupportedOperationException("Not implemented"); + } + }; + // resource.setCacheable(true); + application.getSharedResources().add("foo.gif", resource); + MockHttpServletRequest request = new MockHttpServletRequest(application, null, null); + request.setURL(request.getContextPath() + "/app/" + "resources/" + + Application.class.getName() + "/foo.gif"); + setIfModifiedSinceToNextWeek(request); + MockHttpServletResponse response = new MockHttpServletResponse(request); + filter.doFilter(request, response, new FilterChain() { - throw new UnsupportedOperationException("Not implemented"); - } - }; - resource.setCacheable(true); - application.getSharedResources().add("foo.gif", resource); - MockHttpServletRequest request = new MockHttpServletRequest(application, null, null); - request.setURL(request.getContextPath() + "/app/" + "resources/" + - Application.class.getName() + "/foo.gif"); - setIfModifiedSinceToNextWeek(request); - MockHttpServletResponse response = new MockHttpServletResponse(request); - filter.doFilter(request, response, new FilterChain() + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) + throws IOException, ServletException + { + } + }); + assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus()); + String responseExpiresHeader = response.getHeader("Expires"); + assertNotNull("Expires header must be set on not modified response", + responseExpiresHeader); + + Date responseExpires = headerDateFormat.parse(responseExpiresHeader); + assertTrue("Expected later than current date but was " + responseExpires, + responseExpires.after(new Date())); + } + finally { - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) - throws IOException, ServletException - { - } - }); - assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus()); - String responseExpiresHeader = response.getHeader("Expires"); - assertNotNull("Expires header must be set on not modified response", responseExpiresHeader); - - Date responseExpires = headerDateFormat.parse(responseExpiresHeader); - assertTrue("Expected later than current date but was " + responseExpires, - responseExpires.after(new Date())); + ThreadContext.detach(); + } } private void setIfModifiedSinceToNextWeek(MockHttpServletRequest request) @@ -159,7 +171,7 @@ FilterTestingApplicationFactory.class.getName()); initParameters.put(WicketFilter.FILTER_MAPPING_PARAM, "/app/*"); initParameters.put(ContextParamWebApplicationFactory.APP_CLASS_PARAM, - DummyWebApplication.class.getName()); + MockApplication.class.getName()); } public String getFilterName() Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/stateless/StatelessComponentPageWithParams.java Mon Mar 1 00:01:57 2010 @@ -43,7 +43,8 @@ @Override public void onClick() { - if (getPageParameters().getNamedParameterKeys().size() == 2) + if (getPageParameters().getNamedParameterKeys().size() == 2 || + getPageParameters().getIndexedParamsCount() == 2) { throw new WicketRuntimeException("wanted exception"); } Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/util/cookies/CookieUtilsTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/cookies/CookieUtilsTest.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/util/cookies/CookieUtilsTest.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/util/cookies/CookieUtilsTest.java Mon Mar 1 00:01:57 2010 @@ -65,7 +65,7 @@ // See comment in CookieUtils on how removing a Cookies works. As no cookies in the request, // no "delete" cookie will be added to the response. persister.remove(textField); - assertNull(getRequestCookies()); + assertEquals(0, getRequestCookies().size()); assertEquals(0, getResponseCookies().size()); // Save the input field's value (add it to the response's cookie list) Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java?rev=917331&r1=917330&r2=917331&view=diff ============================================================================== --- wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java (original) +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java Mon Mar 1 00:01:57 2010 @@ -551,7 +551,12 @@ try { tester.startPage(BlockedResourceLinkPage.class); - System.out.println(tester.getLastResponse().getStatus()); + + TagTester linkTag = TagTester.createTagByAttribute(tester.getLastResponseAsString(), + "wicket:id", "link"); + String url = linkTag.getAttribute("href"); + url = url.replace("../", "wicket/"); + tester.executeUrl(url); fail("Accessing " + BlockedResourceLinkPage.class + " should have raised a " + PackageResourceBlockedException.class); }