Skip to content

Commit 901ef76

Browse files
committed
starting with embedded driver
1 parent c62bfaf commit 901ef76

6 files changed

Lines changed: 276 additions & 0 deletions

File tree

jdk_17_maven/em/embedded/pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.evomaster</groupId>
7+
<artifactId>evomaster-benchmark-jdk17-em</artifactId>
8+
<version>1.6.2-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>evomaster-benchmark-jdk17-em-embedded</artifactId>
12+
<packaging>pom</packaging>
13+
14+
<modules>
15+
<module>web</module>
16+
</modules>
17+
18+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.evomaster</groupId>
7+
<artifactId>evomaster-benchmark-jdk17-em-embedded</artifactId>
8+
<version>1.6.2-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>evomaster-benchmark-jdk17-em-embedded-web</artifactId>
12+
<packaging>pom</packaging>
13+
14+
15+
<modules>
16+
<module>spring-petclinic</module>
17+
</modules>
18+
19+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<artifactId>evomaster-benchmark-jdk17-em-embedded-web-spring-petclinic</artifactId>
8+
<packaging>jar</packaging>
9+
10+
<parent>
11+
<groupId>org.evomaster</groupId>
12+
<artifactId>evomaster-benchmark-jdk17-em-embedded-web</artifactId>
13+
<version>1.6.2-SNAPSHOT</version>
14+
</parent>
15+
16+
17+
<dependencies>
18+
19+
</dependencies>
20+
21+
22+
23+
</project>
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package em.embedded.market;
2+
3+
4+
import org.evomaster.client.java.controller.AuthUtils;
5+
import org.evomaster.client.java.controller.EmbeddedSutController;
6+
import org.evomaster.client.java.controller.InstrumentedSutStarter;
7+
import org.evomaster.client.java.controller.api.dto.AuthenticationDto;
8+
import org.evomaster.client.java.controller.api.dto.SutInfoDto;
9+
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
10+
import org.evomaster.client.java.controller.db.DbCleaner;
11+
import org.evomaster.client.java.controller.db.SqlScriptRunner;
12+
import org.evomaster.client.java.controller.db.SqlScriptRunnerCached;
13+
import org.evomaster.client.java.controller.internal.db.DbSpecification;
14+
import org.evomaster.client.java.controller.problem.ProblemInfo;
15+
import org.evomaster.client.java.controller.problem.RestProblem;
16+
import org.springframework.boot.SpringApplication;
17+
import org.springframework.context.ConfigurableApplicationContext;
18+
import org.springframework.jdbc.core.JdbcTemplate;
19+
20+
import java.sql.Connection;
21+
import java.sql.SQLException;
22+
import java.util.Arrays;
23+
import java.util.List;
24+
import java.util.Map;
25+
import java.util.Scanner;
26+
27+
/**
28+
* Class used to start/stop the SUT. This will be controller by the EvoMaster process
29+
*/
30+
public class EmbeddedEvoMasterController extends EmbeddedSutController {
31+
32+
FIXME
33+
public static void main(String[] args) {
34+
35+
int port = 40100;
36+
if (args.length > 0) {
37+
port = Integer.parseInt(args[0]);
38+
}
39+
40+
EmbeddedEvoMasterController controller = new EmbeddedEvoMasterController(port);
41+
InstrumentedSutStarter starter = new InstrumentedSutStarter(controller);
42+
43+
starter.start();
44+
}
45+
46+
47+
private ConfigurableApplicationContext ctx;
48+
private Connection sqlConnection;
49+
private List<DbSpecification> dbSpecification;
50+
51+
52+
public EmbeddedEvoMasterController() {
53+
this(40100);
54+
}
55+
56+
public EmbeddedEvoMasterController(int port) {
57+
setControllerPort(port);
58+
}
59+
60+
@Override
61+
public String startSut() {
62+
63+
ctx = SpringApplication.run(market.RestApplication.class, new String[]{
64+
"--server.port=0",
65+
"--spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;"
66+
});
67+
68+
if (sqlConnection != null) {
69+
try {
70+
sqlConnection.close();
71+
} catch (SQLException e) {
72+
throw new RuntimeException(e);
73+
}
74+
}
75+
JdbcTemplate jdbc = ctx.getBean(JdbcTemplate.class);try {
76+
sqlConnection = jdbc.getDataSource().getConnection();
77+
} catch (SQLException e) {
78+
throw new RuntimeException(e);
79+
}
80+
81+
dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.H2,sqlConnection)
82+
//.withInitSqlOnResourcePath("/data.sql"));
83+
.withDisabledSmartClean());
84+
85+
return "http://localhost:" + getSutPort();
86+
}
87+
88+
protected int getSutPort() {
89+
return (Integer) ((Map) ctx.getEnvironment()
90+
.getPropertySources().get("server.ports").getSource())
91+
.get("local.server.port");
92+
}
93+
94+
95+
@Override
96+
public boolean isSutRunning() {
97+
return ctx != null && ctx.isRunning();
98+
}
99+
100+
@Override
101+
public void stopSut() {
102+
ctx.stop();
103+
}
104+
105+
@Override
106+
public String getPackagePrefixesToCover() {
107+
return "market.";
108+
}
109+
110+
@Override
111+
public void resetStateOfSUT() {
112+
DbCleaner.clearDatabase_H2(sqlConnection, null);
113+
SqlScriptRunnerCached.runScriptFromResourceFile(sqlConnection,"/data.sql");
114+
}
115+
116+
@Override
117+
public ProblemInfo getProblemInfo() {
118+
119+
return new RestProblem(
120+
"http://localhost:" + getSutPort() + "/v2/api-docs",
121+
null,
122+
null
123+
);
124+
}
125+
126+
@Override
127+
public SutInfoDto.OutputFormat getPreferredOutputFormat() {
128+
return SutInfoDto.OutputFormat.JAVA_JUNIT_5;
129+
}
130+
131+
@Override
132+
public List<AuthenticationDto> getInfoForAuthentication() {
133+
return Arrays.asList(
134+
AuthUtils.getForBasic("admin","admin","password"),
135+
AuthUtils.getForBasic("user", "ivan.petrov@yandex.ru", "petrov")
136+
);
137+
}
138+
139+
140+
141+
@Override
142+
public List<DbSpecification> getDbSpecifications() {
143+
return dbSpecification;
144+
}
145+
}

jdk_17_maven/em/pom.xml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.evomaster</groupId>
7+
<artifactId>evomaster-benchmark-jdk17</artifactId>
8+
<version>1.6.2-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>evomaster-benchmark-jdk17-em</artifactId>
12+
<packaging>pom</packaging>
13+
14+
<modules>
15+
<module>external</module>
16+
<module>embedded</module>
17+
</modules>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.evomaster</groupId>
22+
<artifactId>evomaster-client-java-controller</artifactId>
23+
<version>${evomaster-version}</version>
24+
<exclusions>
25+
<!--
26+
At the moment, we use an old version in EM, due to some
27+
issues/headaches in upgrading Jetty.
28+
So, to avoid conflicts, we just exclude it here
29+
-->
30+
<exclusion>
31+
<groupId>javax.validation</groupId>
32+
<artifactId>validation-api</artifactId>
33+
</exclusion>
34+
</exclusions>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.evomaster</groupId>
38+
<artifactId>evomaster-client-java-dependencies</artifactId>
39+
<version>${evomaster-version}</version>
40+
<scope>test</scope>
41+
</dependency>
42+
</dependencies>
43+
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-compiler-plugin</artifactId>
50+
<version>3.5.1</version>
51+
<configuration>
52+
<source>17</source>
53+
<target>17</target>
54+
</configuration>
55+
</plugin>
56+
</plugins>
57+
<pluginManagement>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-shade-plugin</artifactId>
62+
<version>3.0.0</version>
63+
</plugin>
64+
</plugins>
65+
</pluginManagement>
66+
</build>
67+
68+
69+
70+
</project>

jdk_17_maven/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
</configuration>
6262
</plugin>
6363
</plugins>
64+
6465
</build>
6566

6667
</project>

0 commit comments

Comments
 (0)