Skip to content

Commit 3979427

Browse files
committed
petclinic
1 parent a7f42c8 commit 3979427

4 files changed

Lines changed: 185 additions & 9 deletions

File tree

jdk_8_maven/em/embedded/graphql/petclinic-graphql/src/main/java/em/embedded/org/springframework/samples/petclinic/EmbeddedEvoMasterController.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.evomaster.client.java.controller.api.dto.SutInfoDto;
77
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
88
import org.evomaster.client.java.controller.db.DbCleaner;
9+
import org.evomaster.client.java.controller.db.SqlScriptRunner;
910
import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;
1011
import org.evomaster.client.java.controller.internal.SutController;
1112
import org.evomaster.client.java.controller.internal.db.DbSpecification;
@@ -17,6 +18,8 @@
1718
import org.springframework.samples.petclinic.PetClinicApplication;
1819
import org.testcontainers.containers.GenericContainer;
1920

21+
import java.io.InputStream;
22+
import java.io.InputStreamReader;
2023
import java.sql.Connection;
2124
import java.sql.SQLException;
2225
import java.util.Arrays;
@@ -41,8 +44,12 @@ public static void main(String[] args){
4144

4245
private ConfigurableApplicationContext ctx;
4346
private Connection sqlConnection;
47+
private String INIT_DB_SCRIPT_PATH = "/populateDB.sql";
48+
4449
private List<DbSpecification> dbSpecification;
4550

51+
private String initSQLScript;
52+
4653
private static final GenericContainer postgres = new GenericContainer("postgres:9")
4754
.withExposedPorts(5432)
4855
.withEnv("POSTGRES_HOST_AUTH_METHOD","trust")
@@ -56,6 +63,12 @@ public EmbeddedEvoMasterController() {
5663

5764
public EmbeddedEvoMasterController(int port) {
5865
setControllerPort(port);
66+
67+
try (InputStream in = getClass().getResourceAsStream(INIT_DB_SCRIPT_PATH)) {
68+
initSQLScript = String.join(System.lineSeparator(), (new SqlScriptRunner()).readCommands(new InputStreamReader(in)));
69+
} catch (Exception e) {
70+
throw new RuntimeException(e);
71+
}
5972
}
6073

6174

@@ -90,12 +103,18 @@ public String startSut() {
90103
throw new RuntimeException(e);
91104
}
92105

106+
// create tables
107+
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/initDB.sql");
93108

109+
/*
110+
ensure the data is empty
111+
*/
112+
DbCleaner.clearDatabase_Postgres(sqlConnection,"public", null);
94113

95114
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.POSTGRES,sqlConnection)
96-
.withSchemas("public").withDisabledSmartClean());
115+
.withSchemas("public").withInitSqlScript(initSQLScript));
116+
97117

98-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/db/postgresql/initDB.sql");
99118

100119
return "http://localhost:" + getSutPort();
101120
}
@@ -125,8 +144,8 @@ public String getPackagePrefixesToCover() {
125144

126145
@Override
127146
public void resetStateOfSUT() {
128-
DbCleaner.clearDatabase_Postgres(sqlConnection,"public", null);
129-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/db/postgresql/populateDB.sql");
147+
// DbCleaner.clearDatabase_Postgres(sqlConnection,"public", null);
148+
// SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/db/postgresql/populateDB.sql");
130149
}
131150

132151
@Override
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
CREATE TABLE IF NOT EXISTS vets (
2+
id SERIAL,
3+
first_name VARCHAR(30),
4+
last_name VARCHAR(30),
5+
CONSTRAINT pk_vets PRIMARY KEY (id)
6+
);
7+
8+
CREATE INDEX IF NOT EXISTS idx_vets_last_name ON vets (last_name);
9+
10+
ALTER SEQUENCE vets_id_seq RESTART WITH 100;
11+
12+
13+
CREATE TABLE IF NOT EXISTS specialties (
14+
id SERIAL,
15+
name VARCHAR(80),
16+
CONSTRAINT pk_specialties PRIMARY KEY (id)
17+
);
18+
19+
CREATE INDEX IF NOT EXISTS idx_specialties_name ON specialties (name);
20+
21+
ALTER SEQUENCE specialties_id_seq RESTART WITH 100;
22+
23+
24+
CREATE TABLE IF NOT EXISTS vet_specialties (
25+
vet_id INT NOT NULL,
26+
specialty_id INT NOT NULL,
27+
FOREIGN KEY (vet_id) REFERENCES vets(id),
28+
FOREIGN KEY (specialty_id) REFERENCES specialties(id),
29+
CONSTRAINT unique_ids UNIQUE (vet_id,specialty_id)
30+
);
31+
32+
33+
34+
CREATE TABLE IF NOT EXISTS types (
35+
id SERIAL,
36+
name VARCHAR(80),
37+
CONSTRAINT pk_types PRIMARY KEY (id)
38+
);
39+
40+
CREATE INDEX IF NOT EXISTS idx_types_name ON types (name);
41+
42+
ALTER SEQUENCE types_id_seq RESTART WITH 100;
43+
44+
CREATE TABLE IF NOT EXISTS owners (
45+
id SERIAL,
46+
first_name VARCHAR(30),
47+
last_name VARCHAR(30),
48+
address VARCHAR(255),
49+
city VARCHAR(80),
50+
telephone VARCHAR(20),
51+
CONSTRAINT pk_owners PRIMARY KEY (id)
52+
);
53+
54+
CREATE INDEX IF NOT EXISTS idx_owners_last_name ON owners (last_name);
55+
56+
ALTER SEQUENCE owners_id_seq RESTART WITH 100;
57+
58+
59+
CREATE TABLE IF NOT EXISTS pets (
60+
id SERIAL,
61+
name VARCHAR(30),
62+
birth_date DATE,
63+
type_id INT NOT NULL,
64+
owner_id INT NOT NULL,
65+
FOREIGN KEY (owner_id) REFERENCES owners(id),
66+
FOREIGN KEY (type_id) REFERENCES types(id),
67+
CONSTRAINT pk_pets PRIMARY KEY (id)
68+
);
69+
70+
CREATE INDEX IF NOT EXISTS idx_pets_name ON pets (name);
71+
72+
ALTER SEQUENCE pets_id_seq RESTART WITH 100;
73+
74+
75+
CREATE TABLE IF NOT EXISTS visits (
76+
id SERIAL,
77+
pet_id INT NOT NULL,
78+
visit_date DATE,
79+
description VARCHAR(255),
80+
FOREIGN KEY (pet_id) REFERENCES pets(id),
81+
CONSTRAINT pk_visits PRIMARY KEY (id)
82+
);
83+
84+
ALTER SEQUENCE visits_id_seq RESTART WITH 100;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
INSERT INTO vets VALUES (1, 'James', 'Carter') ON CONFLICT DO NOTHING;
2+
INSERT INTO vets VALUES (2, 'Helen', 'Leary') ON CONFLICT DO NOTHING;
3+
INSERT INTO vets VALUES (3, 'Linda', 'Douglas') ON CONFLICT DO NOTHING;
4+
INSERT INTO vets VALUES (4, 'Rafael', 'Ortega') ON CONFLICT DO NOTHING;
5+
INSERT INTO vets VALUES (5, 'Henry', 'Stevens') ON CONFLICT DO NOTHING;
6+
INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins') ON CONFLICT DO NOTHING;
7+
8+
INSERT INTO specialties VALUES (1, 'radiology') ON CONFLICT DO NOTHING;
9+
INSERT INTO specialties VALUES (2, 'surgery') ON CONFLICT DO NOTHING;
10+
INSERT INTO specialties VALUES (3, 'dentistry') ON CONFLICT DO NOTHING;
11+
12+
INSERT INTO vet_specialties VALUES (2, 1) ON CONFLICT DO NOTHING;
13+
INSERT INTO vet_specialties VALUES (3, 2) ON CONFLICT DO NOTHING;
14+
INSERT INTO vet_specialties VALUES (3, 3) ON CONFLICT DO NOTHING;
15+
INSERT INTO vet_specialties VALUES (4, 2) ON CONFLICT DO NOTHING;
16+
INSERT INTO vet_specialties VALUES (5, 1) ON CONFLICT DO NOTHING;
17+
18+
INSERT INTO types VALUES (1, 'cat') ON CONFLICT DO NOTHING;
19+
INSERT INTO types VALUES (2, 'dog') ON CONFLICT DO NOTHING;
20+
INSERT INTO types VALUES (3, 'lizard') ON CONFLICT DO NOTHING;
21+
INSERT INTO types VALUES (4, 'snake') ON CONFLICT DO NOTHING;
22+
INSERT INTO types VALUES (5, 'bird') ON CONFLICT DO NOTHING;
23+
INSERT INTO types VALUES (6, 'hamster') ON CONFLICT DO NOTHING;
24+
25+
INSERT INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023') ON CONFLICT DO NOTHING;
26+
INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749') ON CONFLICT DO NOTHING;
27+
INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763') ON CONFLICT DO NOTHING;
28+
INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198') ON CONFLICT DO NOTHING;
29+
INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765') ON CONFLICT DO NOTHING;
30+
INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654') ON CONFLICT DO NOTHING;
31+
INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387') ON CONFLICT DO NOTHING;
32+
INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683') ON CONFLICT DO NOTHING;
33+
INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435') ON CONFLICT DO NOTHING;
34+
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487') ON CONFLICT DO NOTHING;
35+
36+
INSERT INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1) ON CONFLICT DO NOTHING;
37+
INSERT INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2) ON CONFLICT DO NOTHING;
38+
INSERT INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3) ON CONFLICT DO NOTHING;
39+
INSERT INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3) ON CONFLICT DO NOTHING;
40+
INSERT INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4) ON CONFLICT DO NOTHING;
41+
INSERT INTO pets VALUES (6, 'George', '2000-01-20', 4, 5) ON CONFLICT DO NOTHING;
42+
INSERT INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6) ON CONFLICT DO NOTHING;
43+
INSERT INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6) ON CONFLICT DO NOTHING;
44+
INSERT INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7) ON CONFLICT DO NOTHING;
45+
INSERT INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8) ON CONFLICT DO NOTHING;
46+
INSERT INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9) ON CONFLICT DO NOTHING;
47+
INSERT INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10) ON CONFLICT DO NOTHING;
48+
INSERT INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10) ON CONFLICT DO NOTHING;
49+
50+
INSERT INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot') ON CONFLICT DO NOTHING;
51+
INSERT INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot') ON CONFLICT DO NOTHING;
52+
INSERT INTO visits VALUES (3, 8, '2009-06-04', 'neutered') ON CONFLICT DO NOTHING;
53+
INSERT INTO visits VALUES (4, 7, '2008-09-04', 'spayed') ON CONFLICT DO NOTHING;

jdk_8_maven/em/external/graphql/petclinic-graphql/src/main/java/em/external/org/springframework/samples/petclinic/ExternalEvoMasterController.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import org.evomaster.client.java.controller.api.dto.SutInfoDto;
77
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
88
import org.evomaster.client.java.controller.db.DbCleaner;
9+
import org.evomaster.client.java.controller.db.SqlScriptRunner;
910
import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;
1011
import org.evomaster.client.java.controller.internal.db.DbSpecification;
1112
import org.evomaster.client.java.controller.problem.GraphQlProblem;
1213
import org.evomaster.client.java.controller.problem.ProblemInfo;
1314
import org.testcontainers.containers.GenericContainer;
1415

16+
import java.io.InputStream;
17+
import java.io.InputStreamReader;
1518
import java.sql.Connection;
1619
import java.sql.DriverManager;
1720
import java.sql.SQLException;
@@ -62,8 +65,12 @@ public static void main(String[] args) {
6265
private final int sutPort;
6366
private String jarLocation;
6467
private Connection sqlConnection;
68+
private String INIT_DB_SCRIPT_PATH = "/populateDB.sql";
69+
6570
private List<DbSpecification> dbSpecification;
6671

72+
private String initSQLScript;
73+
6774
private static final GenericContainer postgres = new GenericContainer("postgres:9")
6875
.withExposedPorts(5432)
6976
.withEnv("POSTGRES_DB", "petclinic")
@@ -93,6 +100,12 @@ public ExternalEvoMasterController(
93100
this.timeoutSeconds = timeoutSeconds;
94101
setControllerPort(controllerPort);
95102
setJavaCommand(command);
103+
104+
try (InputStream in = getClass().getResourceAsStream(INIT_DB_SCRIPT_PATH)) {
105+
initSQLScript = String.join(System.lineSeparator(), (new SqlScriptRunner()).readCommands(new InputStreamReader(in)));
106+
} catch (Exception e) {
107+
throw new RuntimeException(e);
108+
}
96109
}
97110

98111

@@ -154,20 +167,27 @@ public void postStart() {
154167
try {
155168
sqlConnection = DriverManager.getConnection(dbUrl(), "postgres", "");
156169

170+
// create tables
171+
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/initDB.sql");
172+
173+
/*
174+
ensure the data is empty
175+
*/
176+
DbCleaner.clearDatabase_Postgres(sqlConnection,"public", null);
177+
157178
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.POSTGRES,sqlConnection)
158-
.withSchemas("public").withDisabledSmartClean());
159-
// initSqlOnResourcePath = "/db/postgresql/populateDB.sql";
179+
.withSchemas("public").withInitSqlScript(initSQLScript));
180+
160181

161-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/initDB.sql");
162182
} catch (Exception e) {
163183
throw new RuntimeException(e);
164184
}
165185
}
166186

167187
@Override
168188
public void resetStateOfSUT() {
169-
DbCleaner.clearDatabase_Postgres(sqlConnection,"public", null);
170-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/populateDB.sql");
189+
// DbCleaner.clearDatabase_Postgres(sqlConnection,"public", null);
190+
// SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/populateDB.sql");
171191
}
172192

173193
@Override

0 commit comments

Comments
 (0)