} catch (IllegalArgumentException e) {
} // ok
}
public void testEncodedUri() {
UriTemplateProcessor template1 =
new BitWorkingUriTemplateProcessor("cars(old*new:good)my?{-join|&|car1,car2}");
String[][] carsDefined = { {"car1", "Ford"}, {"car2", "Opel"}};
assertMatchTemplate(template1, "cars(old*new:good)my?car1=Ford&car2=Opel", carsDefined);
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("car1", "Ford");
hashMap.put("car2", "Opel");
assertEquals("instantiate template1", "cars(old*new:good)my?car1=Ford&car2=Opel", template1
.expand(hashMap));
UriTemplateProcessor template2 =
new BitWorkingUriTemplateProcessor("vegetables|{-list|?|vegs}");
String[][] vegsDefined = {{"vegs", "carrot", "leek"}};
assertMatchTemplate(template2, "vegetables|carrot?leek", vegsDefined);
hashMap = new HashMap<String, Object>();
hashMap.put("vegs", new String[] {"carrot", "leek"});
assertEquals("instantiate template2", "vegetables|carrot?leek", template2.expand(hashMap));
UriTemplateProcessor template3 =
new BitWorkingUriTemplateProcessor("vegetables{-prefix|?|vegs}");
assertMatchTemplate(template3, "vegetables?carrot?leek", vegsDefined);
hashMap = new HashMap<String, Object>();
hashMap.put("vegs", new String[] {"carrot", "leek"});
assertEquals("instantiate template3", "vegetables?carrot?leek", template3.expand(hashMap));
UriTemplateProcessor template4 =
new BitWorkingUriTemplateProcessor("vegetables|{-suffix|?|vegs}");
assertMatchTemplate(template4, "vegetables|carrot?leek?", vegsDefined);
hashMap = new HashMap<String, Object>();
hashMap.put("vegs", new String[] {"carrot", "leek"});
assertEquals("instantiate template4", "vegetables|carrot?leek?", template4.expand(hashMap));
UriTemplateProcessor template5 =
new BitWorkingUriTemplateProcessor("translator({-join|?|czech,english})");
String[][] translation = { {"czech", "pes"}, {"english", "dog"}};
assertMatchTemplate(template5, "translator(english=dog?czech=pes)", translation);
hashMap = new HashMap<String, Object>();
hashMap.put("english", "dog");
hashMap.put("czech", "pes");
assertEquals("instantiate template5", "translator(czech=pes?english=dog)", template5
.expand(hashMap));
UriTemplateProcessor template6 =
new BitWorkingUriTemplateProcessor("food{-opt|?|meat,milk}");
String[][] empty = {};
assertMatchTemplate(template6, "food?", empty);
hashMap = new HashMap<String, Object>();
hashMap.put("meat", "poultry");
assertEquals("instantiate template6", "food?", template6.expand(hashMap));
UriTemplateProcessor template7 =
new BitWorkingUriTemplateProcessor("food{-neg|()|meat,milk}");
assertMatchTemplate(template7, "food()", empty);
hashMap = new HashMap<String, Object>();
assertEquals("instantiate template7", "food()", template7.expand(hashMap));
}