}
public void testGetFormattedLocation() {
String origLoc = "/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}";
HTTPLocation loc;
loc = new HTTPLocation(origLoc);
HTTPLocationTemplate template;
HTTPLocationTemplate[] templates;
templates = loc.getTemplates("town");
templates[0].setValue("Perth");
template = loc.getTemplate("state");
template.setValue("WA");
template = loc.getTemplate("country");
template.setValue("Australia");
template = loc.getTemplate("tmp");
template.setValue("41.5");
template = loc.getTemplate("mth");
template.setValue("February");
template = loc.getTemplate("dt");
template.setValue("28th");
templates[1].setValue("Fremantle");
String formattedLoc = "/temperature/Perth/WA/Australia?temp=41.5&month=February&date=28th&place=Fremantle";
String returnedLoc = loc.getFormattedLocation();
assertEquals("Unexpected formatted location value", formattedLoc, returnedLoc);
origLoc = "/temperature/{town}/{!state}/{country}?temp={tmp}&month={mth}&date={!dt}&place={town}";
loc = new HTTPLocation(origLoc);
templates = loc.getTemplates("town");
//templates[0].setValue("Perth"); //if {town} is not substituted, it will be replaced by empty string
template = loc.getTemplate("state");
template.setValue("WA");
template = loc.getTemplate("country");
template.setValue("Australia");
template = loc.getTemplate("tmp");
template.setValue("41.5");
template = loc.getTemplate("mth");
template.setValue("February");
template = loc.getTemplate("dt");
//template.setValue("28th"); //if {!dt} is not substituted, it will be replaced by empty string
templates[1].setValue("Fremantle");
formattedLoc = "/temperature//WA/Australia?temp=41.5&month=February&date=&place=Fremantle";
returnedLoc = loc.getFormattedLocation();
assertEquals("Unexpected formatted location value", formattedLoc, returnedLoc);
origLoc = "/travel/flight?no=BA6&dep=13.55";
loc = new HTTPLocation(origLoc);
returnedLoc = loc.getFormattedLocation();
assertEquals("Unexpected location value", origLoc, returnedLoc);
origLoc = "{invalid:name}";
loc = new HTTPLocation(origLoc);
returnedLoc = loc.getFormattedLocation();
assertNull("Location is invalid, so null was expected", returnedLoc);
}