Bug 951 - Externalize cors definition of restconf
[controller.git] / opendaylight / commons / filter-valve / src / test / java / org / opendaylight / controller / filtervalve / cors / model / UrlMatcherTest.java
diff --git a/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/model/UrlMatcherTest.java b/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/model/UrlMatcherTest.java
new file mode 100644 (file)
index 0000000..07f6354
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.filtervalve.cors.model;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+
+import java.util.LinkedHashMap;
+import org.junit.Test;
+
+public class UrlMatcherTest {
+    UrlMatcher<String> urlMatcher;
+
+    @Test
+    public void test() throws Exception {
+        final String defaultFilter = "default";
+        final String exactMatchFilter = "someFilter";
+        final String jspFilter = "jspFilter";
+        final String exactMatch = "/somePath";
+        final String prefixFilter = "prefixFilter";
+        LinkedHashMap<String, String> patternMap = new LinkedHashMap<String, String>() {
+            {
+                put(exactMatch, exactMatchFilter);
+                put("/*", defaultFilter);
+                put("*.jsp", jspFilter);
+                put("/foo/*", prefixFilter);
+            }
+        };
+        urlMatcher = new UrlMatcher<>(patternMap);
+        assertMatches("/abc", defaultFilter);
+        assertMatches(exactMatch, exactMatchFilter, defaultFilter);
+        assertMatches("/some.jsp", defaultFilter, jspFilter);
+        assertMatches("/foo/bar", defaultFilter, prefixFilter);
+        assertMatches("/foo/bar.jsp", defaultFilter, jspFilter, prefixFilter);
+    }
+
+    public void assertMatches(String testedPath, String... filters) {
+        assertEquals(asList(filters), urlMatcher.findMatchingFilters(testedPath));
+    }
+
+}