You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jb...@apache.org on 2007/03/14 14:11:05 UTC

svn commit: r518124 - /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ResourceTest.java

Author: jbq
Date: Wed Mar 14 06:11:04 2007
New Revision: 518124

URL: http://svn.apache.org/viewvc?view=rev&rev=518124
Log:
Add unit test for wicket.Resource

Added:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ResourceTest.java   (with props)

Added: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ResourceTest.java?view=auto&rev=518124
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ResourceTest.java (added)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ResourceTest.java Wed Mar 14 06:11:04 2007
@@ -0,0 +1,107 @@
+/*
+ * 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 wicket;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import wicket.protocol.http.MockHttpServletResponse;
+import wicket.protocol.http.WebRequestCycle;
+import wicket.util.resource.FileResourceStream;
+import wicket.util.resource.IResourceStream;
+
+public class ResourceTest extends WicketTestCase
+{
+	private static final Log log = LogFactory.getLog(ResourceTest.class);
+	private static final String TEST_STRING = "Hello, World!";
+
+	public void testCacheableResource() {
+		String testFileLastModified;
+		final File testFile;
+		try
+		{
+			testFile = File.createTempFile(ResourceTest.class.getName(), null);
+			OutputStream out = new FileOutputStream(testFile);
+			out.write(TEST_STRING.getBytes());
+			out.close();
+		}
+		catch (IOException e)
+		{
+			throw new RuntimeException(e);
+		}
+		testFileLastModified = MockHttpServletResponse.formatDate(testFile.lastModified());
+		tester.setupRequestAndResponse();
+		WebRequestCycle cycle = tester.createRequestCycle();
+		Resource resource = new Resource() {
+			/**
+			 * 
+			 */
+			private static final long serialVersionUID = 1L;
+
+			public IResourceStream getResourceStream()
+			{
+				return new FileResourceStream(new wicket.util.file.File(testFile));
+			}
+		};
+		resource.onResourceRequested();
+		tester.processRequestCycle(cycle);
+
+		log.debug(getLastModified());
+		assertEquals(testFileLastModified, getLastModified());
+		assertEquals(TEST_STRING.length(), getContentLength());
+	}
+	public void testNonCacheableResource() {
+		String testFileLastModified;
+		final File testFile;
+		try
+		{
+			testFile = File.createTempFile(ResourceTest.class.getName(), null);
+			OutputStream out = new FileOutputStream(testFile);
+			out.write(TEST_STRING.getBytes());
+			out.close();
+		}
+		catch (IOException e)
+		{
+			throw new RuntimeException(e);
+		}
+		testFileLastModified = MockHttpServletResponse.formatDate(testFile.lastModified());
+		tester.setupRequestAndResponse();
+		WebRequestCycle cycle = tester.createRequestCycle();
+		Resource resource = new Resource() {
+			/**
+			 * 
+			 */
+			private static final long serialVersionUID = 1L;
+
+			public IResourceStream getResourceStream()
+			{
+				return new FileResourceStream(new wicket.util.file.File(testFile));
+			}
+		};
+		resource.setCacheable(false);
+		resource.onResourceRequested();
+		tester.processRequestCycle(cycle);
+
+		assertNull(getLastModified());
+		assertEquals(TEST_STRING.length(), getContentLength());
+	}
+}

Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ResourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/ResourceTest.java
------------------------------------------------------------------------------
    svn:keywords = Id