-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathClientBuilderTest.java
More file actions
34 lines (27 loc) · 1.18 KB
/
ClientBuilderTest.java
File metadata and controls
34 lines (27 loc) · 1.18 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
package com.clickhouse.client.api;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.lang.reflect.Field;
import java.util.List;
public class ClientBuilderTest {
@Test
public void testAddEndpointToleratesUnderscoreHostname() throws Exception {
try (Client client = new Client.Builder()
.addEndpoint("http://host_with_underscore:8123")
.setUsername("default")
.setPassword("")
.build()) {
String firstEndpoint = extractFirstEndpointUri(client);
Assert.assertEquals(firstEndpoint, "http://host_with_underscore:8123/",
"Endpoint URI should preserve original hostname");
}
}
private static String extractFirstEndpointUri(Client client) throws Exception {
Field endpointsField = Client.class.getDeclaredField("endpoints");
endpointsField.setAccessible(true);
@SuppressWarnings("unchecked")
List<com.clickhouse.client.api.transport.Endpoint> endpoints =
(List<com.clickhouse.client.api.transport.Endpoint>) endpointsField.get(client);
return endpoints.get(0).getURI().toString();
}
}