Repository navigation
Expand file tree
/
Copy pathSQLDriverFactoryTest.java
More file actions
84 lines (69 loc) · 2.09 KB
/
Copy pathSQLDriverFactoryTest.java
File metadata and controls
84 lines (69 loc) · 2.09 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
77
78
79
80
81
82
83
84
package org.javawebstack.orm.test;
import org.javawebstack.orm.connection.MySQL;
import org.javawebstack.orm.util.SQLDriverFactory;
import org.javawebstack.orm.util.SQLDriverNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class SQLDriverFactoryTest {
private SQLDriverFactory factory;
private final Map<String, String > configMap = new HashMap<String, String >(){
{
put("file", "sb.sqlite");
put("host", "localhost");
put("port", "3306");
put("name", "app");
put("user", "root");
put("password", "");
}
};
@BeforeEach
public void beforeEach() {
factory = new SQLDriverFactory(configMap);
}
/*
* Normal Cases
*/
@Test
public void testSQLite() throws SQLDriverNotFoundException {
assertNotNull(factory.getDriver("sqlite"));
}
@Test
public void testMySQL() throws SQLDriverNotFoundException {
assertNotNull(factory.getDriver("mysql"));
}
@Test
public void testRegisrtration() throws SQLDriverNotFoundException {
factory.registerDriver("mariadb", () -> new MySQL(
configMap.get("host"),
Integer.parseInt(configMap.get("port")),
configMap.get("name"),
configMap.get("user"),
configMap.get("password")
));
assertNotNull(factory.getDriver("mariadb"));
}
/*
* Edge Cases
*/
@Test
public void testDriverNameIsCaseSensitive() {
assertThrows(
SQLDriverNotFoundException.class,
() -> factory.getDriver("MySQL")
);
}
/*
* Error Cases
*/
@Test
public void testCannotFindUninitializedDriver() {
assertThrows(
SQLDriverNotFoundException.class,
() -> factory.getDriver("nodriver")
);
}
}