Return-Path: Delivered-To: apmail-struts-commits-archive@locus.apache.org Received: (qmail 2974 invoked from network); 21 Aug 2008 17:12:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Aug 2008 17:12:44 -0000 Received: (qmail 41165 invoked by uid 500); 21 Aug 2008 17:12:42 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 40936 invoked by uid 500); 21 Aug 2008 17:12:41 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 40927 invoked by uid 99); 21 Aug 2008 17:12:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Aug 2008 10:12:41 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Aug 2008 17:11:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0CD102388852; Thu, 21 Aug 2008 10:11:38 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r687805 - in /struts/struts2/trunk/core/src/test: java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java resources/org/apache/struts2/static/ resources/org/apache/struts2/static/resource.css Date: Thu, 21 Aug 2008 17:11:37 -0000 To: commits@struts.apache.org From: musachy@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080821171138.0CD102388852@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: musachy Date: Thu Aug 21 10:11:37 2008 New Revision: 687805 URL: http://svn.apache.org/viewvc?rev=687805&view=rev Log: Add content loader test Added: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java struts/struts2/trunk/core/src/test/resources/org/apache/struts2/static/ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/static/resource.css Added: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java?rev=687805&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java (added) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java Thu Aug 21 10:11:37 2008 @@ -0,0 +1,92 @@ +/* + * $Id: ServletDispatchedTestAssertInterceptor.java 651946 2008-04-27 13:41:38Z apetrelli $ + * + * 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.struts2.dispatcher; + +import java.io.IOException; + +import javax.servlet.http.HttpServletResponse; + +import junit.framework.TestCase; + +import org.apache.struts2.dispatcher.ng.HostConfig; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockServletContext; + +import com.mockobjects.dynamic.C; +import com.mockobjects.dynamic.Mock; + + +public class StaticContentLoaderTest extends TestCase { + + private DefaultStaticContentLoader contentLoader; + private MockHttpServletRequest req; + private MockHttpServletResponse res; + + public void testCantHandleWithoutServingStatic() { + StaticContentLoader contentLoader = new DefaultStaticContentLoader(); + + assertFalse(contentLoader.canHandle("/static/test1.css")); + assertFalse(contentLoader.canHandle("/struts/test1.css")); + assertFalse(contentLoader.canHandle("test1.css")); + } + + public void testCanHandle() { + DefaultStaticContentLoader contentLoader = new DefaultStaticContentLoader(); + contentLoader.setServeStaticContent("true"); + + assertTrue(contentLoader.canHandle("/static/test1.css")); + assertTrue(contentLoader.canHandle("/struts/test1.css")); + assertFalse(contentLoader.canHandle("test1.css")); + } + + public void testValidRersources() throws IOException { + contentLoader.findStaticResource("/struts/resource.css", req, res); + assertEquals("heya!", res.getContentAsString()); + } + + public void testInvalidRersources1() throws IOException { + contentLoader.findStaticResource("/struts..", req, res); + assertEquals(HttpServletResponse.SC_NOT_FOUND, res.getStatus()); + assertEquals(0, res.getContentLength()); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + this.contentLoader = new DefaultStaticContentLoader(); + MockServletContext servletContext = new MockServletContext(); + req = new MockHttpServletRequest(servletContext); + res = new MockHttpServletResponse(); + + + Mock hostConfigMock = new Mock(HostConfig.class); + hostConfigMock.expectAndReturn("getInitParameter", C.args(C.eq("packages")), null); + hostConfigMock.expectAndReturn("getInitParameter", C.args(C.eq("loggerFactory")), null); + + contentLoader.setEncoding("utf-8"); + + contentLoader.setHostConfig((HostConfig) hostConfigMock.proxy()); + } + + +} Added: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/static/resource.css URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/static/resource.css?rev=687805&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/static/resource.css (added) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/static/resource.css Thu Aug 21 10:11:37 2008 @@ -0,0 +1 @@ +heya! \ No newline at end of file