Beispiel #1
0
 @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));
 }
Beispiel #2
0
 @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));
 }
Beispiel #3
0
 @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);
 }
Beispiel #4
0
 @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));
 }
Beispiel #5
0
 @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);
 }
Beispiel #6
0
 @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));
 }
Beispiel #7
0
 @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));
 }
Beispiel #8
0
 @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));
 }
Beispiel #9
0
 @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));
 }
Beispiel #10
0
 @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);
 }
Beispiel #11
0
 @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));
 }