1
|
/**
|
2
|
* Copyright (C) 2021 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.common;
|
10
|
|
11
|
import java.net.URISyntaxException;
|
12
|
|
13
|
import org.junit.Assert;
|
14
|
import org.junit.Test;
|
15
|
|
16
|
/**
|
17
|
* @author a.mueller
|
18
|
* @since 05.01.2021
|
19
|
*/
|
20
|
public class UriTest {
|
21
|
|
22
|
@Test
|
23
|
public void test() {
|
24
|
try {
|
25
|
//see example in #9111
|
26
|
URI uri = new URI("https://bioone.org/journals/Cactus-and-Succulent-Journal/volume-78/issue-2/0007-9367(2006)78[66:FKASLA]2.0.CO;2/Finders-Keepers-and-some-Lavranian-Adjustments-in-Mesembryanthema/10.2985/0007-9367(2006)78[66:FKASLA]2.0.CO;2.full");
|
27
|
Assert.assertEquals(
|
28
|
"/journals/Cactus-and-Succulent-Journal/volume-78/issue-2/0007-9367(2006)78[66:FKASLA]2.0.CO;2/Finders-Keepers-and-some-Lavranian-Adjustments-in-Mesembryanthema/10.2985/0007-9367(2006)78[66:FKASLA]2.0.CO;2.full",
|
29
|
uri.getPath());
|
30
|
|
31
|
} catch (URISyntaxException e) {
|
32
|
Assert.fail("Parsing example URI from #9111 should not throw exception");
|
33
|
}
|
34
|
|
35
|
try {
|
36
|
//see example in #9111
|
37
|
URI uri = new URI("http:\\www.fail.de");
|
38
|
Assert.fail("Using backslash in URI instead of slash should fail");
|
39
|
} catch (URISyntaxException e) {
|
40
|
//OK
|
41
|
}
|
42
|
|
43
|
}
|
44
|
|
45
|
@Test
|
46
|
public void testFragment() {
|
47
|
try {
|
48
|
//see example in #9111
|
49
|
URI uri = new URI("https://max:muster@www.example.com:8080/index.html?p1=A&p2=B#ressource");
|
50
|
Assert.assertEquals(
|
51
|
"ressource",
|
52
|
uri.getFragment());
|
53
|
|
54
|
uri = new URI("https://max:muster@www.example.com:8080/index.html?p1=A&p2=B#ressource&#another-frag?");
|
55
|
Assert.assertEquals(
|
56
|
"ressource&#another-frag?",
|
57
|
uri.getFragment());
|
58
|
} catch (URISyntaxException e) {
|
59
|
Assert.fail("Parsing example URI should find fragment");
|
60
|
}
|
61
|
|
62
|
try {
|
63
|
//see example in #9111
|
64
|
URI uri = new URI("http:\\www.fail.de");
|
65
|
Assert.fail("Using backslash in URI instead of slash should fail");
|
66
|
} catch (URISyntaxException e) {
|
67
|
//OK
|
68
|
}
|
69
|
|
70
|
}
|
71
|
|
72
|
}
|