velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1768187 - in /velocity/tools/trunk: velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/ velocity-tools-examples/velocity-tools-examples-showcase/src/test/java/org/apache/velocity/examples/showcase/ velocity-tools-view...
Date Sat, 05 Nov 2016 11:08:57 GMT
Author: cbrisson
Date: Sat Nov  5 11:08:57 2016
New Revision: 1768187

URL: http://svn.apache.org/viewvc?rev=1768187&view=rev
Log:
[tools] blackbox tests fixed

Modified:
    velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/browser.vm
    velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/test/java/org/apache/velocity/examples/showcase/ViewToolsIT.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
    velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UAParser.java

Modified: velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/browser.vm
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/browser.vm?rev=1768187&r1=1768186&r2=1768187&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/browser.vm
(original)
+++ velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/main/webapp/browser.vm
Sat Nov  5 11:08:57 2016
@@ -91,6 +91,7 @@ $demo.thisPage.insert("#doclink( 'Browse
 #demo( 'browser' 'Yahoo' $desc )
 #demo( 'browser' 'Google' $desc )
 #demo( 'browser' 'Java' $desc )
+#demo( 'browser' 'httpunit' $desc )
 #demo( 'browser' 'Altavista' $desc )
 #demo( 'browser' 'Scooter' $desc )
 #demo( 'browser' 'Lycos' $desc )

Modified: velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/test/java/org/apache/velocity/examples/showcase/ViewToolsIT.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/test/java/org/apache/velocity/examples/showcase/ViewToolsIT.java?rev=1768187&r1=1768186&r2=1768187&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/test/java/org/apache/velocity/examples/showcase/ViewToolsIT.java
(original)
+++ velocity/tools/trunk/velocity-tools-examples/velocity-tools-examples-showcase/src/test/java/org/apache/velocity/examples/showcase/ViewToolsIT.java
Sat Nov  5 11:08:57 2016
@@ -166,11 +166,11 @@ public class ViewToolsIT {
     /******* Tests **********/
 
     public @Test void testBrowserTool() throws Exception {
-        /* check we are identified as a Java (HttpUnit) client */
+        /* check we are identified as a HttpUnit client */
         WebConversation conv = new WebConversation();
         WebRequest req = new GetMethodWebRequest(ROOT_URL+"browser.vm");
         WebResponse resp = conv.getResponse(req);
-        checkText(resp,"Java","true");
+        checkText(resp,"httpunit","true");
 
         /* check language */
         req.setHeaderField("Accept-Language","en");

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java?rev=1768187&r1=1768186&r2=1768187&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/BrowserTool.java
Sat Nov  5 11:08:57 2016
@@ -119,8 +119,6 @@ public class BrowserTool extends Browser
 
     private static Pattern quality = Pattern.compile("^q\\s*=\\s*(\\d(?:0(?:.\\d{0,3})?|1(?:.0{0,3}))?)$");
 
-    /* parsing helpers */
-    private static UAParser uaParser = null;
     /**
      * Retrieves the User-Agent header from the request (if any).
      * @see #setUserAgentString
@@ -149,7 +147,6 @@ public class BrowserTool extends Browser
             throw new NullPointerException("BrowserTool: log should not be set to null");
         }
         this.LOG = log;
-        uaParser = new UAParser(LOG);
     }
 
 
@@ -176,12 +173,7 @@ public class BrowserTool extends Browser
         {
             userAgentString = ua;
             lowercaseUserAgentString = ua.toLowerCase();
-            if (uaParser == null)
-            {
-                /* can't run without a logger, can we? */
-                throw new VelocityException("BrowserTool: no logger was defined");
-            }
-            userAgent = uaParser.parseUserAgent(ua);
+            userAgent = UAParser.parseUserAgent(ua, LOG);
         }
     }
 
@@ -543,7 +535,7 @@ public class BrowserTool extends Browser
 
     protected boolean test(String key)
     {
-        return lowercaseUserAgentString.indexOf(key) != -1;
+        return key == null ? null : lowercaseUserAgentString.indexOf(key.toLowerCase()) !=
-1;
     }
 
     private void parseAcceptLanguage()

Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UAParser.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UAParser.java?rev=1768187&r1=1768186&r2=1768187&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UAParser.java
(original)
+++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/UAParser.java
Sat Nov  5 11:08:57 2016
@@ -18,13 +18,17 @@ import java.util.regex.Pattern;
 
 public class UAParser
 {
-    public UAParser(Logger log)
+    public UAParser()
+    {
+    }
+
+    public void setLog(Logger log)
     {
         this.LOG = log;
     }
 
     protected org.slf4j.Logger LOG = null;
-    
+
     public static class UAEntity
     {
         private String name = null;
@@ -242,7 +246,13 @@ public class UAParser
     }
 
     /* the big hairy parsing method */
-    public UserAgent parseUserAgent(String userAgentString)
+    public static UserAgent parseUserAgent(String userAgentString)
+    {
+        return parseUserAgent(userAgentString, null);
+    }
+
+    /* the big hairy parsing method */
+    public static UserAgent parseUserAgent(String userAgentString, Logger log)
     {
         UserAgent ua = null;
         try
@@ -587,7 +597,7 @@ public class UAParser
         }
         catch (Exception e)
         {
-            LOG.error("BrowserTool: Could not parse browser for User-Agent: {}", userAgentString,
e);
+            if (log != null) log.error("BrowserTool: Could not parse browser for User-Agent:
{}", userAgentString, e);
             ua = null;
         }
         return ua;



Mime
View raw message