tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1036792 - in /tomcat/trunk: java/org/apache/catalina/util/ContextName.java test/org/apache/catalina/util/TestContextName.java
Date Fri, 19 Nov 2010 10:33:54 GMT
Author: markt
Date: Fri Nov 19 10:33:54 2010
New Revision: 1036792

URL: http://svn.apache.org/viewvc?rev=1036792&view=rev
Log:
Add displayName to ContextName
Fix some bugs in ContextName constructors
Add a test case for ContextName

Added:
    tomcat/trunk/test/org/apache/catalina/util/TestContextName.java   (with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/util/ContextName.java

Modified: tomcat/trunk/java/org/apache/catalina/util/ContextName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/ContextName.java?rev=1036792&r1=1036791&r2=1036792&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/ContextName.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/ContextName.java Fri Nov 19 10:33:54 2010
@@ -47,21 +47,21 @@ public final class ContextName {
             baseName = name;
         }
 
+        String tmp;
         // Extract version number
         int versionIndex = baseName.indexOf(VERSION_MARKER);
         if (versionIndex > -1) {
             version = baseName.substring(versionIndex + 2);
+            tmp = baseName.substring(0, versionIndex);
         } else {
             version = "";
+            tmp = baseName;
         }
 
-        if (ROOT_NAME.equals(baseName)) {
+        if (ROOT_NAME.equals(tmp)) {
             path = "";
-        } else if (versionIndex > -1) {
-            path = "/" + baseName.substring(0, versionIndex).replaceAll(
-                    FWD_SLASH_REPLACEMENT, "/");
         } else {
-            path = "/" + baseName.replaceAll(FWD_SLASH_REPLACEMENT, "/");
+            path = "/" + tmp.replaceAll(FWD_SLASH_REPLACEMENT, "/");
         }
         
         if (versionIndex > -1) {
@@ -101,7 +101,7 @@ public final class ContextName {
 
         // Base name is converted path + version
         StringBuilder tmp = new StringBuilder();
-        if ("".equals(path)) {
+        if ("".equals(this.path)) {
             tmp.append(ROOT_NAME);
         } else {
             tmp.append(this.path.substring(1).replaceAll("/",
@@ -129,4 +129,25 @@ public final class ContextName {
     public String getName() {
         return name;
     }
+
+    public String getDisplayName() {
+        StringBuilder tmp = new StringBuilder();
+        if (path == "") {
+            tmp.append('/');
+        } else {
+            tmp.append(path);
+        }
+        
+        if (version != "") {
+            tmp.append(VERSION_MARKER);
+            tmp.append(version);
+        }
+        
+        return tmp.toString();
+    }
+    
+    @Override
+    public String toString() {
+        return getDisplayName();
+    }
 }

Added: tomcat/trunk/test/org/apache/catalina/util/TestContextName.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/util/TestContextName.java?rev=1036792&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/util/TestContextName.java (added)
+++ tomcat/trunk/test/org/apache/catalina/util/TestContextName.java Fri Nov 19 10:33:54 2010
@@ -0,0 +1,140 @@
+package org.apache.catalina.util;
+
+import junit.framework.TestCase;
+
+public class TestContextName extends TestCase {
+
+    private ContextName cn1;
+    private ContextName cn2;
+    private ContextName cn3;
+    private ContextName cn4;
+    private ContextName cn5;
+    private ContextName cn6;
+    private ContextName cn7;
+    private ContextName cn8;
+    private ContextName cn9;
+    private ContextName cn10;
+    private ContextName cn11;
+    private ContextName cn12;
+    private ContextName cn13;
+    private ContextName cn14;
+    private ContextName cn15;
+    private ContextName cn16;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        cn1 = new ContextName(null, null);
+        cn2 = new ContextName("", null);
+        cn3 = new ContextName("/", null);
+        cn4 = new ContextName("/foo", null);
+        cn5 = new ContextName("/foo/bar", null);
+        cn6 = new ContextName(null, "A");
+        cn7 = new ContextName("", "B");
+        cn8 = new ContextName("/", "C");
+        cn9 = new ContextName("/foo", "D");
+        cn10 = new ContextName("/foo/bar", "E");
+        cn11 = new ContextName("ROOT");
+        cn12 = new ContextName("foo");
+        cn13 = new ContextName("foo#bar");
+        cn14 = new ContextName("ROOT##A");
+        cn15 = new ContextName("foo##D");
+        cn16 = new ContextName("foo#bar##E");
+    }
+
+    public void testGetBaseName() {
+        assertEquals("ROOT", cn1.getBaseName());
+        assertEquals("ROOT", cn2.getBaseName());
+        assertEquals("ROOT", cn3.getBaseName());
+        assertEquals("foo", cn4.getBaseName());
+        assertEquals("foo#bar", cn5.getBaseName());
+        assertEquals("ROOT##A", cn6.getBaseName());
+        assertEquals("ROOT##B", cn7.getBaseName());
+        assertEquals("ROOT##C", cn8.getBaseName());
+        assertEquals("foo##D", cn9.getBaseName());
+        assertEquals("foo#bar##E", cn10.getBaseName());
+        assertEquals("ROOT", cn11.getBaseName());
+        assertEquals("foo", cn12.getBaseName());
+        assertEquals("foo#bar", cn13.getBaseName());
+        assertEquals("ROOT##A", cn14.getBaseName());
+        assertEquals("foo##D", cn15.getBaseName());
+        assertEquals("foo#bar##E", cn16.getBaseName());
+    }
+
+    public void testGetPath() {
+        assertEquals("", cn1.getPath());
+        assertEquals("", cn2.getPath());
+        assertEquals("", cn3.getPath());
+        assertEquals("/foo", cn4.getPath());
+        assertEquals("/foo/bar", cn5.getPath());
+        assertEquals("", cn6.getPath());
+        assertEquals("", cn7.getPath());
+        assertEquals("", cn8.getPath());
+        assertEquals("/foo", cn9.getPath());
+        assertEquals("/foo/bar", cn10.getPath());
+        assertEquals("", cn11.getPath());
+        assertEquals("/foo", cn12.getPath());
+        assertEquals("/foo/bar", cn13.getPath());
+        assertEquals("", cn14.getPath());
+        assertEquals("/foo", cn15.getPath());
+        assertEquals("/foo/bar", cn16.getPath());
+    }
+
+    public void testGetVersion() {
+        assertEquals("", cn1.getVersion());
+        assertEquals("", cn2.getVersion());
+        assertEquals("", cn3.getVersion());
+        assertEquals("", cn4.getVersion());
+        assertEquals("", cn5.getVersion());
+        assertEquals("A", cn6.getVersion());
+        assertEquals("B", cn7.getVersion());
+        assertEquals("C", cn8.getVersion());
+        assertEquals("D", cn9.getVersion());
+        assertEquals("E", cn10.getVersion());
+        assertEquals("", cn11.getVersion());
+        assertEquals("", cn12.getVersion());
+        assertEquals("", cn13.getVersion());
+        assertEquals("A", cn14.getVersion());
+        assertEquals("D", cn15.getVersion());
+        assertEquals("E", cn16.getVersion());
+    }
+
+    public void testGetName() {
+        assertEquals("", cn1.getName());
+        assertEquals("", cn2.getName());
+        assertEquals("", cn3.getName());
+        assertEquals("/foo", cn4.getName());
+        assertEquals("/foo/bar", cn5.getName());
+        assertEquals("##A", cn6.getName());
+        assertEquals("##B", cn7.getName());
+        assertEquals("##C", cn8.getName());
+        assertEquals("/foo##D", cn9.getName());
+        assertEquals("/foo/bar##E", cn10.getName());
+        assertEquals("", cn11.getName());
+        assertEquals("/foo", cn12.getName());
+        assertEquals("/foo/bar", cn13.getName());
+        assertEquals("##A", cn14.getName());
+        assertEquals("/foo##D", cn15.getName());
+        assertEquals("/foo/bar##E", cn16.getName());
+    }
+
+    public void testGetDisplayName() {
+        assertEquals("/", cn1.getDisplayName());
+        assertEquals("/", cn2.getDisplayName());
+        assertEquals("/", cn3.getDisplayName());
+        assertEquals("/foo", cn4.getDisplayName());
+        assertEquals("/foo/bar", cn5.getDisplayName());
+        assertEquals("/##A", cn6.getDisplayName());
+        assertEquals("/##B", cn7.getDisplayName());
+        assertEquals("/##C", cn8.getDisplayName());
+        assertEquals("/foo##D", cn9.getDisplayName());
+        assertEquals("/foo/bar##E", cn10.getDisplayName());
+        assertEquals("/", cn11.getDisplayName());
+        assertEquals("/foo", cn12.getDisplayName());
+        assertEquals("/foo/bar", cn13.getDisplayName());
+        assertEquals("/##A", cn14.getDisplayName());
+        assertEquals("/foo##D", cn15.getDisplayName());
+        assertEquals("/foo/bar##E", cn16.getDisplayName());
+    }
+
+}

Propchange: tomcat/trunk/test/org/apache/catalina/util/TestContextName.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message