2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.filtervalve.cors.model;
11 import static java.util.Arrays.asList;
12 import static org.junit.Assert.assertEquals;
14 import java.util.LinkedHashMap;
15 import org.junit.Test;
17 public class UrlMatcherTest {
18 UrlMatcher<String> urlMatcher;
21 public void test() throws Exception {
22 final String defaultFilter = "default";
23 final String exactMatchFilter = "someFilter";
24 final String jspFilter = "jspFilter";
25 final String exactMatch = "/somePath";
26 final String prefixFilter = "prefixFilter";
27 LinkedHashMap<String, String> patternMap = new LinkedHashMap<>();
28 patternMap.put(exactMatch, exactMatchFilter);
29 patternMap.put("/*", defaultFilter);
30 patternMap.put("*.jsp", jspFilter);
31 patternMap.put("/foo/*", prefixFilter);
32 urlMatcher = new UrlMatcher<>(patternMap);
33 assertMatches("/abc", defaultFilter);
34 assertMatches(exactMatch, exactMatchFilter, defaultFilter);
35 assertMatches("/some.jsp", defaultFilter, jspFilter);
36 assertMatches("/foo/bar", defaultFilter, prefixFilter);
37 assertMatches("/foo/bar.jsp", defaultFilter, jspFilter, prefixFilter);
40 public void assertMatches(String testedPath, String... filters) {
41 assertEquals(asList(filters), urlMatcher.findMatchingFilters(testedPath));