all);
}
public void testListOperator() {
UriTemplateProcessor template1 =
new BitWorkingUriTemplateProcessor("locations/{-list|/|var}");
UriTemplateProcessor template2 =
new BitWorkingUriTemplateProcessor("locations{-opt|/|var}{-list|/|var}");
UriTemplateProcessor template3 =
new BitWorkingUriTemplateProcessor("telegram:{-list|stop|var}");
String[][] empty = {{"var", ""}};
String[][] a = {{"var", "a"}};
String[][] ab = {{"var", "a", "b"}};
String[][] ab_ = {{"var", "a", "b", ""}};
String[][] a_c = {{"var", "a", "", "c"}};
String[][] _bc = {{"var", "", "b", "c"}};
String[][] message = {{"var", "hello", "baby", "go", "home"}};
assertMatchTemplate(template1, "locations", null);
assertMatchTemplate(template2, "locations", empty);
assertMatchTemplate(template1, "locations/", empty);
assertMatchTemplate(template2, "locations/", empty);
assertMatchTemplate(template1, "locations/a", a);
assertMatchTemplate(template2, "locations/a", a);
assertMatchTemplate(template1, "locations/a/b", ab);
assertMatchTemplate(template2, "locations/a/b", ab);
assertMatchTemplate(template2, "locations/a/b/", ab_);
assertMatchTemplate(template2, "locations/a//c", a_c);
assertMatchTemplate(template2, "locations//b/c", _bc);
assertMatchTemplate(template3, "telegram:hellostopbabystopgostophome", message);
try {
new BitWorkingUriTemplateProcessor("locations/{-list|/|var1,var2}");
fail("only one variable is allowed");
} catch (IllegalArgumentException expected) {
}
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {});
assertEquals("instantiate template1", "locations/", template1.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {});
assertEquals("instantiate template2", "locations", template2.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"d"});
assertEquals("instantiate template1", "locations/d", template1.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"d"});
assertEquals("instantiate template2", "locations/d", template2.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"d", "e"});
assertEquals("instantiate template1", "locations/d/e", template1.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"d", "e"});
assertEquals("instantiate template2", "locations/d/e", template2.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"d", "", "e"});
assertEquals("instantiate template1", "locations/d//e", template1.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"d", "", "e"});
assertEquals("instantiate template2", "locations/d//e", template2.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"", "d", "e"});
assertEquals("instantiate template1", "locations//d/e", template1.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"", "d", "e"});
assertEquals("instantiate template2", "locations//d/e", template2.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"d", "e", ""});
assertEquals("instantiate template1", "locations/d/e/", template1.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"d", "e", ""});
assertEquals("instantiate template2", "locations/d/e/", template2.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", new String[] {"hello", "baby", "go", "home"});
assertEquals("instantiate template3", "telegram:hellostopbabystopgostophome", template3
.expand(hashMap));
hashMap = new HashMap<String, Object>();
hashMap.put("var", "value");
assertEquals("instantiate template1", "locations/value", template1.expand(hashMap));
}