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
78
79
80
81
82
83
84
85
86
87
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
*/
public class BundleLocationResolverTestCase {
@Test
public void requireThatDollarsAreIncludedInLocation() {
assertLocation("scheme:$foo", "scheme:$foo");
assertLocation("scheme:foo$bar", "scheme:foo$bar");
}
@Test
public void requireThatCurlyBracesAreIncludedInLocation() {
assertLocation("scheme:{foo", "scheme:{foo");
assertLocation("scheme:foo{", "scheme:foo{");
assertLocation("scheme:foo{bar", "scheme:foo{bar");
assertLocation("scheme:}foo", "scheme:}foo");
assertLocation("scheme:foo}", "scheme:foo}");
assertLocation("scheme:foo}bar", "scheme:foo}bar");
assertLocation("scheme:{foo}bar", "scheme:{foo}bar");
assertLocation("scheme:foo{bar}", "scheme:foo{bar}");
}
@Test
public void requireThatUnterminatedPropertiesAreIncludedInLocation() {
assertLocation("scheme:${foo", "scheme:${foo");
assertLocation("scheme:foo${", "scheme:foo${");
assertLocation("scheme:foo${bar", "scheme:foo${bar");
}
@Test
public void requireThatAllSystemPropertiesAreExpanded() throws IOException {
assertCanonicalPath("", "${foo}");
assertCanonicalPath("barcox", "${foo}bar${baz}cox");
assertCanonicalPath("foobaz", "foo${bar}baz${cox}");
System.setProperty("requireThatAllSystemPropertiesAreExpanded.foo", "FOO");
System.setProperty("requireThatAllSystemPropertiesAreExpanded.bar", "BAR");
System.setProperty("requireThatAllSystemPropertiesAreExpanded.baz", "BAZ");
System.setProperty("requireThatAllSystemPropertiesAreExpanded.cox", "COX");
assertCanonicalPath("FOO", "${requireThatAllSystemPropertiesAreExpanded.foo}");
assertCanonicalPath("FOObarBAZcox", "${requireThatAllSystemPropertiesAreExpanded.foo}bar" +
"${requireThatAllSystemPropertiesAreExpanded.baz}cox");
assertCanonicalPath("fooBARbazCOX", "foo${requireThatAllSystemPropertiesAreExpanded.bar}" +
"baz${requireThatAllSystemPropertiesAreExpanded.cox}");
}
@Test
public void requireThatUnschemedLocationsAreExpandedToBundleLocationProperty() throws IOException {
assertCanonicalPath(BundleLocationResolver.BUNDLE_PATH + "foo", "foo");
}
@Test
public void requireThatFileSchemedLocationsAreCanonicalized() throws IOException {
assertCanonicalPath("", "file:");
assertCanonicalPath("foo", "file:foo");
assertCanonicalPath("foo", "file:./foo");
assertCanonicalPath("foo/bar", "file:foo/bar");
assertCanonicalPath("foo/bar", "file:./foo/../foo/./bar");
assertCanonicalPath("foo", " \f\n\r\tfile:foo");
}
@Test
public void requireThatOtherSchemedLocationsAreUntouched() {
assertLocation("foo:", "foo:");
assertLocation("foo:bar", "foo:bar");
assertLocation("foo:bar/baz", "foo:bar/baz");
}
private static void assertCanonicalPath(String expected, String bundleLocation) throws IOException {
assertLocation("file:" + new File(expected).getCanonicalPath(), bundleLocation);
}
private static void assertLocation(String expected, String bundleLocation) {
assertEquals(expected, BundleLocationResolver.resolve(bundleLocation));
}
}
|