Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ca.nrc.cadc.ac;
import java.net.URISyntaxException;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;
import ca.nrc.cadc.util.Log4jInit;
public class GroupURITest
{
private static Logger log = Logger.getLogger(GroupURITest.class);
static
{
Log4jInit.setLevel("ca.nrc.cadc.ac", Level.INFO);
}
@Test
public void testMalformed()
{
try
{
// wrong scheme
assertIllegalArgument("iko://cadc.nrc.ca/gms?gname", "scheme");
// fragment instead of query
assertIllegalArgument("ivo://cadc.nrc.ca/gms#gname", "fragment");
// no authority
assertIllegalArgument("ivo://gms?gname", "authority");
// extended path in group
assertIllegalArgument("ivo://cadc.nrc.ca/gms/path?gname", "path");
}
catch (Throwable t)
{
log.error("Test Failed", t);
Assert.fail();
}
}
@Test
public void testCorrect()
{
try
{
GroupURI g = new GroupURI("ivo://my.authority/gms?name");
Assert.assertEquals("ivo", g.getURI().getScheme());
Assert.assertEquals("my.authority", g.getAuthority());
Assert.assertEquals("/gms", g.getURI().getPath());
Assert.assertEquals("name", g.getName());
Assert.assertEquals("ivo://my.authority/gms", g.getServiceID().toString());
}
catch (Throwable t)
{
log.error("Test Failed", t);
}
}
private void assertIllegalArgument(String uri, String message) throws URISyntaxException
{
try
{
new GroupURI(uri);
Assert.fail("Expected Illegal argument for URI " + uri);
}
catch (IllegalArgumentException e)
{
// expected
log.debug("Checking if message '" + e.getMessage() + "' contains '" + message + "'");
Assert.assertTrue(e.getMessage().toLowerCase().contains(message));
}
}
}