|
6 | 6 | import org.evomaster.client.java.controller.api.dto.SutInfoDto; |
7 | 7 | import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType; |
8 | 8 | import org.evomaster.client.java.controller.db.DbCleaner; |
| 9 | +import org.evomaster.client.java.controller.db.SqlScriptRunner; |
9 | 10 | import org.evomaster.client.java.controller.db.SqlScriptRunnerCached; |
10 | 11 | import org.evomaster.client.java.controller.internal.db.DbSpecification; |
11 | 12 | import org.evomaster.client.java.controller.problem.ProblemInfo; |
12 | 13 | import org.evomaster.client.java.controller.problem.RestProblem; |
13 | 14 | import org.testcontainers.containers.GenericContainer; |
14 | 15 |
|
| 16 | +import java.io.InputStream; |
| 17 | +import java.io.InputStreamReader; |
15 | 18 | import java.sql.Connection; |
16 | 19 | import java.sql.DriverManager; |
17 | 20 | import java.sql.SQLException; |
@@ -74,6 +77,10 @@ public static void main(String[] args) { |
74 | 77 | private Connection sqlConnection; |
75 | 78 | private List<DbSpecification> dbSpecification; |
76 | 79 |
|
| 80 | + private String INIT_DB_SCRIPT_PATH = "/init_db.sql"; |
| 81 | + |
| 82 | + private String initSQLScript; |
| 83 | + |
77 | 84 | private static final GenericContainer postgres = new GenericContainer("postgres:9") |
78 | 85 | .withExposedPorts(5432) |
79 | 86 | .withEnv("POSTGRES_HOST_AUTH_METHOD","trust") |
@@ -105,6 +112,12 @@ public ExternalEvoMasterController( |
105 | 112 | this.packagesToInstrument = packagesToInstrument; |
106 | 113 | setControllerPort(controllerPort); |
107 | 114 | setJavaCommand(command); |
| 115 | + |
| 116 | + try (InputStream in = getClass().getResourceAsStream(INIT_DB_SCRIPT_PATH)) { |
| 117 | + initSQLScript = String.join(System.lineSeparator(), (new SqlScriptRunner()).readCommands(new InputStreamReader(in))); |
| 118 | + } catch (Exception e) { |
| 119 | + throw new RuntimeException(e); |
| 120 | + } |
108 | 121 | } |
109 | 122 |
|
110 | 123 |
|
@@ -174,19 +187,27 @@ public void postStart() { |
174 | 187 |
|
175 | 188 | try { |
176 | 189 | sqlConnection = DriverManager.getConnection(dbUrl(), "postgres", ""); |
| 190 | + |
| 191 | + /* |
| 192 | + ensure the data in db is empty |
| 193 | + */ |
| 194 | + DbCleaner.clearDatabase_Postgres(sqlConnection, |
| 195 | + "subscriptions", |
| 196 | + Arrays.asList("flyway_schema_history")); |
| 197 | + |
177 | 198 | dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.POSTGRES,sqlConnection) |
178 | | - .withSchemas("subscriptions").withDisabledSmartClean()); |
| 199 | + .withSchemas("subscriptions").withInitSqlScript(initSQLScript)); |
179 | 200 | } catch (Exception e) { |
180 | 201 | throw new RuntimeException(e); |
181 | 202 | } |
182 | 203 | } |
183 | 204 |
|
184 | 205 | @Override |
185 | 206 | public void resetStateOfSUT() { |
186 | | - DbCleaner.clearDatabase_Postgres(sqlConnection, |
187 | | - "subscriptions", |
188 | | - Arrays.asList("flyway_schema_history")); |
189 | | - SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/init_db.sql"); |
| 207 | +// DbCleaner.clearDatabase_Postgres(sqlConnection, |
| 208 | +// "subscriptions", |
| 209 | +// Arrays.asList("flyway_schema_history")); |
| 210 | +// SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/init_db.sql"); |
190 | 211 | } |
191 | 212 |
|
192 | 213 | @Override |
|
0 commit comments