Repository navigation
Expand file tree
/
Copy pathConnectionInfoTest.java
More file actions
76 lines (68 loc) · 2.67 KB
/
Copy pathConnectionInfoTest.java
File metadata and controls
76 lines (68 loc) · 2.67 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
73
74
75
76
package io.github.utplsql.cli;
import com.beust.jcommander.ParameterException;
import org.junit.Assert;
import org.junit.Test;
/**
* Created by Vinicius on 21/04/2017.
*/
public class ConnectionInfoTest {
/**
* Regex pattern to match following connection strings:
* user/[email protected]:1521/db
* user/[email protected]/db
* user/pass@db
* user/pass
*/
@Test
public void connectionStr_Full() {
try {
ConnectionInfo ci = new ConnectionInfo().parseConnectionString("user/pass@localhost:3000/db");
Assert.assertEquals("user", ci.getUser());
Assert.assertEquals("pass", ci.getPassword());
Assert.assertEquals("localhost", ci.getHost());
Assert.assertEquals(3000, ci.getPort());
Assert.assertEquals("db", ci.getDb());
Assert.assertEquals("user@localhost:3000/db", ci.toString());
Assert.assertEquals("jdbc:oracle:thin:@//localhost:3000/db", ci.getConnectionUrl());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
@Test
public void connectionStr_WithoutPort() {
try {
ConnectionInfo ci = new ConnectionInfo().parseConnectionString("user/pass@localhost/db");
Assert.assertEquals("user", ci.getUser());
Assert.assertEquals("pass", ci.getPassword());
Assert.assertEquals("localhost", ci.getHost());
Assert.assertEquals(1521, ci.getPort());
Assert.assertEquals("db", ci.getDb());
Assert.assertEquals("user@localhost:1521/db", ci.toString());
Assert.assertEquals("jdbc:oracle:thin:@//localhost:1521/db", ci.getConnectionUrl());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
@Test
public void connectionStr_WithoutHostAndPort() {
try {
ConnectionInfo ci = new ConnectionInfo().parseConnectionString("user/pass@db");
Assert.assertEquals("user", ci.getUser());
Assert.assertEquals("pass", ci.getPassword());
Assert.assertEquals("127.0.0.1", ci.getHost());
Assert.assertEquals(1521, ci.getPort());
Assert.assertEquals("db", ci.getDb());
Assert.assertEquals("jdbc:oracle:thin:@//127.0.0.1:1521/db", ci.getConnectionUrl());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
@Test
public void connectionStr_Invalid() {
try {
new ConnectionInfo().parseConnectionString("user/pass");
Assert.fail();
} catch (ParameterException ignored) {}
}
}