You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2013/08/19 15:00:16 UTC

svn commit: r1515392 - in /felix/trunk/http/sslfilter: ./ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/felix/ src/test/java/org/apache/felix/http/ src/test/java/org/apache/felix/http/sslfilter/ src/test...

Author: fmeschbe
Date: Mon Aug 19 13:00:15 2013
New Revision: 1515392

URL: http://svn.apache.org/r1515392
Log:
FELIX-4196 Add unit tests and compile for Java 5 to support Mockito

Added:
    felix/trunk/http/sslfilter/src/test/
    felix/trunk/http/sslfilter/src/test/java/
    felix/trunk/http/sslfilter/src/test/java/org/
    felix/trunk/http/sslfilter/src/test/java/org/apache/
    felix/trunk/http/sslfilter/src/test/java/org/apache/felix/
    felix/trunk/http/sslfilter/src/test/java/org/apache/felix/http/
    felix/trunk/http/sslfilter/src/test/java/org/apache/felix/http/sslfilter/
    felix/trunk/http/sslfilter/src/test/java/org/apache/felix/http/sslfilter/internal/
    felix/trunk/http/sslfilter/src/test/java/org/apache/felix/http/sslfilter/internal/SslFilterRequestTest.java
Modified:
    felix/trunk/http/sslfilter/pom.xml

Modified: felix/trunk/http/sslfilter/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/http/sslfilter/pom.xml?rev=1515392&r1=1515391&r2=1515392&view=diff
==============================================================================
--- felix/trunk/http/sslfilter/pom.xml (original)
+++ felix/trunk/http/sslfilter/pom.xml Mon Aug 19 13:00:15 2013
@@ -34,6 +34,13 @@
     <build>
         <plugins>
             <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <version>2.3.7</version>

Added: felix/trunk/http/sslfilter/src/test/java/org/apache/felix/http/sslfilter/internal/SslFilterRequestTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/sslfilter/src/test/java/org/apache/felix/http/sslfilter/internal/SslFilterRequestTest.java?rev=1515392&view=auto
==============================================================================
--- felix/trunk/http/sslfilter/src/test/java/org/apache/felix/http/sslfilter/internal/SslFilterRequestTest.java (added)
+++ felix/trunk/http/sslfilter/src/test/java/org/apache/felix/http/sslfilter/internal/SslFilterRequestTest.java Mon Aug 19 13:00:15 2013
@@ -0,0 +1,83 @@
+/*
+ * 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.felix.http.sslfilter.internal;
+
+import static org.mockito.Mockito.when;
+
+import javax.servlet.http.HttpServletRequest;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class SslFilterRequestTest
+{
+
+    @Test
+    public void test_isSecure()
+    {
+        HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
+        SslFilterRequest sreq = new SslFilterRequest(req);
+
+        when(req.isSecure()).thenReturn(false);
+        TestCase.assertFalse(req.isSecure());
+        TestCase.assertTrue(sreq.isSecure());
+        TestCase.assertFalse(req.isSecure());
+
+        when(req.isSecure()).thenReturn(true);
+        TestCase.assertTrue(req.isSecure());
+        TestCase.assertTrue(sreq.isSecure());
+        TestCase.assertTrue(req.isSecure());
+    }
+
+    @Test
+    public void test_getScheme()
+    {
+        HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
+        SslFilterRequest sreq = new SslFilterRequest(req);
+
+        when(req.getScheme()).thenReturn("http");
+        TestCase.assertEquals("http", req.getScheme());
+        TestCase.assertEquals("https", sreq.getScheme());
+        TestCase.assertEquals("http", req.getScheme());
+
+        when(req.getScheme()).thenReturn("https");
+        TestCase.assertEquals("https", req.getScheme());
+        TestCase.assertEquals("https", sreq.getScheme());
+        TestCase.assertEquals("https", req.getScheme());
+    }
+
+    @Test
+    public void test_getRequestURL()
+    {
+        HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
+        SslFilterRequest sreq = new SslFilterRequest(req);
+
+        when(req.getRequestURL()).thenReturn(new StringBuffer("http://some/page"));
+        TestCase.assertEquals("http://some/page", req.getRequestURL().toString());
+        TestCase.assertEquals("https://some/page", sreq.getRequestURL().toString());
+        TestCase.assertEquals("http://some/page", req.getRequestURL().toString());
+
+        when(req.getRequestURL()).thenReturn(new StringBuffer("https://some/page"));
+        TestCase.assertEquals("https://some/page", req.getRequestURL().toString());
+        TestCase.assertEquals("https://some/page", sreq.getRequestURL().toString());
+        TestCase.assertEquals("https://some/page", req.getRequestURL().toString());
+    }
+}