1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package dev.aherscu.qa.jgiven.jdbc;
17
18 import static dev.aherscu.qa.testing.utils.StringUtilsExtensions.*;
19
20 import java.util.concurrent.*;
21
22 import javax.annotation.concurrent.*;
23
24 import org.apache.commons.configuration.*;
25 import org.apache.commons.configuration.AbstractConfiguration;
26
27 import com.zaxxer.hikari.*;
28
29 import dev.aherscu.qa.jgiven.jdbc.utils.dbutils.*;
30 import dev.aherscu.qa.testing.utils.config.BaseConfiguration;
31 import lombok.*;
32 import lombok.extern.slf4j.*;
33
34
35
36
37
38
39 @ThreadSafe
40 @Slf4j
41 public final class TestConfiguration extends BaseConfiguration {
42 private static final ConcurrentMap<String, StreamingQueryRunner> queryRunners =
43 new ConcurrentHashMap<>();
44
45 static {
46
47
48 AbstractConfiguration
49 .setDefaultListDelimiter(COMMA.charAt(0));
50 }
51
52
53
54
55
56
57
58 public TestConfiguration(final Configuration... configurations) {
59 super(configurations);
60 }
61
62 public StreamingQueryRunner queryRunnerFor(final String id) {
63 log.trace("configuring query runner {}", id);
64 return queryRunners.computeIfAbsent(id, _id -> {
65 val dataSource = new HikariDataSource();
66 dataSource.setJdbcUrl(datasourceString(_id, "url"));
67 return new StreamingQueryRunner(dataSource);
68 });
69 }
70
71 private int datasourceInt(String id, String name) {
72 return getInt("datasource" + DOT + id + DOT + name);
73 }
74
75 private String datasourceString(String id, String name) {
76 return getString("datasource" + DOT + id + DOT + name);
77 }
78
79 }