|
19 | 19 | import org.testcontainers.containers.CassandraContainer; |
20 | 20 | import org.testcontainers.utility.DockerImageName; |
21 | 21 |
|
22 | | -import java.io.IOException; |
23 | | -import java.nio.file.Files; |
24 | | -import java.nio.file.Paths; |
25 | 22 | import java.util.HashMap; |
26 | 23 | import java.util.Map; |
27 | 24 |
|
28 | 25 | public class CassandraTestResource implements QuarkusTestResourceLifecycleManager { |
29 | 26 |
|
30 | 27 | static DockerImageName dockerImageName = DockerImageName.parse("cassandra:3.11.10"); |
31 | 28 | static CassandraContainer<?> cassandraContainer = new CassandraContainer<>(dockerImageName) |
32 | | - .withExposedPorts(9042); |
| 29 | + .withExposedPorts(9042) |
| 30 | + .withInitScript("cql/load.cql"); |
33 | 31 |
|
34 | 32 | @Override |
35 | 33 | public Map<String, String> start() { |
36 | 34 | cassandraContainer.start(); |
37 | 35 |
|
38 | | - // Load CQL script if it exists |
39 | | - try { |
40 | | - String scriptPath = "src/test/resources/cql/load.cql"; |
41 | | - if (Files.exists(Paths.get(scriptPath))) { |
42 | | - String cqlScript = Files.readString(Paths.get(scriptPath)).trim(); |
43 | | - if (!cqlScript.isEmpty()) { |
44 | | - // Split by semicolon and execute each statement |
45 | | - String[] statements = cqlScript.split(";"); |
46 | | - for (String statement : statements) { |
47 | | - String trimmed = statement.trim(); |
48 | | - if (!trimmed.isEmpty() && !trimmed.startsWith("--") && !trimmed.startsWith("//")) { |
49 | | - cassandraContainer.getSession().execute(trimmed); |
50 | | - } |
51 | | - } |
52 | | - } |
53 | | - } |
54 | | - } catch (IOException e) { |
55 | | - // Script loading is optional, continue without it |
56 | | - } |
57 | | - |
58 | 36 | HashMap<String, String> map = new HashMap<>(); |
59 | 37 | map.put("cassandra.host", cassandraContainer.getHost()); |
60 | 38 | map.put("cassandra.port", String.valueOf(cassandraContainer.getMappedPort(9042))); |
|
0 commit comments