Skip to content

Commit d09b611

Browse files
committed
resetting database without resetStateOfSUT
1 parent 6487b44 commit d09b611

4 files changed

Lines changed: 109 additions & 122 deletions

File tree

jdk_11_maven/em/embedded/rest/tracking-system/src/main/java/em/embedded/com/pfa/app/EmbeddedEvoMasterController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public static void main(String[] args) {
4848

4949
private String INIT_DB_SCRIPT_PATH = "/data.sql";
5050

51-
private String initSQLScript;
52-
5351
public EmbeddedEvoMasterController() {
5452
this(40100);
5553
}
@@ -64,7 +62,9 @@ public String startSut() {
6462
ctx = SpringApplication.run(ProjectTrackingSystemApplication.class, new String[]{
6563
"--server.port=0",
6664
"--spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;",
67-
"--spring.profiles.active=dev"
65+
"--spring.profiles.active=dev",
66+
// to not execute sql file (data.sql) located in resources folder. Because flyway handles it.
67+
"--spring.datasource.initialization-mode=never"
6868
});
6969

7070
if (sqlConnection != null) {
@@ -81,7 +81,9 @@ public String startSut() {
8181
throw new RuntimeException(e);
8282
}
8383

84-
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection));
84+
DbCleaner.clearDatabase_H2(sqlConnection, Arrays.asList("flyway_schema_history"));
85+
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection)
86+
.withInitSqlOnResourcePath(INIT_DB_SCRIPT_PATH));
8587

8688
return "http://localhost:" + getSutPort();
8789
}
@@ -110,7 +112,6 @@ public String getPackagePrefixesToCover() {
110112

111113
@Override
112114
public void resetStateOfSUT() {
113-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection, INIT_DB_SCRIPT_PATH);
114115
}
115116

116117
@Override

jdk_11_maven/em/embedded/rest/tracking-system/src/main/resources/data.sql

Lines changed: 50 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
SET REFERENTIAL_INTEGRITY FALSE;
2-
TRUNCATE TABLE projects;
3-
TRUNCATE TABLE locations;
4-
TRUNCATE TABLE departments;
5-
TRUNCATE TABLE employees;
6-
TRUNCATE TABLE assignments;
7-
TRUNCATE TABLE user_credentials;
8-
SET REFERENTIAL_INTEGRITY TRUE;
9-
10-
INSERT INTO projects (project_id, title, start_date, end_date, status) VALUES
1+
insert into projects (project_id, title, start_date, end_date, status) values
112
(1, 'TRANSBSCS', '2020-09-28', '2020-11-04', 'COMPLETED'),
123
(2, 'SYNCH_BSCS_IMX', '2020-11-26', '2021-03-25', 'IN_PROGRESS'),
134
(3, 'TASYI9A LILVIRANDA', '2020-11-26', '2020-11-26', 'COMPLETED'),
@@ -18,17 +9,17 @@ INSERT INTO projects (project_id, title, start_date, end_date, status) VALUES
189
(8, 'GREENPLUME_UPGRADE', '2020-11-02', '2021-05-01', 'IN_PROGRESS'),
1910
(9, 'COMMISION_AUTOMATION', '2020-06-01', '2021-03-02', 'IN_PROGRESS');
2011

21-
INSERT INTO locations (location_id, adr, postal_code, city) VALUES
12+
insert into locations (location_id, adr, postal_code, city) values
2213
(1, 'RUE DE LA BOURSE', '2016', 'LAC2'),
2314
(2, 'RUE DE BLA BLA', '2016', 'CHARGUIA');
2415

25-
INSERT INTO departments (department_id, department_name, location_id) VALUES
16+
insert into departments (department_id, department_name, location_id) values
2617
(4, 'DWH', 1),
2718
(5, 'Digital', 1),
2819
(6, 'Billing', 1);
2920

3021

31-
INSERT INTO employees (employee_id, first_name, last_name, email, phone, hiredate, job, salary, manager_id, department_id) VALUES
22+
insert into employees (employee_id, first_name, last_name, email, phone, hiredate, job, salary, manager_id, department_id) values
3223
(1, 'Selim', 'Horri', 'springabcxyzboot@gmail.com', '22125144', '2019-04-15', 'Billing', '5000.00', NULL, NULL),
3324
(2, 'Badr', 'Idoudi', 'springabcxyzboot@gmail.com', '22125144', '2019-04-15', 'Digital', '5000.00', NULL, NULL),
3425
(3, 'Imen', 'Touk', 'springabcxyzboot@gmail.com', '22125144', '2019-04-15', 'Data Warehouse', '5000.00', NULL, NULL),
@@ -44,63 +35,63 @@ INSERT INTO employees (employee_id, first_name, last_name, email, phone, hiredat
4435
(13, 'Mouna', 'Chaouachi', 'springabcxyzboot@gmail.com', '22125144', NULL, 'Data Warehouse', '5000.50', NULL, NULL),
4536
(14, 'admin', 'admin', 'springabcxyzboot@gmail.com', '22125144', NULL, 'RH', '5000.00', NULL, NULL);
4637

47-
UPDATE employees
48-
SET manager_id = 4, department_id = 6
49-
WHERE employee_id = 1;
38+
update employees
39+
set manager_id = 4, department_id = 6
40+
where employee_id = 1;
5041

51-
UPDATE employees
52-
SET manager_id = 9, department_id = 5
53-
WHERE employee_id = 2;
42+
update employees
43+
set manager_id = 9, department_id = 5
44+
where employee_id = 2;
5445

55-
UPDATE employees
56-
SET manager_id = 5, department_id = 4
57-
WHERE employee_id = 3;
46+
update employees
47+
set manager_id = 5, department_id = 4
48+
where employee_id = 3;
5849

59-
UPDATE employees
60-
SET manager_id = NULL, department_id = 6
61-
WHERE employee_id = 4;
50+
update employees
51+
set manager_id = NULL, department_id = 6
52+
where employee_id = 4;
6253

63-
UPDATE employees
64-
SET manager_id = NULL, department_id = 4
65-
WHERE employee_id = 5;
54+
update employees
55+
set manager_id = NULL, department_id = 4
56+
where employee_id = 5;
6657

67-
UPDATE employees
68-
SET manager_id = 4, department_id = 6
69-
WHERE employee_id = 6;
58+
update employees
59+
set manager_id = 4, department_id = 6
60+
where employee_id = 6;
7061

71-
UPDATE employees
72-
SET manager_id = 4, department_id = 6
73-
WHERE employee_id = 7;
62+
update employees
63+
set manager_id = 4, department_id = 6
64+
where employee_id = 7;
7465

75-
UPDATE employees
76-
SET manager_id = 4, department_id = 6
77-
WHERE employee_id = 8;
66+
update employees
67+
set manager_id = 4, department_id = 6
68+
where employee_id = 8;
7869

79-
UPDATE employees
80-
SET manager_id = NULL, department_id = 5
81-
WHERE employee_id = 9;
70+
update employees
71+
set manager_id = NULL, department_id = 5
72+
where employee_id = 9;
8273

83-
UPDATE employees
84-
SET manager_id = 9, department_id = 5
85-
WHERE employee_id = 10;
74+
update employees
75+
set manager_id = 9, department_id = 5
76+
where employee_id = 10;
8677

87-
UPDATE employees
88-
SET manager_id = 9, department_id = 5
89-
WHERE employee_id = 11;
78+
update employees
79+
set manager_id = 9, department_id = 5
80+
where employee_id = 11;
9081

91-
UPDATE employees
92-
SET manager_id = 5, department_id = 4
93-
WHERE employee_id = 12;
82+
update employees
83+
set manager_id = 5, department_id = 4
84+
where employee_id = 12;
9485

95-
UPDATE employees
96-
SET manager_id = 5, department_id = 4
97-
WHERE employee_id = 13;
86+
update employees
87+
set manager_id = 5, department_id = 4
88+
where employee_id = 13;
9889

99-
UPDATE employees
100-
SET manager_id = NULL, department_id = NULL
101-
WHERE employee_id = 14;
90+
update employees
91+
set manager_id = NULL, department_id = NULL
92+
where employee_id = 14;
10293

103-
INSERT INTO assignments (employee_id, project_id, commit_date, commit_emp_desc, commit_mgr_desc) VALUES
94+
insert into assignments (employee_id, project_id, commit_date, commit_emp_desc, commit_mgr_desc) values
10495
(1, 1, '2020-11-26 10:50:09', NULL, 'init'),
10596
(1, 1, '2020-11-26 13:14:22', 'set up some configs', 'you need to implement sec solution'),
10697
(1, 1, '2020-12-12 16:49:42', 'implement customer by invoice', NULL),
@@ -111,7 +102,7 @@ INSERT INTO assignments (employee_id, project_id, commit_date, commit_emp_desc,
111102
(1, 2, '2020-11-26 13:14:22', 'generate xml file', 'check out marshaling correctness'),
112103
(1, 2, '2020-12-12 11:57:18', 'files on CRMIMX', NULL),
113104
(1, 2, '2020-12-12 12:13:51', '00000', NULL),
114-
(1, 2, '2020-12-12 12:23:39', 'Set up xml for CRMIMX1', NULL),
105+
(1, 2, '2020-12-12 12:23:39', 'set up xml for CRMIMX1', NULL),
115106
(1, 2, '2020-12-12 12:30:14', 'implement BSCSIMX2 business layer', NULL),
116107
(1, 2, '2020-12-12 12:37:53', 'synchronize BSCSIMX2', NULL),
117108
(1, 2, '2020-12-12 16:40:17', 'create a simple xml file for IMX CX', NULL),
@@ -134,7 +125,7 @@ INSERT INTO assignments (employee_id, project_id, commit_date, commit_emp_desc,
134125
(3, 4, '2020-12-17 11:30:09', 'ta7dhirat ........$$**', NULL),
135126
(3, 9, '2020-12-19 16:06:20', NULL, 'init'),
136127
(6, 1, '2020-11-26 10:49:41', NULL, 'init'),
137-
(6, 1, '2020-11-26 10:50:53', 'SET UP DIFFERENT LAYERS', NULL),
128+
(6, 1, '2020-11-26 10:50:53', 'set UP DIFFERENT LAYERS', NULL),
138129
(6, 1, '2020-12-12 15:16:55', 'import new libs', NULL),
139130
(6, 1, '2020-12-12 15:17:31', 'set exception payload', NULL),
140131
(10, 6, '2020-12-19 11:34:11', NULL, 'init'),
@@ -161,7 +152,7 @@ INSERT INTO assignments (employee_id, project_id, commit_date, commit_emp_desc,
161152
(13, 9, '2020-12-19 16:13:01', 'get first ids', NULL),
162153
(13, 9, '2020-12-19 16:13:17', 'create new workspace', NULL);
163154

164-
INSERT INTO user_credentials (user_id, username, password, enabled, role, employee_id) VALUES
155+
insert into user_credentials (user_id, username, password, enabled, role, employee_id) values
165156
(1, 'imentouk', '$2a$10$6pNV34gbMAEj6vuyVmQMdOfSKk.kuxOUOeucg78/cvOprSR3lsZL2', 1, 'ROLE_EMP', 3),
166157
(2, 'badridoudi', '$2a$10$6pNV34gbMAEj6vuyVmQMdOfSKk.kuxOUOeucg78/cvOprSR3lsZL2', 1, 'ROLE_EMP', 2),
167158
(3, 'selimhorri', '$2a$10$6pNV34gbMAEj6vuyVmQMdOfSKk.kuxOUOeucg78/cvOprSR3lsZL2', 1, 'ROLE_EMP', 1),

jdk_11_maven/em/external/rest/tracking-system/src/main/java/em/external/com/pfa/app/ExternalEvoMasterController.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.evomaster.client.java.controller.problem.RestProblem;
1111
import org.evomaster.client.java.sql.DbCleaner;
1212
import org.evomaster.client.java.sql.DbSpecification;
13-
import org.evomaster.client.java.sql.SqlScriptRunnerCached;
1413
import org.h2.tools.Server;
1514

1615
import java.sql.Connection;
@@ -99,8 +98,7 @@ public String[] getInputParameters() {
9998
"--spring.profiles.active=dev",
10099
"--spring.datasource.url=" + dbUrl() + ";DB_CLOSE_DELAY=-1",
101100
"--spring.datasource.username=sa",
102-
"--spring.datasource.password",
103-
101+
"--spring.datasource.password"
104102
};
105103
}
106104

@@ -150,19 +148,16 @@ public void postStart() {
150148
sqlConnection = DriverManager.getConnection(dbUrl(), "sa", "");
151149

152150
DbCleaner.clearDatabase_H2(sqlConnection, Arrays.asList("flyway_schema_history"));
153-
154151
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection)
155-
.withInitSqlOnResourcePath(INIT_DB_SCRIPT_PATH)
156-
);
152+
.withInitSqlOnResourcePath(INIT_DB_SCRIPT_PATH));
153+
157154
} catch (Exception e) {
158155
throw new RuntimeException(e);
159156
}
160157
}
161158

162159
@Override
163160
public void resetStateOfSUT() {
164-
DbCleaner.clearDatabase_H2(sqlConnection, Arrays.asList("flyway_schema_history"));
165-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection, INIT_DB_SCRIPT_PATH);
166161
}
167162

168163
@Override

0 commit comments

Comments
 (0)