Test for VitroURL.
This commit is contained in:
parent
2de267af6b
commit
ddd285aab9
1 changed files with 137 additions and 0 deletions
|
@ -0,0 +1,137 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.filters;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
public class VitroURLTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of beginsWithSlash method, of class VitroURL.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testBeginsWithSlash()
|
||||||
|
{
|
||||||
|
String pathStr = "entity?home=1&uri=http://aims.fao.org/aos/geopolitical.owl#Afghanistan";
|
||||||
|
VitroURL instance = new VitroURL("", "UTF-8");
|
||||||
|
boolean expResult = false;
|
||||||
|
boolean result = instance.beginsWithSlash(pathStr);
|
||||||
|
assertEquals(expResult, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of endsInSlash method, of class VitroURL.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testEndsInSlash()
|
||||||
|
{
|
||||||
|
String pathStr = "/entity?home=1&uri=http://aims.fao.org/aos/geopolitical.owl#Afghanistan";
|
||||||
|
VitroURL instance = new VitroURL("", "UTF-8");
|
||||||
|
boolean expResult = false;
|
||||||
|
boolean result = instance.endsInSlash(pathStr);
|
||||||
|
assertEquals(expResult, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of toString method, of class VitroURL.
|
||||||
|
* This test includes a Individual URI with a '=' and a '?'
|
||||||
|
* This test is from David Cliff via sourceforge.
|
||||||
|
* It isn't clear if the double URLencoding is correct.
|
||||||
|
*/
|
||||||
|
// @Test
|
||||||
|
// public void testToString()
|
||||||
|
// {
|
||||||
|
// String MelbUniStr = "/entity?home=1&uri=HTTPS://bida.themis.unimelb.edu.au/pls/apex/f?p=mrw2rdf:org:::::org_id:145";
|
||||||
|
// VitroURL instance = new VitroURL(MelbUniStr, "UTF-8");
|
||||||
|
// String expResult = "/entity?home=1&uri=HTTPS%253A%252F%252Fbida.themis.unimelb.edu.au%252Fpls%252Fapex%252Ff%253Fp%253Dmrw2rdf%253Aorg%253A%253A%253A%253A%253Aorg_id%253A145";
|
||||||
|
// String result = instance.toString();
|
||||||
|
// assertEquals(expResult, result);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a test similar to testToString()
|
||||||
|
* in that it has a = and a ? but it doesn't
|
||||||
|
* expect a double encoded URI.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testWithEqualsSign(){
|
||||||
|
String MelbUniStr = "/entity?home=1&uri=HTTPS://bida.themis.unimelb.edu.au/pls/apex/f?p=mrw2rdf:org:::::org_id:145";
|
||||||
|
VitroURL instance = new VitroURL(MelbUniStr, "UTF-8");
|
||||||
|
String expResult ="/entity?home=1&uri=HTTPS%3A%2F%2Fbida.themis.unimelb.edu.au%2Fpls%2Fapex%2Ff%3Fp%3Dmrw2rdf%3Aorg%3A%3A%3A%3A%3Aorg_id%3A145";
|
||||||
|
assertEquals(expResult, instance.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseQueryParams(){
|
||||||
|
//parseQueryParams
|
||||||
|
VitroURL instance = new VitroURL("stringNotImportant", "UTF-8");
|
||||||
|
List<String[]> result = instance.parseQueryParams("uri=HTTPS://bida.themis.unimelb.edu.au/pls/apex/f?p=mrw2rdf:org:::::org_id:145");
|
||||||
|
Assert.assertNotNull(result);
|
||||||
|
Assert.assertEquals(1, result.size());
|
||||||
|
Assert.assertNotNull(result.get(0));
|
||||||
|
Assert.assertEquals(2, result.get(0).length);
|
||||||
|
Assert.assertEquals("uri",result.get(0)[0]);
|
||||||
|
Assert.assertEquals("HTTPS://bida.themis.unimelb.edu.au/pls/apex/f?p=mrw2rdf:org:::::org_id:145",result.get(0)[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseQueryParams2(){
|
||||||
|
//parseQueryParams
|
||||||
|
VitroURL instance = new VitroURL("stringNotImportant", "UTF-8");
|
||||||
|
List<String[]> result = instance.parseQueryParams("home=1&uri=HTTPS://bida.themis.unimelb.edu.au/pls/apex/f?p=mrw2rdf:org:::::org_id:145");
|
||||||
|
Assert.assertNotNull(result);
|
||||||
|
Assert.assertEquals(2, result.size());
|
||||||
|
|
||||||
|
Assert.assertNotNull(result.get(0));
|
||||||
|
Assert.assertEquals(2, result.get(0).length);
|
||||||
|
Assert.assertEquals("home",result.get(0)[0]);
|
||||||
|
Assert.assertEquals("1",result.get(0)[1]);
|
||||||
|
|
||||||
|
Assert.assertNotNull(result.get(1));
|
||||||
|
Assert.assertEquals(2, result.get(1).length);
|
||||||
|
Assert.assertEquals("uri",result.get(1)[0]);
|
||||||
|
Assert.assertEquals("HTTPS://bida.themis.unimelb.edu.au/pls/apex/f?p=mrw2rdf:org:::::org_id:145",result.get(1)[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseQueryParams3(){
|
||||||
|
//parseQueryParams
|
||||||
|
VitroURL instance = new VitroURL("stringNotImportant", "UTF-8");
|
||||||
|
List<String[]> result = instance.parseQueryParams("home=1&uri=HTTPS://bida.edu.au/pls/apex/f?p=mrw2&additiona=234");
|
||||||
|
Assert.assertNotNull(result);
|
||||||
|
Assert.assertEquals(2, result.size());
|
||||||
|
|
||||||
|
Assert.assertNotNull(result.get(0));
|
||||||
|
Assert.assertEquals(2, result.get(0).length);
|
||||||
|
Assert.assertEquals("home",result.get(0)[0]);
|
||||||
|
Assert.assertEquals("1",result.get(0)[1]);
|
||||||
|
|
||||||
|
Assert.assertNotNull(result.get(1));
|
||||||
|
Assert.assertEquals(2, result.get(1).length);
|
||||||
|
Assert.assertEquals("uri",result.get(1)[0]);
|
||||||
|
Assert.assertEquals("HTTPS://bida.edu.au/pls/apex/f?p=mrw2&additiona=234",result.get(1)[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test (expected=Error.class)
|
||||||
|
public void testParseQueryParams4(){
|
||||||
|
//parseQueryParams
|
||||||
|
VitroURL instance = new VitroURL("stringNotImportant", "UTF-8");
|
||||||
|
List<String[]> result = instance.parseQueryParams("home=1&shouldBeURI=HTTPS://bida.edu.au/pls/apex/f?p=mrw2&additiona=234");
|
||||||
|
Assert.assertNotNull(result);
|
||||||
|
Assert.assertEquals(2, result.size());
|
||||||
|
|
||||||
|
Assert.assertNotNull(result.get(0));
|
||||||
|
Assert.assertEquals(2, result.get(0).length);
|
||||||
|
Assert.assertEquals("home",result.get(0)[0]);
|
||||||
|
Assert.assertEquals("1",result.get(0)[1]);
|
||||||
|
|
||||||
|
Assert.assertNotNull(result.get(1));
|
||||||
|
Assert.assertEquals(2, result.get(1).length);
|
||||||
|
Assert.assertEquals("uri",result.get(1)[0]);
|
||||||
|
Assert.assertEquals("HTTPS://bida.edu.au/pls/apex/f?p=mrw2&additiona=234",result.get(1)[1]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue