-
Notifications
You must be signed in to change notification settings - Fork 473
Expand file tree
/
Copy pathInfluxDBFactoryTest.java
More file actions
69 lines (59 loc) · 2.11 KB
/
InfluxDBFactoryTest.java
File metadata and controls
69 lines (59 loc) · 2.11 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
package org.influxdb;
import org.influxdb.dto.Pong;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import okhttp3.OkHttpClient;
/**
* Test the InfluxDB Factory API.
*
* @author fujian1115 [at] gmail.com
*
*/
@RunWith(JUnitPlatform.class)
public class InfluxDBFactoryTest {
/**
* Test for a {@link InfluxDBFactory #connect(String)}.
*/
@Test
public void testShouldNotUseBasicAuthWhenCreateInfluxDBInstanceWithoutUserNameAndPassword() {
InfluxDB influxDB = InfluxDBFactory.connect("http://" + TestUtils.getInfluxIP() + ":" + TestUtils.getInfluxPORT(true));
verifyInfluxDBInstance(influxDB);
}
@Test
public void testShouldNotUseBasicAuthWhenCreateInfluxDBInstanceWithUserNameAndWithoutPassword() {
InfluxDB influxDB = InfluxDBFactory.connect("http://" + TestUtils.getInfluxIP() + ":" + TestUtils.getInfluxPORT(true), "admin", null);
verifyInfluxDBInstance(influxDB);
}
private void verifyInfluxDBInstance(InfluxDB influxDB) {
Assertions.assertNotNull(influxDB);
Pong pong = influxDB.ping();
Assertions.assertNotNull(pong);
Assertions.assertNotEquals(pong.getVersion(), "unknown");
}
/**
* Test for a {@link InfluxDBFactory #connect(String, okhttp3.OkHttpClient.Builder)}.
*/
@Test
public void testCreateInfluxDBInstanceWithClientAndWithoutUserNameAndPassword() {
InfluxDB influxDB = InfluxDBFactory.connect("http://" + TestUtils.getInfluxIP() + ":" + TestUtils.getInfluxPORT(true), new OkHttpClient.Builder());
verifyInfluxDBInstance(influxDB);
}
@Test
public void testShouldThrowIllegalArgumentWithInvalidUrl() {
Assertions.assertThrows(IllegalArgumentException.class,() -> {
InfluxDBFactory.connect("invalidUrl");
});
}
@Test
public void testUrlNotContainsColon() {
Assertions.assertThrows(IllegalArgumentException.class, () ->
InfluxDBFactory.connect("http://" + TestUtils.getInfluxIP()));
}
@Test
public void testUrlEndWithColon() {
Assertions.assertThrows(IllegalArgumentException.class, () ->
InfluxDBFactory.connect("http://" + TestUtils.getInfluxIP() + ":"));
}
}