@Test public void testSubstituteMapSameVarWithPattern() throws Exception { URITemplate ut = new URITemplate("/foo/{a}/{a:\\d}"); Map<String, String> map = new HashMap<String, String>(); map.put("a", "0"); assertEquals("Wrong substitution", "/foo/0/0", ut.substitute(map)); }
@Test public void testNestedCurlyBraces() { URITemplate ut = new URITemplate("/foo/{hex:[0-9a-fA-F]{2}}"); Map<String, String> map = new HashMap<String, String>(); map.put("hex", "FF"); assertEquals("Wrong substitution", "/foo/FF", ut.substitute(map)); }
@Test(expected = IllegalArgumentException.class) public void testSubstituteMapSameVarWithPatternFail() throws Exception { URITemplate ut = new URITemplate("/foo/{a}/{a:\\d}"); Map<String, String> map = new HashMap<String, String>(); map.put("a", "not-a-digit"); ut.substitute(map); }
@Test public void testSubstituteMapSameVars() throws Exception { URITemplate ut = new URITemplate("/foo/{a}/{a}/{a}"); Map<String, String> map = new HashMap<String, String>(); map.put("a", "bar"); assertEquals("Wrong substitution", "/foo/bar/bar/bar", ut.substitute(map)); }
@Test(expected = IllegalArgumentException.class) public void testSubstituteMapIncomplete() throws Exception { URITemplate ut = new URITemplate("/foo/{a}/{b}/{a:\\d}"); Map<String, String> map = new HashMap<String, String>(); map.put("b", "bar"); ut.substitute(map); }
@Test public void testSubstituteMapExceeding() throws Exception { URITemplate ut = new URITemplate("/foo/{a}"); Map<String, String> map = new HashMap<String, String>(); map.put("b", "baz"); map.put("a", "blah"); assertEquals("Wrong substitution", "/foo/blah", ut.substitute(map)); }
@Test public void testSubstituteMap() throws Exception { URITemplate ut = new URITemplate("/foo/{a}/{b:\\d\\d}/{c}"); Map<String, String> map = new HashMap<String, String>(); map.put("c", "foo"); map.put("b", "11"); map.put("a", "bar"); assertEquals("Wrong substitution", "/foo/bar/11/foo", ut.substitute(map)); }
@Test public void testSubstituteListExceeding() throws Exception { URITemplate ut = new URITemplate("/foo/{a}/{b}"); List<String> list = Arrays.asList("bar", "baz", "blah"); assertEquals("Wrong substitution", "/foo/bar/baz", ut.substitute(list)); }
@Test public void testSubstituteListIncomplete() throws Exception { URITemplate ut = new URITemplate("/foo/{a}/{c}/{b}/{d:\\w}"); List<String> list = Arrays.asList("bar", "baz"); assertEquals("Wrong substitution", "/foo/bar/baz/{b}/{d:\\w}", ut.substitute(list)); }
@Test(expected = IllegalArgumentException.class) public void testSubstituteListWrongPattern() throws Exception { URITemplate ut = new URITemplate("/foo/{b:\\d\\d}"); List<String> list = Arrays.asList("foo", "not-two-digits"); ut.substitute(list); }
@Test public void testSubstituteList() throws Exception { URITemplate ut = new URITemplate("/foo/{a}/{b:\\d\\d}/{c}"); List<String> list = Arrays.asList("foo", "99", "baz"); assertEquals("Wrong substitution", "/foo/foo/99/baz", ut.substitute(list)); }