portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1619282 - in /portals/applications/webcontent/trunk/reverse-proxy: ./ src/test/java/org/apache/portals/applications/webcontent2/proxy/util/ src/test/webapp/ src/test/webapp/WEB-INF/
Date Thu, 21 Aug 2014 03:10:23 GMT
Author: woonsan
Date: Thu Aug 21 03:10:23 2014
New Revision: 1619282

URL: http://svn.apache.org/r1619282
Log:
APA-60: Adding more tests about loading proxy mappings from YAML configuration

Added:
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/util/
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtilsTest.java
Modified:
    portals/applications/webcontent/trunk/reverse-proxy/pom.xml
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp
    portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp

Modified: portals/applications/webcontent/trunk/reverse-proxy/pom.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/pom.xml?rev=1619282&r1=1619281&r2=1619282&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/pom.xml (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/pom.xml Thu Aug 21 03:10:23 2014
@@ -102,12 +102,18 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
   <profiles>
 
     <!--
-      You can run `mvn -Prun clean veryfy' for easier testing at http://localhost:8080/rproxy/.
+      You can run `mvn -Prun clean veryfy' for easier testing at http://localhost:8080/.
       Also, you can run the following for remote debugging:
 
       $ export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
@@ -158,7 +164,7 @@
               </execution>
             </executions>
             <configuration>
-              <contextPath>/rproxy</contextPath>
+              <contextPath>/</contextPath>
               <webAppSourceDirectory>${basedir}/src/test/webapp</webAppSourceDirectory>
               <classesDirectory>${basedir}/target/classes, ${basedir}/target/test-classes</classesDirectory>
               <systemProperties>

Added: portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtilsTest.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtilsTest.java?rev=1619282&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtilsTest.java
(added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtilsTest.java
Thu Aug 21 03:10:23 2014
@@ -0,0 +1,183 @@
+/*
+ * 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.portals.applications.webcontent2.proxy.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.List;
+
+import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
+import org.apache.portals.applications.webcontent2.proxy.impl.RegexProxyMapping;
+import org.apache.portals.applications.webcontent2.proxy.impl.SimpleProxyMapping;
+import org.apache.portals.applications.webcontent2.rewriter.ContentRewritingException;
+import org.apache.portals.applications.webcontent2.rewriter.impl.AbstractTextLineContentRewriter;
+import org.junit.Test;
+
+public class YamlConfigUtilsTest
+{
+
+    private static final String SIMPLE_MAPPINGS = "\n"
+                    + "--- !simple\n"
+                    + "local: /portals/applications/\n"
+                    + "remote: http://portals.apache.org/applications/\n"
+                    + "\n"
+                    + "--- !simple\n"
+                    + "local: /portals/bridges/\n"
+                    + "remote: http://portals.apache.org/bridges/\n"
+                    + "\n"
+                    + "--- !simple\n"
+                    + "local: /portals/\n"
+                    + "remote: http://portals.apache.org/\n" 
+                    + "\n"
+                    + "--- !simple\n"
+                    + "local: /\n"
+                    + "remote: http://www.apache.org/\n"
+                    + "contentRewriter: !!" + NOOPTextLineContentRewriter.class.getName()
+ " []\n";
+
+    private static final String REGEX_MAPPINGS = "\n"
+                    + "--- !regex\n"
+                    + "localPattern: ^/(\\w+)/(\\w+)/(.*)$\n"
+                    + "remoteReplace: http://$1.apache.org/$2/$3\n"
+                    + "remotePattern: ^http://(\\w+)\\.apache\\.org/(\\w+)/(.*)$\n"
+                    + "localReplace: /$1/$2/$3\n"
+                    + "\n"
+                    + "--- !regex\n" 
+                    + "localPattern: ^/(.*)$\n"
+                    + "remoteReplace: http://www.apache.org/$1\n"
+                    + "remotePattern: ^http://www.apache.org/(.*)$\n"
+                    + "localReplace: /$1\n"
+                    + "contentRewriter: !!" + LineNumberingTextLineContentRewriter.class.getName()
+ " [ 00000 ]\n";
+
+    @Test
+    public void testSimpleMappings() throws Exception
+    {
+        List<ProxyMapping> mappings = YamlConfigUtils.loadProxyMappings(SIMPLE_MAPPINGS,
null);
+        assertEquals(4, mappings.size());
+
+        for (ProxyMapping mapping : mappings)
+        {
+            assertTrue(mapping instanceof SimpleProxyMapping);
+        }
+
+        int index = 0;
+        assertEquals("/portals/applications/", ((SimpleProxyMapping) mappings.get(index)).getLocal());
+        assertEquals("http://portals.apache.org/applications/", ((SimpleProxyMapping) mappings.get(index)).getRemote());
+        assertEquals("/portals/applications/a1/b1/c1",
+                     mappings.get(index).resolveLocalFromRemote("http://portals.apache.org/applications/a1/b1/c1"));
+        assertEquals("http://portals.apache.org/applications/a2/b2/c2",
+                     mappings.get(index).resolveRemoteFromLocal("/portals/applications/a2/b2/c2"));
+        assertNull(mappings.get(index).getContentRewriter());
+
+        ++index;
+        assertEquals("/portals/bridges/", ((SimpleProxyMapping) mappings.get(index)).getLocal());
+        assertEquals("http://portals.apache.org/bridges/", ((SimpleProxyMapping) mappings.get(index)).getRemote());
+        assertEquals("/portals/bridges/a1/b1/c1",
+                     mappings.get(index).resolveLocalFromRemote("http://portals.apache.org/bridges/a1/b1/c1"));
+        assertEquals("http://portals.apache.org/bridges/a2/b2/c2",
+                     mappings.get(index).resolveRemoteFromLocal("/portals/bridges/a2/b2/c2"));
+        assertNull(mappings.get(index).getContentRewriter());
+
+        ++index;
+        assertEquals("/portals/", ((SimpleProxyMapping) mappings.get(index)).getLocal());
+        assertEquals("http://portals.apache.org/", ((SimpleProxyMapping) mappings.get(index)).getRemote());
+        assertEquals("/portals/a1/b1/c1",
+                     mappings.get(index).resolveLocalFromRemote("http://portals.apache.org/a1/b1/c1"));
+        assertEquals("http://portals.apache.org/a2/b2/c2",
+                     mappings.get(index).resolveRemoteFromLocal("/portals/a2/b2/c2"));
+        assertNull(mappings.get(index).getContentRewriter());
+
+        ++index;
+        assertEquals("/", ((SimpleProxyMapping) mappings.get(index)).getLocal());
+        assertEquals("http://www.apache.org/", ((SimpleProxyMapping) mappings.get(index)).getRemote());
+        assertEquals("/a1/b1/c1",
+                     mappings.get(index).resolveLocalFromRemote("http://www.apache.org/a1/b1/c1"));
+        assertEquals("http://www.apache.org/a2/b2/c2",
+                     mappings.get(index).resolveRemoteFromLocal("/a2/b2/c2"));
+        assertNotNull(mappings.get(index).getContentRewriter());
+        assertNotNull(mappings.get(index).getContentRewriter() instanceof NOOPTextLineContentRewriter);
+    }
+
+    @Test
+    public void testRegexMappings() throws Exception
+    {
+        List<ProxyMapping> mappings = YamlConfigUtils.loadProxyMappings(REGEX_MAPPINGS,
null);
+        assertEquals(2, mappings.size());
+
+        for (ProxyMapping mapping : mappings)
+        {
+            assertTrue(mapping instanceof RegexProxyMapping);
+        }
+
+        int index = 0;
+        assertEquals("/portals/applications/a1/b1/c1",
+                     mappings.get(index).resolveLocalFromRemote("http://portals.apache.org/applications/a1/b1/c1"));
+        assertEquals("http://portals.apache.org/applications/a2/b2/c2",
+                     mappings.get(index).resolveRemoteFromLocal("/portals/applications/a2/b2/c2"));
+
+        assertEquals("/portals/bridges/a1/b1/c1",
+                     mappings.get(index).resolveLocalFromRemote("http://portals.apache.org/bridges/a1/b1/c1"));
+        assertEquals("http://portals.apache.org/bridges/a2/b2/c2",
+                     mappings.get(index).resolveRemoteFromLocal("/portals/bridges/a2/b2/c2"));
+
+        assertEquals("/portals/a1/b1/c1",
+                     mappings.get(index).resolveLocalFromRemote("http://portals.apache.org/a1/b1/c1"));
+        assertEquals("http://portals.apache.org/a2/b2/c2",
+                     mappings.get(index).resolveRemoteFromLocal("/portals/a2/b2/c2"));
+
+        assertNull(mappings.get(index).getContentRewriter());
+
+        ++index;
+        assertEquals("/a1/b1/c1",
+                     mappings.get(index).resolveLocalFromRemote("http://www.apache.org/a1/b1/c1"));
+        assertEquals("http://www.apache.org/a2/b2/c2",
+                     mappings.get(index).resolveRemoteFromLocal("/a2/b2/c2"));
+        assertNotNull(mappings.get(index).getContentRewriter());
+        assertNotNull(mappings.get(index).getContentRewriter() instanceof LineNumberingTextLineContentRewriter);
+    }
+
+    public static class NOOPTextLineContentRewriter extends AbstractTextLineContentRewriter
+    {
+        @Override
+        protected String rewriteLine(String line) throws ContentRewritingException, IOException
+        {
+            return line;
+        }
+    }
+
+    public static class LineNumberingTextLineContentRewriter extends AbstractTextLineContentRewriter
+    {
+        private int lineNum = 0;
+        private NumberFormat numberFormat;
+
+        public LineNumberingTextLineContentRewriter(String numberingFormat)
+        {
+            numberFormat = new DecimalFormat(numberingFormat);
+        }
+
+        @Override
+        protected String rewriteLine(String line) throws ContentRewritingException, IOException
+        {
+            return "" + numberFormat.format(++lineNum) + ": " + line;
+        }
+    }
+}

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml?rev=1619282&r1=1619281&r2=1619282&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/WEB-INF/web.xml Thu
Aug 21 03:10:23 2014
@@ -29,12 +29,20 @@
       <param-name>mappings</param-name>
       <param-value>
 --- !simple
-local: /applications/
+local: /portals/applications/
 remote: http://portals.apache.org/applications/
 
 --- !simple
-local: /bridges/
+local: /portals/bridges/
 remote: http://portals.apache.org/bridges/
+
+--- !simple
+local: /portals/
+remote: http://portals.apache.org/
+
+--- !simple
+local: /
+remote: http://www.apache.org/
       </param-value>
     </init-param>
     <load-on-startup>0</load-on-startup>
@@ -43,7 +51,7 @@ remote: http://portals.apache.org/bridge
   <!-- Map /* path to the Reverse Proxy Servlet -->
   <servlet-mapping>
     <servlet-name>ReverseProxyServlet</servlet-name>
-    <url-pattern>/portals/*</url-pattern>
+    <url-pattern>/rproxyservlet/*</url-pattern>
   </servlet-mapping>
   
 </web-app>

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp?rev=1619282&r1=1619281&r2=1619282&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/index.jsp Thu Aug
21 03:10:23 2014
@@ -26,8 +26,10 @@ limitations under the License.
 <hr/>
 
 <ul>
-  <li><a href="portals/applications/" target="_blank">Apache Portals Applications
(reverse proxied)</a></li>
-  <li><a href="portals/bridges/" target="_blank">Apache Portals Bridges (reverse
proxied)</a></li>
+  <li><a href="/rproxyservlet/portals/applications/" target="_blank">Apache Portals
Applications (reverse proxied)</a></li>
+  <li><a href="/rproxyservlet/portals/bridges/" target="_blank">Apache Portals
Bridges (reverse proxied)</a></li>
+  <li><a href="/rproxyservlet/portals/" target="_blank">Apache Portals (reverse
proxied)</a></li>
+  <li><a href="/rproxyservlet/" target="_blank">Apache Software Foundation (reverse
proxied)</a></li>
   <li><a href="portals-includes.jsp" target="_blank">JSP Include for Apache Portals
Applications (reverse proxied)</a></li>
 </ul>
 

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp?rev=1619282&r1=1619281&r2=1619282&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp
(original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/webapp/portals-includes.jsp
Thu Aug 21 03:10:23 2014
@@ -25,7 +25,7 @@ limitations under the License.
 
 <hr/>
 
-<jsp:include page="/portals/applications/" />
+<jsp:include page="/rproxyservlet/portals/applications/" />
 
 </body>
 </html>



Mime
View raw message