Merge changes I52c2aaab,I2509ed5e,Ic1d8a4e5,I73730f79,Ica1959e5,I0ce61b07
[controller.git] / opendaylight / commons / filter-valve / src / test / java / org / opendaylight / controller / filtervalve / cors / model / UrlMatcherTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.filtervalve.cors.model;
10
11 import static java.util.Arrays.asList;
12 import static org.junit.Assert.assertEquals;
13
14 import java.util.LinkedHashMap;
15 import org.junit.Test;
16
17 public class UrlMatcherTest {
18     UrlMatcher<String> urlMatcher;
19
20     @Test
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);
38     }
39
40     public void assertMatches(String testedPath, String... filters) {
41         assertEquals(asList(filters), urlMatcher.findMatchingFilters(testedPath));
42     }
43
44 }