cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r678670 - in /cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher: ./ WildcardMatcherTest.java
Date Tue, 22 Jul 2008 08:13:00 GMT
Author: reinhard
Date: Tue Jul 22 01:12:59 2008
New Revision: 678670

URL: http://svn.apache.org/viewvc?rev=678670&view=rev
Log:
add unit tests for named parameters in wildcard expressions

Added:
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcherTest.java
  (with props)

Added: cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcherTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcherTest.java?rev=678670&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcherTest.java
(added)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcherTest.java
Tue Jul 22 01:12:59 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.cocoon.corona.sitemap.matcher;
+
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.cocoon.corona.sitemap.matcher.WildcardMatcher.WildcardExpressionRewriter;
+import org.junit.Test;
+
+public class WildcardMatcherTest {
+
+    @Test
+    public void testMatcher() {
+        WildcardMatcher matcher = new WildcardMatcher();
+        Map<String, String> result = matcher.match("*/{name}/**/{id}", "abc/def/ghi/jkl/5");
+        Assert.assertEquals("A parameter 'name' is expected.", "def", result.get("name"));
+        Assert.assertEquals("A parameter 'id' is expected.", "5", result.get("id"));
+        Assert.assertEquals("A result value '1' is expected.", "abc", result.get("1"));
+        Assert.assertEquals("A result value '2' is expected.", "def", result.get("2"));
+        Assert.assertEquals("A result value '3' is expected.", "ghi/jkl", result.get("3"));
+        Assert.assertEquals("A result value '4' is expected.", "5", result.get("4"));
+        Assert.assertEquals("A result value '0' is expected.", "abc/def/ghi/jkl/5", result.get("0"));
+    }
+
+    @Test
+    public void testMatcherWithoutParamters() {
+        WildcardMatcher matcher = new WildcardMatcher();
+        Map<String, String> result = matcher.match("*/**", "abc/def/ghi/jkl/5");
+        Assert.assertEquals("A result value '1' is expected.", "abc", result.get("1"));
+        Assert.assertEquals("A result value '2' is expected.", "def/ghi/jkl/5", result.get("2"));
+        Assert.assertEquals("A result value '0' is expected.", "abc/def/ghi/jkl/5", result.get("0"));
+    }
+
+    @Test
+    public void testMatcherWithoutWildcards() {
+        WildcardMatcher matcher = new WildcardMatcher();
+        Map<String, String> result = matcher.match("abc", "abc");
+        Assert.assertNull("No matching result", result.get("1"));
+        Assert.assertEquals("A result value '0' is expected.", "abc", result.get("0"));
+    }
+
+    @Test
+    public void testFindParameterNames() {
+        WildcardExpressionRewriter rewriter = new WildcardExpressionRewriter("abc/{name}/*/{id}");
+        Map<String, String> parameters = rewriter.getParameters();
+        Assert.assertEquals("A parameter 'name' is expected.", "name", parameters.get("1"));
+        Assert.assertEquals("A parameter 'id' is expected.", "id", parameters.get("3"));
+    }
+
+    @Test
+    public void testRewritingExpression() {
+        WildcardExpressionRewriter rewriter = new WildcardExpressionRewriter("abc/{name}/*/{id}.html");
+        Assert.assertEquals("abc/*/*/*.html", rewriter.getRewrittenExpression());
+    }
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcherTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcherTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcherTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message