Skip to content

Commit aeb91a1

Browse files
committed
fix market
1 parent 6528066 commit aeb91a1

File tree

4 files changed

+236
-10
lines changed

4 files changed

+236
-10
lines changed

jdk_11_maven/em/embedded/rest/market/src/main/java/em/embedded/market/EmbeddedEvoMasterController.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.springframework.context.ConfigurableApplicationContext;
1818
import org.springframework.jdbc.core.JdbcTemplate;
1919

20+
import java.io.InputStream;
21+
import java.io.InputStreamReader;
2022
import java.sql.Connection;
2123
import java.sql.SQLException;
2224
import java.util.Arrays;
@@ -48,12 +50,22 @@ public static void main(String[] args) {
4850
private List<DbSpecification> dbSpecification;
4951

5052

53+
private String INIT_DB_SCRIPT_PATH = "/data.sql";
54+
55+
private String initSQLScript;
56+
5157
public EmbeddedEvoMasterController() {
5258
this(40100);
5359
}
5460

5561
public EmbeddedEvoMasterController(int port) {
5662
setControllerPort(port);
63+
64+
try (InputStream in = getClass().getResourceAsStream(INIT_DB_SCRIPT_PATH)) {
65+
initSQLScript = String.join(System.lineSeparator(), (new SqlScriptRunner()).readCommands(new InputStreamReader(in)));
66+
} catch (Exception e) {
67+
throw new RuntimeException(e);
68+
}
5769
}
5870

5971
@Override
@@ -77,9 +89,11 @@ public String startSut() {
7789
throw new RuntimeException(e);
7890
}
7991

92+
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/schema.sql");
93+
DbCleaner.clearDatabase_H2(sqlConnection);
94+
8095
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection)
81-
//.withInitSqlOnResourcePath("/data.sql"));
82-
.withDisabledSmartClean());
96+
.withInitSqlScript(initSQLScript));
8397

8498
return "http://localhost:" + getSutPort();
8599
}
@@ -108,8 +122,8 @@ public String getPackagePrefixesToCover() {
108122

109123
@Override
110124
public void resetStateOfSUT() {
111-
DbCleaner.clearDatabase_H2(sqlConnection, null);
112-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/data.sql");
125+
// DbCleaner.clearDatabase_H2(sqlConnection, null);
126+
// SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/data.sql");
113127
}
114128

115129
@Override
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
INSERT INTO bill (id, number, date_created, total_cost, payed, cc_number) VALUES (1, 271320540, '2019-12-27', 8527, true, '1111222233334444');
2+
3+
INSERT INTO cart (id, total_items, products_cost, delivery_included) VALUES (5, 0, 0, true);
4+
INSERT INTO cart (id, total_items, products_cost, delivery_included) VALUES (6, 0, 0, true);
5+
INSERT INTO cart (id, total_items, products_cost, delivery_included) VALUES (7, 0, 0, true);
6+
INSERT INTO cart (id, total_items, products_cost, delivery_included) VALUES (4, 1, 6517, true);
7+
8+
INSERT INTO cart_item (cart_id, product_id, quantity) VALUES (4, 5, 1);
9+
10+
INSERT INTO contacts (phone, address, id, city_region) VALUES ('+7 123 456 78 90', 'Riesstrasse 18', 4, '13');
11+
INSERT INTO contacts (phone, address, id, city_region) VALUES ('+79211234567', 'sdf', 7, '13');
12+
13+
INSERT INTO customer_order (id, user_account_id, date_created, executed, products_cost, delivery_included, delivery_cost) VALUES (1, 4, '2019-12-27', false, 8127, true, 400);
14+
15+
INSERT INTO distillery (id, title, region_id, description) VALUES (2, 'Balvenie', 6, 'balvenie');
16+
INSERT INTO distillery (id, title, region_id, description) VALUES (6, 'Lagavulin', 4, 'lagavulin');
17+
INSERT INTO distillery (id, title, region_id, description) VALUES (7, 'Laphroaig', 4, 'laphroaig');
18+
INSERT INTO distillery (id, title, region_id, description) VALUES (1, 'Ardbeg', 4, 'ardbeg');
19+
INSERT INTO distillery (id, title, region_id, description) VALUES (3, 'Caol Ila', 4, 'caol ila');
20+
INSERT INTO distillery (id, title, region_id, description) VALUES (4, 'Dalwhinnie', 2, 'dalwhinnie');
21+
INSERT INTO distillery (id, title, region_id, description) VALUES (5, 'Glenkinchie', 5, 'glenkinchie');
22+
INSERT INTO distillery (id, title, region_id, description) VALUES (9, 'Talisker', 3, 'talisker');
23+
INSERT INTO distillery (id, title, region_id, description) VALUES (8, 'Springbank', 1, 'springbank');
24+
25+
INSERT INTO ordered_product (customer_order_id, product_id, quantity) VALUES (1, 8, 1);
26+
27+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (2, 'Uigeadail', 1, 0, 54.200000762939453, 700, 7020, 'Ardbeg Uigedael is named after Loch Uigedael, the lake in the grounds of the distillery Ardbeg which are the water is an important factor in the distilling process. The Uigedael a vatted malt, bottled at 54.2% ABV without cold filtering. Ardbeg Uigedael has no age indication for the expression consists of various malts of different ages. Malts are used partly matured in ex-bourbon and partly on ex-sherry casks.', true);
28+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (10, '10 y.o.', 9, 10, 45.799999237060547, 750, 4683, 'Powerful peat smoke with the salinity of sea water and the moisture of fresh oysters. Full sweetness of dried fruit with smoke and strong aromas of malted barley, warm and intense. Peppery in the mouth. Big, long, warming and peppery on the finish with an attractive sweetness.', true);
29+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (4, '12 y.o.', 3, 12, 43, 700, 4913, 'Smoked ham comes across delicately with citrus and cigar leaves. Fresh and smoky, probably the best part of this whisky. With an almost full body, oil and tar meet subtle smoke. Hints of sweet tastes like honey. Some spices like pepper combined with little sweetness.', true);
30+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (3, '12 y.o. Doublewood', 2, 12, 40, 700, 5403, 'Has clear influences from both bourbon and sherry wood. This malt has only 12 years aged in bourbon casks and then 3 months in young Oloroso casks. The peppery character from the bourbon barrels, penetrates, as it were by the rich and full aroma of Oloroso casks it. The Balvenie Double Wood is therefore a very complex malt.', true);
31+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (7, 'Quarter Cask', 7, 0, 48, 700, 5100, 'A vibrant young Laphroaig whose maturation has been accelerated by ageing in quarter casks. This shows soft sweetness and a velvety feel when first tasted, then the intense peatiness so unique to Laphroaig comes bursting through. A terrific whisky and great value.', true);
32+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (6, '16 y.o.', 6, 16, 43, 750, 6620, 'The Islay representative in the ''Classic Malts'' series is a deep, dry and exceptionally peaty bruiser. Probably the most pungent of all Islay malts, Lagavulin is not for the faint-hearted but inspires fanatical devotion in its many followers.', true);
33+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (8, '12 y.o. Cask Strength Batch 6', 8, 12, 53.099998474121094, 700, 8127, 'Like a storm gathering of the Kintyre coast, dark and ominous, yet tastes so good. The richness comes from the high percentage of sherry casks used in maturation. This is a truly classic Springbank, best enjoyed after dinner, or with your favourite cigar.', true);
34+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (5, '15 y.o.', 4, 15, 43, 750, 6517, 'A good introduction to the delights of single malt whisky – elegant, smooth and medium-bodied, with a light, fruity palate and a whiff of heather on the finish. Part of Diageo''s Classic Malt range. ', true);
35+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (1, 'Ten', 1, 10, 46, 700, 4420, 'Ten Years Old is the basis of the Ardbeg range. After 10 years of maturation in ex-bourbon casks, the whiskey bottled at 46% ABV without cold filtering. The characteristic peat, although clearly present but in perfect balance with the natural sweetness and not predominant in the taste.', false);
36+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (11, '12 y.o.', 5, 12, 43, 700, 4547, 'A light, delicate whiskey; sweet and creamy with a subtle floral aroma. This subtle, refined Lowland is ideal as an aperitif; try it straight from the fridge or freezer.', false);
37+
INSERT INTO product (id, name, distillery_id, age, alcohol, volume, price, description, available) VALUES (9, '18 y.o.', 8, 18, 46, 700, 14490, 'This heavily sherried 18-year-old Springbank has been bottled by Mark Reynier as part of his Renegade series. Distilled in 1995, this sherry hogshead was aged for 10 years in Campbeltown and then moved to Bruichladdich for a further eight years.', true);
38+
39+
INSERT INTO region (id, name, subtitle, color, description) VALUES (3, 'Island', '', 'blue', 'Scotch produced on the islands surrounding the mainland of Scotland offer a very diverse and different taste, they''re not however recognised by the Scotch Whisky Association but are easily grouped together for geographic reasons as one as they''re all islands. Although diverse in flavours, peat and salinity are found in all of the Islands whiskies, the latter because of the vicinity to the sea.
40+
<p><ul>
41+
<li>Number of distilleries: Under 10
42+
<li>Typical flavours: Smoke, Brine, Oil, Black Pepper and Honey
43+
</ul>');
44+
INSERT INTO region (id, name, subtitle, color, description) VALUES (4, 'Islay', '', 'black', 'The Scottish island of Islay (pronounced eye-luh) is located to the west of the mainland and is the smallest Whisky region in terms of area coverage in Scotland. Even though it''s a relatively small island, Islay is currently home to 8 distilleries, 3 of which are World famous, Ardbeg, Laphroaig and Lagavulin. The region is known for its peaty single malts and it''s believed that whisky distillation reached Scotland from Ireland via Islay in the 13th century, hence the high number of past and present distilleries on the island.
45+
<p><ul>
46+
<li>Number of distilleries: Under 10
47+
<li>Typical flavours: Seaweed, Brine, Carbolic Soap, Apple, Smoke and Kippers
48+
</ul>');
49+
INSERT INTO region (id, name, subtitle, color, description) VALUES (1, 'Campbeltown', '', 'purple', 'Campbeltown is part of mainland Scotland but it''s found at the foot of the Mull of Kintyre and was once a thriving whisky hotspot with over 34 distilleries, however it''s now home to just 3. A mixture of improved transportation links to the rival distilleries in the north and a decline in quality as distillers cut corners for mass-production resulting in an inferior product.
50+
<p><ul>
51+
<li>Number of distilleries: Under 5
52+
<li>Typical flavours: Brine, Smoke, Dried Fruit, Vanilla and Toffee
53+
</ul>');
54+
INSERT INTO region (id, name, subtitle, color, description) VALUES (6, 'Speyside', '', 'green', 'The region of Speyside is located in the north east of Scotland surrounding the River Spey, it''s a sub-region to the neighbouring Highlands because of the high density of distilleries in the area. It''s home to the highest number of distilleries in Scotland with well over 60 at present. Speyside is a protected region for Scotch Whisky distilling under UK Government legislation.
55+
<p><ul>
56+
<li>Number of distilleries: Over 60
57+
<li>Typical flavours: Apple, Vanilla, Oak, Malt, Nutmeg and Dried Fruit
58+
</ul>');
59+
INSERT INTO region (id, name, subtitle, color, description) VALUES (2, 'Highland', '', 'brown', 'The Highlands is Scotland''s largest whisky producing area, covering anywhere from the north of Glasgow (the Clyde estuary to the River Tay) all the way to Thurso in the north, not to mention the east and west regions excluding Speyside. Due to the large area, whisky in the Highlands is very diverse and offers a vast amount of different flavours so it''s hard to put a certain style on Whisky from this region.
60+
<p><ul>
61+
<li>Number of distilleries: Over 25
62+
<li>Typical flavours: Fruit Cake, Malt, Oak, Heather, Dried Fruit and Smoke
63+
</ul>');
64+
INSERT INTO region (id, name, subtitle, color, description) VALUES (5, 'Lowland', '', 'yellow', 'Lowlands is the second biggest whisky region in terms of the area it covers, but it''s currently only home to fewer than five distilleries. The Lowlands region covers the south of Scotland up to the north of Glasgow and Edinburgh where it meets the border on the Highlands, the line follows the old county borders running from the Clyde estuary in the west to the River Tay in the east, anything south of this is to the border with England is classified as the ''Lowlands'' in whisky terms.
65+
<p><ul>
66+
<li>Number of distilleries: Under 5
67+
<li>Typical flavours: Grass, Honeysuckle, Cream, Toffee, Toast and Cinnamon
68+
</ul>');
69+
70+
INSERT INTO role (id, title) VALUES (0, 'ROLE_ADMIN');
71+
INSERT INTO role (id, title) VALUES (1, 'ROLE_STAFF');
72+
INSERT INTO role (id, title) VALUES (2, 'ROLE_USER');
73+
74+
INSERT INTO storage (id, available) VALUES (1, true);
75+
INSERT INTO storage (id, available) VALUES (2, true);
76+
INSERT INTO storage (id, available) VALUES (3, true);
77+
INSERT INTO storage (id, available) VALUES (4, true);
78+
INSERT INTO storage (id, available) VALUES (5, true);
79+
INSERT INTO storage (id, available) VALUES (6, true);
80+
INSERT INTO storage (id, available) VALUES (7, true);
81+
INSERT INTO storage (id, available) VALUES (8, true);
82+
INSERT INTO storage (id, available) VALUES (9, true);
83+
INSERT INTO storage (id, available) VALUES (10, true);
84+
INSERT INTO storage (id, available) VALUES (11, true);
85+
86+
INSERT INTO user_account (id, email, password, name, active) VALUES (1, 'admin', '$2a$10$Cmwx2Xr/PVpkibiiDz0s7eaVGZHPUvAu5ivdVC5BJgSYbp3c06FY6', 'Admin', true);
87+
INSERT INTO user_account (id, email, password, name, active) VALUES (4, 'ivan.petrov@yandex.ru', '$2a$10$LfLg6vp4.wyowWP9ysg3F.yQ/udNKfRhGlHJ298xGCtBLC2dDX.OC', 'Ivan Petrov', true);
88+
89+
INSERT INTO user_role (user_id, role_id) VALUES (1, 0);
90+
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
DROP TABLE IF EXISTS bill;
2+
CREATE TABLE bill (
3+
id bigserial NOT NULL,
4+
number integer,
5+
date_created date,
6+
total_cost integer,
7+
payed boolean,
8+
cc_number character varying(19)
9+
);
10+
11+
DROP TABLE IF EXISTS cart;
12+
CREATE TABLE cart (
13+
id bigserial NOT NULL,
14+
total_items integer,
15+
products_cost integer,
16+
delivery_included boolean
17+
);
18+
19+
DROP TABLE IF EXISTS cart_item;
20+
CREATE TABLE cart_item (
21+
cart_id bigint,
22+
product_id bigint,
23+
quantity integer
24+
);
25+
26+
DROP TABLE IF EXISTS contacts;
27+
CREATE TABLE contacts (
28+
id bigserial NOT NULL,
29+
phone character varying(20),
30+
address character varying(100),
31+
city_region character varying(50)
32+
);
33+
34+
DROP TABLE IF EXISTS customer_order;
35+
CREATE TABLE customer_order (
36+
id bigint NOT NULL,
37+
user_account_id bigint,
38+
date_created date,
39+
executed boolean,
40+
products_cost integer,
41+
delivery_included boolean,
42+
delivery_cost integer
43+
);
44+
45+
DROP TABLE IF EXISTS distillery;
46+
CREATE TABLE distillery (
47+
id bigserial NOT NULL,
48+
title character varying(25),
49+
region_id bigint,
50+
description character varying(1000)
51+
);
52+
53+
DROP TABLE IF EXISTS ordered_product;
54+
CREATE TABLE ordered_product (
55+
customer_order_id bigint,
56+
product_id bigint,
57+
quantity integer
58+
);
59+
60+
DROP TABLE IF EXISTS product;
61+
CREATE TABLE product (
62+
id bigserial NOT NULL,
63+
name character varying(45),
64+
distillery_id bigint,
65+
age smallint,
66+
alcohol double precision,
67+
volume integer,
68+
price double precision,
69+
description character varying(1000),
70+
available boolean
71+
);
72+
73+
DROP TABLE IF EXISTS region;
74+
CREATE TABLE region (
75+
id bigserial NOT NULL,
76+
name character varying(20) NOT NULL,
77+
subtitle character varying(20),
78+
color character varying(10),
79+
description character varying(1000)
80+
);
81+
82+
DROP TABLE IF EXISTS role;
83+
CREATE TABLE role (
84+
id bigint NOT NULL,
85+
title character varying(20)
86+
);
87+
88+
DROP TABLE IF EXISTS storage;
89+
CREATE TABLE storage (
90+
id bigserial NOT NULL,
91+
available boolean
92+
);
93+
94+
DROP TABLE IF EXISTS user_account;
95+
CREATE TABLE user_account (
96+
id bigserial NOT NULL,
97+
email character varying(50),
98+
password character varying(255),
99+
name character varying(50),
100+
active boolean
101+
);
102+
103+
DROP TABLE IF EXISTS user_role;
104+
CREATE TABLE user_role (
105+
user_id bigint,
106+
role_id bigint
107+
);

jdk_11_maven/em/external/rest/market/src/main/java/em/external/market/ExternalEvoMasterController.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
import org.evomaster.client.java.controller.api.dto.SutInfoDto;
88
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
99
import org.evomaster.client.java.controller.db.DbCleaner;
10+
import org.evomaster.client.java.controller.db.SqlScriptRunner;
1011
import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;
1112
import org.evomaster.client.java.controller.internal.db.DbSpecification;
1213
import org.evomaster.client.java.controller.problem.ProblemInfo;
1314
import org.evomaster.client.java.controller.problem.RestProblem;
1415
import org.h2.tools.Server;
1516

17+
import java.io.InputStream;
18+
import java.io.InputStreamReader;
1619
import java.sql.Connection;
1720
import java.sql.DriverManager;
1821
import java.sql.SQLException;
@@ -65,6 +68,10 @@ public static void main(String[] args) {
6568
private List<DbSpecification> dbSpecification;
6669
private Server h2;
6770

71+
private String INIT_DB_SCRIPT_PATH = "/data.sql";
72+
73+
private String initSQLScript;
74+
6875
public ExternalEvoMasterController() {
6976
this(40100, "../core/target", 12345, 120, "java");
7077
}
@@ -81,6 +88,12 @@ public ExternalEvoMasterController(int controllerPort, String jarLocation, int s
8188
this.timeoutSeconds = timeoutSeconds;
8289
setControllerPort(controllerPort);
8390
setJavaCommand(command);
91+
92+
try (InputStream in = getClass().getResourceAsStream(INIT_DB_SCRIPT_PATH)) {
93+
initSQLScript = String.join(System.lineSeparator(), (new SqlScriptRunner()).readCommands(new InputStreamReader(in)));
94+
} catch (Exception e) {
95+
throw new RuntimeException(e);
96+
}
8497
}
8598

8699
private String dbUrl( ) {
@@ -145,19 +158,21 @@ public void postStart() {
145158
try {
146159
Class.forName("org.h2.Driver");
147160
sqlConnection = DriverManager.getConnection(dbUrl(), "sa", "");
161+
162+
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/schema.sql");
163+
DbCleaner.clearDatabase_H2(sqlConnection);
164+
148165
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection)
149-
.withDisabledSmartClean());
166+
.withInitSqlScript(initSQLScript));
150167
} catch (Exception e) {
151168
throw new RuntimeException(e);
152169
}
153-
154-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/schema.sql");
155170
}
156171

157172
@Override
158173
public void resetStateOfSUT() {
159-
DbCleaner.clearDatabase_H2(sqlConnection);
160-
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/data.sql");
174+
// DbCleaner.clearDatabase_H2(sqlConnection);
175+
// SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/data.sql");
161176
}
162177

163178
@Override
@@ -219,4 +234,4 @@ public List<AuthenticationDto> getInfoForAuthentication() {
219234
public List<DbSpecification> getDbSpecifications() {
220235
return dbSpecification;
221236
}
222-
}
237+
}

0 commit comments

Comments
 (0)