/
RelationalServiceInfoTest.java
69 lines (49 loc) · 2.35 KB
/
RelationalServiceInfoTest.java
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.springframework.cloud.service.common;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class RelationalServiceInfoTest {
@Test
public void jdbcUrl() {
RelationalServiceInfo serviceInfo = createServiceInfoWithJdbcUrl("bad://bad:bad@bad:1234/bad",
"jdbc:jdbcdbtype://hostname:1234/database?user=username&password=password");
assertEquals("jdbc:jdbcdbtype://hostname:1234/database?user=username&password=password", serviceInfo.getJdbcUrl());
}
@Test
public void jdbcFullUrl() {
RelationalServiceInfo serviceInfo = createServiceInfo("dbtype://username:password@hostname:1234/database");
assertEquals("jdbc:jdbcdbtype://hostname:1234/database?user=username&password=password", serviceInfo.getJdbcUrl());
}
@Test
public void jdbcUrlNoPort() {
RelationalServiceInfo serviceInfo = createServiceInfo("dbtype://username:password@hostname/database");
assertEquals("jdbc:jdbcdbtype://hostname/database?user=username&password=password", serviceInfo.getJdbcUrl());
}
@Test
public void jdbcUrlNoUsernamePassword() {
RelationalServiceInfo serviceInfo = createServiceInfo("dbtype://hostname:1234/database");
assertEquals("jdbc:jdbcdbtype://hostname:1234/database", serviceInfo.getJdbcUrl());
}
@Test
public void jdbcUrlNoPassword() {
RelationalServiceInfo serviceInfo = createServiceInfo("dbtype://username@hostname/database");
assertEquals("jdbc:jdbcdbtype://hostname/database?user=username", serviceInfo.getJdbcUrl());
}
@Test
public void jdbcUrlWithQuery() {
RelationalServiceInfo serviceInfo = createServiceInfo("dbtype://username:password@hostname:1234/database?reconnect=true");
assertEquals("jdbc:jdbcdbtype://hostname:1234/database?user=username&password=password&reconnect=true", serviceInfo.getJdbcUrl());
}
@Test
public void jdbcUrlWithQueryNoUsernamePassword() {
RelationalServiceInfo serviceInfo = createServiceInfo("dbtype://hostname:1234/database?reconnect=true");
assertEquals("jdbc:jdbcdbtype://hostname:1234/database?reconnect=true", serviceInfo.getJdbcUrl());
}
private RelationalServiceInfo createServiceInfo(final String uri) {
return new RelationalServiceInfo("test", uri, "jdbcdbtype") {
};
}
private RelationalServiceInfo createServiceInfoWithJdbcUrl(final String uri, final String jdbcUrl) {
return new RelationalServiceInfo("test", uri, jdbcUrl, "jdbcdbtype") {
};
}
}