// ======================================================================== // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 // and Apache License v2.0 which accompanies this distribution. // The Eclipse Public License is available at // http://www.eclipse.org/legal/epl-v10.html // The Apache License v2.0 is available at // http://www.opensource.org/licenses/apache2.0.php // You may elect to redistribute this code under either of these licenses. // ======================================================================== package org.eclipse.jetty.servlets; import javax.servlet.Servlet; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlets.gzip.GzipTester; import org.eclipse.jetty.servlets.gzip.TestMinGzipSizeServlet; import org.eclipse.jetty.toolchain.test.TestingDir; import org.junit.Rule; import org.junit.Test; /** * Perform specific tests on the IncludableGzipFilter's ability to manage * minGzipSize initialization parameter. * * @see <a href="Eclipse Bug 366106">http://bugs.eclipse.org/366106</a> */ public class IncludableGzipFilterMinSizeTest { @Rule public TestingDir testdir = new TestingDir(); private Class<? extends Servlet> testServlet = TestMinGzipSizeServlet.class; @Test public void testUnderMinSize() throws Exception { GzipTester tester = new GzipTester(testdir); // Use IncludableGzipFilter tester.setGzipFilterClass(IncludableGzipFilter.class); FilterHolder holder = tester.setContentServlet(testServlet); // A valid mime type that we will never use in this test. // configured here to prevent mimeType==null logic holder.setInitParameter("mimeTypes","application/soap+xml"); holder.setInitParameter("minGzipSize", "2048"); holder.setInitParameter("uncheckedPrintWriter","true"); tester.copyTestServerFile("small_script.js"); try { tester.start(); tester.assertIsResponseNotGzipFiltered("small_script.js", "small_script.js.sha1", "text/javascript; charset=utf-8"); } finally { tester.stop(); } } @Test public void testOverMinSize() throws Exception { GzipTester tester = new GzipTester(testdir); // Use IncludableGzipFilter tester.setGzipFilterClass(IncludableGzipFilter.class); FilterHolder holder = tester.setContentServlet(testServlet); holder.setInitParameter("mimeTypes","application/soap+xml,text/javascript"); holder.setInitParameter("minGzipSize", "2048"); holder.setInitParameter("uncheckedPrintWriter","true"); tester.copyTestServerFile("big_script.js"); try { tester.start(); tester.assertIsResponseGzipCompressed("big_script.js"); } finally { tester.stop(); } } }