You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by jk...@apache.org on 2007/03/20 23:50:11 UTC

svn commit: r520634 - in /incubator/woden/trunk/java: src/org/apache/woden/ant/ src/org/apache/woden/wsdl20/extensions/http/ test/org/apache/woden/tests/ test/org/apache/woden/wsdl20/extensions/http/

Author: jkaputin
Date: Tue Mar 20 15:50:08 2007
New Revision: 520634

URL: http://svn.apache.org/viewvc?view=rev&rev=520634
Log:
WODEN-148 Fix bug when location contains no templates,
completed junit testcases, modified WsdlCm writer to
use new HTTPLocation methods.

Added:
    incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTemplateTest.java
Modified:
    incubator/woden/trunk/java/src/org/apache/woden/ant/CmHttpWriter.java
    incubator/woden/trunk/java/src/org/apache/woden/ant/CmSoapWriter.java
    incubator/woden/trunk/java/src/org/apache/woden/wsdl20/extensions/http/HTTPLocation.java
    incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java
    incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPBindingOperationExtensionsTest.java
    incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTest.java

Modified: incubator/woden/trunk/java/src/org/apache/woden/ant/CmHttpWriter.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/ant/CmHttpWriter.java?view=diff&rev=520634&r1=520633&r2=520634
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/ant/CmHttpWriter.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/ant/CmHttpWriter.java Tue Mar 20 15:50:08 2007
@@ -207,7 +207,7 @@
             return;
         }
         
-        out.write(tag, location.getLocationTemplate());
+        out.write(tag, location.getOriginalLocation());
     }
 
 }

Modified: incubator/woden/trunk/java/src/org/apache/woden/ant/CmSoapWriter.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/ant/CmSoapWriter.java?view=diff&rev=520634&r1=520633&r2=520634
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/ant/CmSoapWriter.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/ant/CmSoapWriter.java Tue Mar 20 15:50:08 2007
@@ -275,7 +275,7 @@
             return;
         }
         
-        out.write(tag, location.getLocationTemplate());
+        out.write(tag, location.getOriginalLocation());
     }
 
 }

Modified: incubator/woden/trunk/java/src/org/apache/woden/wsdl20/extensions/http/HTTPLocation.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/src/org/apache/woden/wsdl20/extensions/http/HTTPLocation.java?view=diff&rev=520634&r1=520633&r2=520634
==============================================================================
--- incubator/woden/trunk/java/src/org/apache/woden/wsdl20/extensions/http/HTTPLocation.java (original)
+++ incubator/woden/trunk/java/src/org/apache/woden/wsdl20/extensions/http/HTTPLocation.java Tue Mar 20 15:50:08 2007
@@ -106,7 +106,7 @@
      * @param location the String value of the http location
      */
     public HTTPLocation(String location) {
-        fLocationTemplate = location;
+        fOriginalLocation = location;
         
         if(location == null) {
             //TODO throw NPE with suitable error message
@@ -456,15 +456,19 @@
     private List tokenizeTemplate() {
         
         StringBuffer buffer = new StringBuffer();
-        int len = fLocationTemplate.length();
+        int len = fOriginalLocation.length();
         char currChar;
         int lastPos = len-1;
         List tokens = new Vector();
         boolean questionMarkFound = false;
         
         for(int i=0; i<len; i++) {
-            currChar = fLocationTemplate.charAt(i);
+            currChar = fOriginalLocation.charAt(i);
             if(currChar == '?' && !questionMarkFound) {
+                if(buffer.length() > 0) {
+                    tokens.add(buffer.toString());
+                    buffer = new StringBuffer();
+                }
                 questionMarkFound = true;
                 tokens.add(questionMark);
             } else if(currChar == '{') {
@@ -472,10 +476,10 @@
                     tokens.add(buffer.toString());
                     buffer = new StringBuffer();
                 }
-                if(i < lastPos && fLocationTemplate.charAt(i+1) == '{') {
+                if(i < lastPos && fOriginalLocation.charAt(i+1) == '{') {
                     tokens.add(doubleLeftBraces);
                     i++;   //continue scan from the 2nd left curly brace
-                } else if(i < lastPos && fLocationTemplate.charAt(i+1) == '!') {
+                } else if(i < lastPos && fOriginalLocation.charAt(i+1) == '!') {
                     tokens.add(exclamatedLeftBrace);
                     i++;   //continue scan from the exclamation mark
                 } else {
@@ -486,7 +490,7 @@
                     tokens.add(buffer.toString());
                     buffer = new StringBuffer();
                 }
-                if(i < lastPos && fLocationTemplate.charAt(i+1) == '}') {
+                if(i < lastPos && fOriginalLocation.charAt(i+1) == '}') {
                     tokens.add(doubleRightBraces);
                     i++;   //move loop position to the 2nd right curly brace
                 } else {

Modified: incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java?view=diff&rev=520634&r1=520633&r2=520634
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/tests/AllWodenTestsDOM.java Tue Mar 20 15:50:08 2007
@@ -46,6 +46,7 @@
 import org.apache.woden.wsdl20.extensions.http.HTTPBindingMessageReferenceExtensionsTest;
 import org.apache.woden.wsdl20.extensions.http.HTTPBindingOperationExtensionsTest;
 import org.apache.woden.wsdl20.extensions.http.HTTPEndpointExtensionsTest;
+import org.apache.woden.wsdl20.extensions.http.HTTPLocationTemplateTest;
 import org.apache.woden.wsdl20.extensions.http.HTTPLocationTest;
 import org.apache.woden.wsdl20.extensions.soap.SOAPBindingExtensionsTest;
 import org.apache.woden.wsdl20.extensions.soap.SOAPBindingFaultExtensionsTest;
@@ -117,6 +118,7 @@
     addTest(HTTPBindingOperationExtensionsTest.suite());
     addTest(HTTPBindingMessageReferenceExtensionsTest.suite());
     addTest(HTTPLocationTest.suite());
+    addTest(HTTPLocationTemplateTest.suite());
     addTest(HTTPEndpointExtensionsTest.suite());
     addTest(SimpleURIResolverTest.suite());
     addTest(ImportElementTest.suite());

Modified: incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPBindingOperationExtensionsTest.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPBindingOperationExtensionsTest.java?view=diff&rev=520634&r1=520633&r2=520634
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPBindingOperationExtensionsTest.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPBindingOperationExtensionsTest.java Tue Mar 20 15:50:08 2007
@@ -93,7 +93,7 @@
         
         String expected = "http://ws.apache.woden/location";
         HTTPLocation httpLoc = httpBindOperExts.getHttpLocation();
-        String actual = httpLoc.getLocationTemplate();
+        String actual = httpLoc.getOriginalLocation();
         assertEquals("Unexpected value for http location",
                 expected,
                 actual);

Added: incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTemplateTest.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTemplateTest.java?view=auto&rev=520634
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTemplateTest.java (added)
+++ incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTemplateTest.java Tue Mar 20 15:50:08 2007
@@ -0,0 +1,107 @@
+/**
+ * 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.woden.wsdl20.extensions.http;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Functional verification test of HTTPLocationTemplate.
+ * 
+ * @author John Kaputin (jkaputin@apache.org)
+ */
+public class HTTPLocationTemplateTest extends TestCase 
+{
+    public static Test suite()
+    {
+        return new TestSuite(HTTPLocationTemplateTest.class);
+    }
+    
+    public void testCtor() throws Exception
+    {
+        HTTPLocationTemplate template;
+        
+        //foo, encoded, in query
+        template = new HTTPLocationTemplate("foo", true, true);
+        assertNotNull(template);
+        
+        //foo, encoded, in path
+        template = new HTTPLocationTemplate("foo", true, false);
+        assertNotNull(template);
+        
+        //foo, raw, in path
+        template = new HTTPLocationTemplate("foo", false, false);
+        assertNotNull(template);
+        
+        //foo, raw, in query
+        template = new HTTPLocationTemplate("foo", false, true);
+        assertNotNull(template);
+        
+        //TODO tests for null or invalid names
+    }
+    
+    public void testGetName() {
+        
+        HTTPLocationTemplate template;
+        template = new HTTPLocationTemplate("foo", true, true);
+        assertNotNull(template);
+        assertEquals("Incorrect template name", "foo", template.getName());
+        
+    }
+    
+    public void testSetGetValue() {
+        
+        HTTPLocationTemplate template;
+        template = new HTTPLocationTemplate("foo", true, true);
+        
+        String actual = template.getValue();
+        assertNull(actual);
+        
+        template.setValue("bar");
+        actual = template.getValue();
+        assertNotNull(actual);
+        assertEquals("Unexpected value", "bar", actual);
+        
+        template.setValue(null);
+        actual = template.getValue();
+        assertNull(actual);
+    }
+    
+    public void testIsEncoded() {
+        
+        HTTPLocationTemplate template;
+        
+        template = new HTTPLocationTemplate("foo", true, true);
+        assertTrue(template.isEncoded());
+        
+        template = new HTTPLocationTemplate("foo", false, true);
+        assertFalse(template.isEncoded());
+    }
+        
+    public void testIsQuery() {
+        
+        HTTPLocationTemplate template;
+        
+        template = new HTTPLocationTemplate("foo", true, true);
+        assertTrue(template.isQuery());
+        
+        template = new HTTPLocationTemplate("foo", true, false);
+        assertFalse(template.isQuery());
+    }
+    
+}

Modified: incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTest.java
URL: http://svn.apache.org/viewvc/incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTest.java?view=diff&rev=520634&r1=520633&r2=520634
==============================================================================
--- incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTest.java (original)
+++ incubator/woden/trunk/java/test/org/apache/woden/wsdl20/extensions/http/HTTPLocationTest.java Tue Mar 20 15:50:08 2007
@@ -34,22 +34,6 @@
         return new TestSuite(HTTPLocationTest.class);
     }
     
-    /*
-     * @see TestCase#setUp()
-     */
-    protected void setUp() throws Exception 
-    {
-        super.setUp();
-    }
-
-    /*
-     * @see TestCase#tearDown()
-     */
-    protected void tearDown() throws Exception 
-    {
-        super.tearDown();
-    }
-    
     public void testCtor() throws Exception
     {
         HTTPLocation loc;
@@ -62,6 +46,10 @@
         loc = new HTTPLocation("/temperature/");
         assertNotNull(loc);
         
+        //no curly braces, path and query string
+        loc = new HTTPLocation("/temperature/town?month=Jan&day=01");
+        assertNotNull(loc);
+        
         //one local name
         loc = new HTTPLocation("/temperature/{town}/");
         assertNotNull(loc);
@@ -70,6 +58,10 @@
         loc = new HTTPLocation("/temperature/{town}/{state}/{country}");
         assertNotNull(loc);
         
+        //multiple local names, encoded & raw, path & query string
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?month={mth}&date={!dt}");
+        assertNotNull(loc);
+        
         //with double curly braces
         loc = new HTTPLocation("{{XXX}}/temperature/{town}/{{{state}}}/{country}");
         assertNotNull(loc);
@@ -80,578 +72,309 @@
         
     }
     
-    public void testGetTemplate() {
-        
-        //TODO rewrite these tests as sep methods.
+    public void testGetTemplates_noArg() {
         
         HTTPLocation loc;
-        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?acct={acctNo}&bal={!balance}");
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
         
-        HTTPLocationTemplate template;
-        HTTPLocationTemplate[] templates;
+        HTTPLocationTemplate[] templates = loc.getTemplates();
+        assertEquals("Incorrect number of templates", 7, templates.length);
         
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
         templates = loc.getTemplates();
-        assertEquals("Incorrect number of templates", 5, templates.length);
+        assertEquals("Unexpected templates", 0, templates.length);
+    }    
         
-        templates = loc.getTemplatesInPath();
+    public void testGetTemplatesInPath_noArg() {
+        
+        HTTPLocation loc;
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
+        
+        HTTPLocationTemplate[] templates = loc.getTemplatesInPath();
         assertEquals("Incorrect number of templates", 3, templates.length);
+        for(int i=0; i<templates.length; i++) {
+            assertFalse(templates[i].isQuery());
+        }
+        
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        templates = loc.getTemplatesInPath();
+        assertEquals("Unexpected templates", 0, templates.length);
+    }    
+        
+    public void testGetTemplatesInQuery_noArg() {
+        
+        HTTPLocation loc;
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
         
+        HTTPLocationTemplate[] templates = loc.getTemplatesInQuery();
+        assertEquals("Incorrect number of templates", 4, templates.length);
+        for(int i=0; i<templates.length; i++) {
+            assertTrue(templates[i].isQuery());
+        }
+        
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
         templates = loc.getTemplatesInQuery();
+        assertEquals("Unexpected templates", 0, templates.length);
+    }    
+        
+    public void testGetTemplates_oneArg() {
+        
+        HTTPLocation loc;
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
+        
+        HTTPLocationTemplate[] templates = loc.getTemplates("town");
         assertEquals("Incorrect number of templates", 2, templates.length);
         
-        template = loc.getTemplate("town");
-        assertNotNull("expected a template", template);
-        assertTrue(template.isEncoded());
-        assertNull(template.getValue());
+        templates = loc.getTemplates("state");
+        assertEquals("Incorrect number of templates", 1, templates.length);
         
-        templates = loc.getTemplatesInPath("state");
-        assertEquals(1, templates.length);
-        assertFalse(templates[0].isEncoded());
+        templates = loc.getTemplates("mth");
+        assertEquals("Incorrect number of templates", 1, templates.length);
+        
+        templates = loc.getTemplates("dummy");
+        assertEquals("Unexpected templates", 0, templates.length);
+        
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        templates = loc.getTemplates("dummy");
+        assertEquals("Unexpected templates", 0, templates.length);
+    }    
+        
+    public void testGetTemplatesInPath_oneArg() {
+        
+        HTTPLocation loc;
+        loc = new HTTPLocation("/temperature/{town}/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
+        
+        HTTPLocationTemplate[] templates = loc.getTemplatesInPath("town");
+        assertEquals("Incorrect number of templates", 2, templates.length);
+        for(int i=0; i<templates.length; i++) {
+            assertFalse(templates[i].isQuery());
+        }
+        
+        templates = loc.getTemplatesInPath("country");
+        assertEquals("Incorrect number of templates", 1, templates.length);
         assertFalse(templates[0].isQuery());
         
-        template = loc.getTemplateInQuery("acctNo");
-        assertTrue(template.isQuery());
-        template.setValue("dummy");
-        assertEquals("dummy", template.getValue());
+        templates = loc.getTemplatesInPath("dummy");
+        assertEquals("Unexpected templates", 0, templates.length);
+        
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        templates = loc.getTemplatesInPath("dummy");
+        assertEquals("Unexpected templates", 0, templates.length);
+    }    
+        
+    public void testGetTemplatesInQuery_oneArg() {
         
-    }
-    
- 
-/* The following tests are for methods deprecated by WODEN-148...to be removed
-
-    public void testGetLocationTemplate() throws Exception
-    {
         HTTPLocation loc;
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&temp2={tmp}&month={mth}&date={!dt}&place={town}");
         
-        //after ctor
-        loc = new HTTPLocation("/temperature/{town}");
-        assertEquals("/temperature/{town}", loc.getLocationTemplate());
-        
-        //after substitution ... template still has its original value
-        loc = new HTTPLocation("/temperature/{town}");
-        loc.substitute("town","London");
-        assertEquals("/temperature/{town}", loc.getLocationTemplate());
+        HTTPLocationTemplate[] templates = loc.getTemplatesInQuery("tmp");
+        assertEquals("Incorrect number of templates", 2, templates.length);
+        for(int i=0; i<templates.length; i++) {
+            assertTrue(templates[i].isQuery());
+        }
         
+        templates = loc.getTemplatesInQuery("dt");
+        assertEquals("Incorrect number of templates", 1, templates.length);
+        assertTrue(templates[0].isQuery());
+        
+        templates = loc.getTemplatesInQuery("dummy");
+        assertEquals("Unexpected templates", 0, templates.length);
+        
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        templates = loc.getTemplatesInQuery("dummy");
+        assertEquals("Unexpected templates", 0, templates.length);
+    }    
+        
+    public void testGetTemplate() {
         
-    }
-    
-    public void testIsTemplateValid() throws Exception
-    {
         HTTPLocation loc;
-        boolean result;
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
         
-        //empty string
-        loc = new HTTPLocation("");
-        result = loc.isTemplateValid();
-        assertTrue(result);
+        HTTPLocationTemplate template = loc.getTemplate("town");
+        assertNotNull("expected a template", template);
         
-        //no curly braces
-        loc = new HTTPLocation("/temperature/");
-        result = loc.isTemplateValid();
-        assertTrue(result);
+        //Where multiple templates exist with the same name, this method should return the first.
+        //Check that the template returned is the first (i.e. not the one in the query string).
+        assertFalse(template.isQuery());
         
-        //one local name
-        loc = new HTTPLocation("/temperature/{town}/");
-        result = loc.isTemplateValid();
-        assertTrue(result);
         
-        //multiple local names
-        loc = new HTTPLocation("/temperature/{town}/{state}/{country}");
-        result = loc.isTemplateValid();
-        assertTrue(result);
+        template = loc.getTemplate("dt");
+        assertNotNull("expected a template", template);
         
-        //with double curly braces
-        loc = new HTTPLocation("{{XXX}}/temperature/{town}/}}{state}{{/{country};Tic{{Tac{{Toe");
-        result = loc.isTemplateValid();
-        assertTrue(result);
-
-        //invalid .. unmatched left braces
-        
-        loc = new HTTPLocation("/foo/{bar{");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("/foo/{bar");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("/foo/bar{");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("/f{oo/{bar}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("{/f{oo/{bar}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("/foo/{bar}/man{");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        */
-        /* One might expect the template "{{{state}}}" to be parsed as {{,{state},}} where inner 
-         * most braces are matched as a pair enclosing the string "state", but in the 
-         * Woden implementation the double curly braces take precedence so it is parsed as 
-         * {{,{,state,}},} which flags the template as invalid. The WSDL 2.0 spec is silent on the 
-         * precedence of double curly braces over pairs of matching single braces.
-         */
-    /*
-        loc = new HTTPLocation("{{{state}}}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-
-        //invalid .. unmatched right braces
-        
-        loc = new HTTPLocation("/foo/}bar}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("/foo/}bar");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("/foo/bar}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("/f}oo/{bar}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("}/f}oo/{bar}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        
-        loc = new HTTPLocation("/foo/{bar}/man}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-        */
-        /* ditto the previous comment about double curly braces taking precedence over a 
-         * potentially matching pair of single curly braces. The template "{state}}}" is
-         * parsed as {,state,}},} not as {state},}}.
-         * 
-         */
-    /*
-        loc = new HTTPLocation("{state}}}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-
-        //invalid local name ... not of type xs:NCName
-        
-        loc = new HTTPLocation("/foo/{bar:man}");
-        result = loc.isTemplateValid();
-        assertFalse(result);
-    }
-    
-    public void testGetLocalNames() {
-        HTTPLocation loc;
-        String[] actual;
-        String[] expected;
-        boolean result;
-        
-        loc = new HTTPLocation("?op=EchoInt");
-        actual = loc.getLocalNames();
-        expected = new String[] {};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        actual = loc.getLocalNames();
-        expected = new String[] {"fname"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        actual = loc.getLocalNames();
-        expected = new String[] {"fname","mname","lname"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
+        template = loc.getTemplate("dummy");
+        assertNull("Unexpected template", template);
         
-    }
-    
-    public void testGetDistinctLocalNames() {
-        HTTPLocation loc;
-        String[] actual;
-        String[] expected;
-        boolean result;
-        
-        loc = new HTTPLocation("?op=EchoInt");
-        actual = loc.getDistinctLocalNames();
-        expected = new String[] {};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        actual = loc.getDistinctLocalNames();
-        expected = new String[] {"fname"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        actual = loc.getDistinctLocalNames();
-        expected = new String[] {"fname","mname","lname"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={fname};last={lname}");
-        actual = loc.getDistinctLocalNames();
-        expected = new String[] {"fname","lname"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={fname}");
-        actual = loc.getDistinctLocalNames();
-        expected = new String[] {"fname","mname"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={fname};last={fname}");
-        actual = loc.getDistinctLocalNames();
-        expected = new String[] {"fname"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        template = loc.getTemplate("dummy");
+        assertNull("Unexpected template", template);
+    }    
+        
+    public void testGetTemplateInPath() {
         
-    }
-
-    
-    public void testCountLocalNames() {
         HTTPLocation loc;
-        int count;
+        loc = new HTTPLocation("/temperature/{town}/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
         
-        loc = new HTTPLocation("?op=EchoInt");
-        count = loc.countLocalNames();
-        assertEquals(0,count);
+        HTTPLocationTemplate template = loc.getTemplateInPath("town");
+        assertNotNull("expected a template", template);
+        assertFalse(template.isQuery());
         
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        count = loc.countLocalNames();
-        assertEquals(1,count);
+        template = loc.getTemplateInPath("state");
+        assertNotNull("expected a template", template);
         
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        count = loc.countLocalNames();
-        assertEquals(3,count);
+        template = loc.getTemplateInPath("mth");
+        assertNull("Unexpected template", template);
         
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={fname}");
-        count = loc.countLocalNames();
-        assertEquals(3,count);
+        template = loc.getTemplateInPath("dummy");
+        assertNull("Unexpected template", template);
         
-    }
-    
-    public void testCountOccurrences() {
-        HTTPLocation loc;
-        int count;
-        String localName = "fname";
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        template = loc.getTemplateInPath("dummy");
+        assertNull("Unexpected template", template);
+    }    
         
-        loc = new HTTPLocation("?op=EchoInt");
-        count = loc.countOccurrences(localName);
-        assertEquals(0,count);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        count = loc.countOccurrences(localName);
-        assertEquals(1,count);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        count = loc.countOccurrences(localName);
-        assertEquals(1,count);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={fname}");
-        count = loc.countOccurrences(localName);
-        assertEquals(2,count);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={fname};last={fname}");
-        count = loc.countOccurrences(localName);
-        assertEquals(3,count);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={lname};middle={lname};last={lname}");
-        count = loc.countOccurrences(localName);
-        assertEquals(0,count);
+    public void testGetTemplateInQuery() {
         
-    }
-    
-    public void testSubstitute_StringString() {
         HTTPLocation loc;
-        String actual;
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}&place2={town}");
         
-        loc = new HTTPLocation("?op=EchoInt");
-        loc.substitute("fname", "Dougal"); //no effect
-        actual = loc.toString();
-        assertEquals("?op=EchoInt", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        loc.substitute("fname", "Dougal");
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        loc.substitute("fname", "Dougal");
-        loc.substitute("lname", "Smith");
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal;middle={mname};last=Smith", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={mname}");
-        loc.substitute("mname", "Dougal");
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first={fname};middle=Dougal;last={mname}", actual);
-
-    }
-    
-    public void testSubstitute_StringStringBoolean() {
-        HTTPLocation loc;
-        String actual;
+        HTTPLocationTemplate template = loc.getTemplateInQuery("town");
+        assertNotNull("expected a template", template);
+        assertTrue(template.isQuery());
         
-        loc = new HTTPLocation("?op=EchoInt");
-        loc.substitute("fname", "Dougal", false); //no effect
-        actual = loc.toString();
-        assertEquals("?op=EchoInt", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        loc.substitute("fname", "Dougal", false);
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        loc.substitute("fname", "Dougal", true);
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        loc.substitute("mname", "Dougal", true);
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first={fname};middle=Dougal;last={lname}", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={mname}");
-        loc.substitute("mname", "Dougal", false);
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first={fname};middle=Dougal;last={mname}", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={mname}");
-        loc.substitute("mname", "Dougal", true);
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first={fname};middle=Dougal;last=Dougal", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        loc.substitute(null, "Dougal", true); //arg1 null so ignored
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first={fname};middle={mname};last={lname}", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={mname}");
-        loc.substitute("mname", "Dougal", true);
-        loc.substitute("mname", null, false); //1st value 'Dougal' removed
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first={fname};middle={mname};last=Dougal", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={mname}");
-        loc.substitute("mname", "Dougal", true);
-        loc.substitute("mname", null, true); //both values 'Dougal' removed
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first={fname};middle={mname};last={mname}", actual);
-
-    }
-
-    public void testSubstitute_StringStringArray() {
-        HTTPLocation loc;
-        String actual;
+        template = loc.getTemplateInQuery("dt");
+        assertNotNull("expected a template", template);
         
-        loc = new HTTPLocation("?op=EchoInt");
-        loc.substitute("fname", new String[] {"Dougal"}); //no effect
-        actual = loc.toString();
-        assertEquals("?op=EchoInt", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        loc.substitute("fname", new String[] {"Dougal"}); //1 to 1
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        loc.substitute("fname", new String[] {"Dougal","Malcolm"});  //array > template
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal;middle={mname};last={lname}", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={fname};last={lname}");
-        loc.substitute("fname", new String[] {"Dougal","Malcolm"});  //array = template
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal;middle=Malcolm;last={lname}", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={fname};last={fname}");
-        loc.substitute("fname", new String[] {"Dougal","Malcolm"});  //array < template
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal;middle=Malcolm;last={fname}", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={fname};last={fname}");
-        loc.substitute("fname", new String[] {"Dougal","Malcolm","MacDonald","McDouglas"});  //array > template
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal;middle=Malcolm;last=MacDonald", actual);
-
-    }
-    
-    public void testSubstitute_StringArray() {
-        HTTPLocation loc;
-        String actual;
+        template = loc.getTemplateInQuery("country");
+        assertNull("Unexpected template", template);
         
-        loc = new HTTPLocation("?op=EchoInt");
-        loc.substitute(new String[] {"Dougal"}); //no effect
-        actual = loc.toString();
-        assertEquals("?op=EchoInt", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        loc.substitute(new String[] {"Dougal"}); //1 to 1
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        loc.substitute(new String[] {"Dougal","Malcolm"});  //array < template
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal;middle=Malcolm;last={lname}", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        loc.substitute(new String[] {"Dougal","Malcolm","MacDonald"});  //array = template
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal;middle=Malcolm;last=MacDonald", actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={lname}");
-        loc.substitute(new String[] {"Dougal","Malcolm","MacDonald","McDouglas"});  //array > template
-        actual = loc.toString();
-        assertEquals("?op=EchoInt;first=Dougal;middle=Malcolm;last=MacDonald", actual);
-
-    }
-    
-    public void testGetValue_String() {
-        HTTPLocation loc;
-        String actual;
+        template = loc.getTemplateInQuery("dummy");
+        assertNull("Unexpected template", template);
         
-        loc = new HTTPLocation("?op=EchoInt");
-        actual = loc.getValue("fname"); //no effect
-        assertNull(actual);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        actual = loc.getValue("fname");
-        assertNull(actual);
-        loc.substitute(new String[] {"Dougal"});
-        actual = loc.getValue("fname");
-        assertEquals("Dougal",actual);
-        
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={mname}");
-        loc.substitute(new String[] {"Dougal","Malcolm","MacDonald"});
-        actual = loc.getValue("mname");
-        assertEquals("Malcolm",actual);
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        template = loc.getTemplateInQuery("dummy");
+        assertNull("Unexpected template", template);
+    }    
+        
+    public void testGetTemplateNames() {
         
-    }
-    
-    public void testGetValues_String() {
         HTTPLocation loc;
-        String[] actual;
-        String[] expected;
-        boolean result;
-        
-        loc = new HTTPLocation("?op=EchoInt");
-        actual = loc.getValues("fname"); //no effect
-        expected = new String[] {};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        actual = loc.getValues("fname");
-        expected = new String[] {(String)null};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        actual = loc.getValues("mname");
-        expected = new String[] {};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        loc.substitute("fname", "Dougal");
-        actual = loc.getValues("fname");
-        expected = new String[] {"Dougal"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={fname};last={mname}");
-        loc.substitute("fname", new String[] {"Dougal","Malcolm"});
-        actual = loc.getValues("fname");
-        expected = new String[] {"Dougal","Malcolm"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-
-    }
-    
-    public void testGetValues() {
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
+        
+        String[] names = loc.getTemplateNames();
+        assertEquals("Incorrect number of names", 7, names.length);
+        assertEquals("Incorrect order of names", "town", names[0]);
+        assertEquals("Incorrect order of names", "state", names[1]);
+        assertEquals("Incorrect order of names", "country", names[2]);
+        assertEquals("Incorrect order of names", "tmp", names[3]);
+        assertEquals("Incorrect order of names", "mth", names[4]);
+        assertEquals("Incorrect order of names", "dt", names[5]);
+        assertEquals("Incorrect order of names", "town", names[6]);
+        
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        names = loc.getTemplateNames();
+        assertEquals("Unexpected template names", 0, names.length);
+    }    
+        
+    public void testGetTemplateNamesInPath() {
+        
         HTTPLocation loc;
-        String[] actual;
-        String[] expected;
-        boolean result;
-        
-        loc = new HTTPLocation("?op=EchoInt");
-        actual = loc.getValues(); //no effect
-        expected = new String[] {};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        actual = loc.getValues();
-        expected = new String[] {(String)null};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname}");
-        loc.substitute("fname", "Dougal");
-        actual = loc.getValues();
-        expected = new String[] {"Dougal"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
-
-        loc = new HTTPLocation("?op=EchoInt;first={fname};middle={mname};last={fname}");
-        loc.substitute("fname", new String[] {"Dougal","Malcolm"});
-        actual = loc.getValues();
-        expected = new String[] {"Dougal",null,"Malcolm"};
-        result = arraysEqual(expected,actual);
-        assertTrue(result);
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}");
         
-    }
-    
-    public void testToString() {
+        String[] names = loc.getTemplateNamesInPath();
+        assertEquals("Incorrect number of names", 3, names.length);
+        assertEquals("Incorrect order of names", "town", names[0]);
+        assertEquals("Incorrect order of names", "state", names[1]);
+        assertEquals("Incorrect order of names", "country", names[2]);
         
-        //toString() has been significantly tested by the testSubstituteXXX methods
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        names = loc.getTemplateNamesInPath();
+        assertEquals("Unexpected template names", 0, names.length);
+    }    
+        
+    public void testGetTemplateNamesInQuery() {
         
         HTTPLocation loc;
-        String actual;
+        loc = new HTTPLocation("/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}&temp2={tmp}");
+        
+        String[] names = loc.getTemplateNamesInQuery();
+        assertEquals("Incorrect number of names", 5, names.length);
+        assertEquals("Incorrect order of names", "tmp", names[0]);
+        assertEquals("Incorrect order of names", "mth", names[1]);
+        assertEquals("Incorrect order of names", "dt", names[2]);
+        assertEquals("Incorrect order of names", "town", names[3]);
+        assertEquals("Incorrect order of names", "tmp", names[4]);
         
-        loc = new HTTPLocation("?op={{EchoInt}};f}{irst{{}}={fname};middle}={mname};last{={lname};{{");
-        loc.substitute(new String[] {"Dougal","Malcolm","MacDonald","McDouglas"});  //array > template
-        actual = loc.toString();
-        assertEquals("?op={EchoInt};f}{irst{}=Dougal;middle}=Malcolm;last{=MacDonald;{", actual);
+        loc = new HTTPLocation("/travel/flight?no=BA6&dep=13.55");
+        names = loc.getTemplateNamesInQuery();
+        assertEquals("Unexpected template names", 0, names.length);
+    }    
+        
+    public void testGetOriginalLocation() {
+        
+        String origLoc = "/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}";
+        HTTPLocation loc;
+        loc = new HTTPLocation(origLoc);
+        String returnedLoc = loc.getOriginalLocation();
+        assertEquals("Unexpected location value", origLoc, returnedLoc);
         
+        origLoc = "/travel/flight?no=BA6&dep=13.55";
+        loc = new HTTPLocation(origLoc);
+        returnedLoc = loc.getOriginalLocation();
+        assertEquals("Unexpected location value", origLoc, returnedLoc);
     }
-*/
     
-    private boolean arraysEqual(String[] a1, String[] a2) {
-        boolean result = true;
-        Object o1, o2;
-        
-        if(a1.length != a2.length) {
-            result = false;
-        } else {
-            for(int i=0; i<a1.length; i++) {
-                o1 = a1[i];
-                o2 = a2[i];
-                if(o1 == null && o2 == null) {
-                    continue;
-                }
-                if(o1 == null || o2 == null) {
-                    result = false;
-                    break;
-                }
-                if(!a1[i].equals(a2[i])) {
-                    result = false;
-                    break;
-                }
-            }
-        }
+    public void testGetFormattedLocation() {
         
-        return result;
+        String origLoc = "/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}";
+        HTTPLocation loc;
+        loc = new HTTPLocation(origLoc);
+        HTTPLocationTemplate template;
+        HTTPLocationTemplate[] templates;
+        templates = loc.getTemplates("town");
+        templates[0].setValue("Perth");
+        template = loc.getTemplate("state");
+        template.setValue("WA");
+        template = loc.getTemplate("country");
+        template.setValue("Australia");
+        template = loc.getTemplate("tmp");
+        template.setValue("41.5");
+        template = loc.getTemplate("mth");
+        template.setValue("February");
+        template = loc.getTemplate("dt");
+        template.setValue("28th");
+        templates[1].setValue("Fremantle");
+        String formattedLoc = "/temperature/Perth/WA/Australia?temp=41.5&month=February&date=28th&place=Fremantle";
+        String returnedLoc = loc.getFormattedLocation();
+        assertEquals("Unexpected formatted location value", formattedLoc, returnedLoc);
+        
+        origLoc = "/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}";
+        loc = new HTTPLocation(origLoc);
+        templates = loc.getTemplates("town");
+        //templates[0].setValue("Perth"); //if {town} is not substituted, it will be replaced by empty string
+        template = loc.getTemplate("state");
+        template.setValue("WA");
+        template = loc.getTemplate("country");
+        template.setValue("Australia");
+        template = loc.getTemplate("tmp");
+        template.setValue("41.5");
+        template = loc.getTemplate("mth");
+        template.setValue("February");
+        template = loc.getTemplate("dt");
+        //template.setValue("28th");  //if {!dt} is not substituted, it will be replaced by empty string
+        templates[1].setValue("Fremantle");
+        formattedLoc = "/temperature//WA/Australia?temp=41.5&month=February&date=&place=Fremantle";
+        returnedLoc = loc.getFormattedLocation();
+        assertEquals("Unexpected formatted location value", formattedLoc, returnedLoc);
+        
+        origLoc = "/travel/flight?no=BA6&dep=13.55";
+        loc = new HTTPLocation(origLoc);
+        returnedLoc = loc.getFormattedLocation();
+        assertEquals("Unexpected location value", origLoc, returnedLoc);
+    }
+    
+    public void testToString() {
+        //behaviour same as getFormattedLocation();
+        testGetFormattedLocation();
     }
     
 }



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