1 /** 2 * Copyright (C) 2014 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18 package com.google.inject.servlet; 19 20 import junit.framework.TestCase; 21 22 public class UriPatternTypeTest extends TestCase { 23 testMatches_servlet()24 public void testMatches_servlet() { 25 UriPatternMatcher pattern = UriPatternType.get(UriPatternType.SERVLET, "/foo/*"); 26 assertTrue(pattern.matches("/foo/asdf")); 27 assertTrue(pattern.matches("/foo/asdf?val=1")); 28 assertFalse(pattern.matches("/path/file.bar")); 29 assertFalse(pattern.matches("/path/file.bar?val=1")); 30 assertFalse(pattern.matches("/asdf")); 31 assertFalse(pattern.matches("/asdf?val=1")); 32 33 pattern = UriPatternType.get(UriPatternType.SERVLET, "*.bar"); 34 assertFalse(pattern.matches("/foo/asdf")); 35 assertFalse(pattern.matches("/foo/asdf?val=1")); 36 assertTrue(pattern.matches("/path/file.bar")); 37 assertTrue(pattern.matches("/path/file.bar?val=1")); 38 assertFalse(pattern.matches("/asdf")); 39 assertFalse(pattern.matches("/asdf?val=1")); 40 41 pattern = UriPatternType.get(UriPatternType.SERVLET, "/asdf"); 42 assertFalse(pattern.matches("/foo/asdf")); 43 assertFalse(pattern.matches("/foo/asdf?val=1")); 44 assertFalse(pattern.matches("/path/file.bar")); 45 assertFalse(pattern.matches("/path/file.bar?val=1")); 46 assertTrue(pattern.matches("/asdf")); 47 assertTrue(pattern.matches("/asdf?val=1")); 48 } 49 testMatches_regex()50 public void testMatches_regex() { 51 UriPatternMatcher pattern = UriPatternType.get(UriPatternType.REGEX, "/.*/foo"); 52 assertFalse(pattern.matches("/foo/asdf")); 53 assertFalse(pattern.matches("/foo/asdf?val=1")); 54 assertTrue(pattern.matches("/path/foo")); 55 assertTrue(pattern.matches("/path/foo?val=1")); 56 assertFalse(pattern.matches("/foo")); 57 assertFalse(pattern.matches("/foo?val=1")); 58 } 59 } 60