forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUriPrefixerTest.java
More file actions
72 lines (59 loc) · 2.72 KB
/
Copy pathUriPrefixerTest.java
File metadata and controls
72 lines (59 loc) · 2.72 KB
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
/*
* Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata;
import org.springframework.web.util.UriComponentsBuilder;
import org.testng.annotations.Test;
import java.net.URI;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class UriPrefixerTest {
@Test
public void testMergeUrisWithSlash() throws Exception {
final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads");
final URI result = prefixer.mergeUris("/test");
assertThat(result.toString(), is("http://localhost:1/uploads/test"));
}
@Test
public void testMergeUrisWithSlashes() throws Exception {
final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads/");
final URI result = prefixer.mergeUris("/test");
assertThat(result.toString(), is("http://localhost:1/uploads/test"));
}
@Test
public void testMergeUrisWithAllSlashes() throws Exception {
final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads/");
final URI result = prefixer.mergeUris("/test/");
assertThat(result.toString(), is("http://localhost:1/uploads/test/"));
}
@Test
public void testMergeUrisWithoutSlash() throws Exception {
final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads/");
final URI result = prefixer.mergeUris("test");
assertThat(result.toString(), is("http://localhost:1/uploads/test"));
}
@Test
public void testMergeUrisWithoutSlashes() throws Exception {
final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads");
final URI result = prefixer.mergeUris("test");
assertThat(result.toString(), is("http://localhost:1/uploads/test"));
}
@Test
public void shouldNotDoubleEncodeQueryParam() throws Exception {
final UriPrefixer prefixer = new UriPrefixer("http://localhost:1/uploads");
final URI uri = UriComponentsBuilder.fromPath("/foo")
.queryParam("bar", "\n") // some crazy value which needs encoding
.build()
.toUri();
final URI result = prefixer.mergeUris(uri);
assertThat(result.toString(), is("http://localhost:1/uploads/foo?bar=%0A"));
}
@Test
public void shouldName() throws Exception {
final UriPrefixer prefixer = new UriPrefixer("https://localhost:1");
final URI result = prefixer.mergeUris("http://localhost:1/uploads/test/");
assertThat(result.toString(), is("https://localhost:1/uploads/test/"));
}
}