|
9 | 9 |
|
10 | 10 | import java.net.URI;
|
11 | 11 |
|
| 12 | +import static org.elasticsearch.xpack.sql.client.UriUtils.appendSegmentToPath; |
12 | 13 | import static org.elasticsearch.xpack.sql.client.UriUtils.parseURI;
|
13 | 14 | import static org.elasticsearch.xpack.sql.client.UriUtils.removeQuery;
|
14 | 15 |
|
@@ -84,4 +85,56 @@ public void testRemoveQueryNoQuery() throws Exception {
|
84 | 85 | assertEquals(URI.create("http://server:9100"),
|
85 | 86 | removeQuery(URI.create("http://server:9100"), "http://server:9100", DEFAULT_URI));
|
86 | 87 | }
|
| 88 | + |
| 89 | + public void testAppendEmptySegmentToPath() throws Exception { |
| 90 | + assertEquals(URI.create("http://server:9100"), |
| 91 | + appendSegmentToPath(URI.create("http://server:9100"), "")); |
| 92 | + } |
| 93 | + |
| 94 | + public void testAppendNullSegmentToPath() throws Exception { |
| 95 | + assertEquals(URI.create("http://server:9100"), |
| 96 | + appendSegmentToPath(URI.create("http://server:9100"), null)); |
| 97 | + } |
| 98 | + |
| 99 | + public void testAppendSegmentToNullPath() throws Exception { |
| 100 | + assertEquals( |
| 101 | + "URI must not be null", |
| 102 | + expectThrows(IllegalArgumentException.class, () -> appendSegmentToPath(null, "/_sql")).getMessage() |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + public void testAppendSegmentToEmptyPath() throws Exception { |
| 107 | + assertEquals(URI.create("/_sql"), |
| 108 | + appendSegmentToPath(URI.create(""), "/_sql")); |
| 109 | + } |
| 110 | + |
| 111 | + public void testAppendSlashSegmentToPath() throws Exception { |
| 112 | + assertEquals(URI.create("http://server:9100"), |
| 113 | + appendSegmentToPath(URI.create("http://server:9100"), "/")); |
| 114 | + } |
| 115 | + |
| 116 | + public void testAppendSqlSegmentToPath() throws Exception { |
| 117 | + assertEquals(URI.create("http://server:9100/_sql"), |
| 118 | + appendSegmentToPath(URI.create("http://server:9100"), "/_sql")); |
| 119 | + } |
| 120 | + |
| 121 | + public void testAppendSqlSegmentNoSlashToPath() throws Exception { |
| 122 | + assertEquals(URI.create("http://server:9100/_sql"), |
| 123 | + appendSegmentToPath(URI.create("http://server:9100"), "_sql")); |
| 124 | + } |
| 125 | + |
| 126 | + public void testAppendSegmentToPath() throws Exception { |
| 127 | + assertEquals(URI.create("http://server:9100/es_rest/_sql"), |
| 128 | + appendSegmentToPath(URI.create("http://server:9100/es_rest"), "/_sql")); |
| 129 | + } |
| 130 | + |
| 131 | + public void testAppendSegmentNoSlashToPath() throws Exception { |
| 132 | + assertEquals(URI.create("http://server:9100/es_rest/_sql"), |
| 133 | + appendSegmentToPath(URI.create("http://server:9100/es_rest"), "_sql")); |
| 134 | + } |
| 135 | + |
| 136 | + public void testAppendSegmentTwoSlashesToPath() throws Exception { |
| 137 | + assertEquals(URI.create("https://server:9100/es_rest/_sql"), |
| 138 | + appendSegmentToPath(URI.create("https://server:9100/es_rest/"), "/_sql")); |
| 139 | + } |
87 | 140 | }
|
0 commit comments