-
Notifications
You must be signed in to change notification settings - Fork 22
spring-rest-example drivers #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| FROM amazoncorretto:17-alpine-jdk | ||
|
|
||
| COPY ./dist/spring-rest-example-sut.jar . | ||
| COPY ./dist/jacocoagent.jar . | ||
|
|
||
|
|
||
|
|
||
| #ENV TOOL="undefined" | ||
| #ENV RUN="0" | ||
|
|
||
| ENTRYPOINT \ | ||
| java \ | ||
| # unfortunately dumponexit is completely unreliable in Docker :( | ||
| # -javaagent:jacocoagent.jar=destfile=./jacoco/spring-rest-example__${TOOL}__${RUN}__jacoco.exec,append=false,dumponexit=true \ | ||
| -javaagent:jacocoagent.jar=output=tcpserver,address=*,port=6300,append=false,dumponexit=false \ | ||
| -jar spring-rest-example-sut.jar \ | ||
| --server.port=8080 --spring.datasource.username=root --spring.datasource.password=root --spring.datasource.url="jdbc:mysql://db:3306/example?useSSL=false&allowPublicKeyRetrieval=true" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| services: | ||
| sut-spring-rest-example: | ||
| build: | ||
| dockerfile: ./dockerfiles/spring-rest-example.dockerfile | ||
| context: .. | ||
| # environment: | ||
| # TOOL: ${TOOL:-undefined} | ||
| # RUN: ${RUN:-0} | ||
| ports: | ||
| - "${HOST_PORT:-8080}:8080" | ||
| - "${JACOCO_PORT:-6300}:6300" | ||
| # volumes: | ||
| # default env does not work on volumes | ||
| # - ${JACOCODIR}:/jacoco | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
|
|
||
| db: | ||
| image: mysql:8.0 | ||
| tmpfs: | ||
| - '/var/lib/mysql' | ||
|
|
||
|
|
||
| environment: | ||
| MYSQL_ROOT_PASSWORD: root | ||
| MYSQL_DATABASE: example | ||
|
|
||
|
|
||
|
|
||
|
|
||
| healthcheck: | ||
| test: ["CMD", "mysqladmin", "ping", "-h", "localhost"] | ||
| interval: 30s | ||
| timeout: 30s | ||
| retries: 3 | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.evomaster</groupId> | ||
| <artifactId>evomaster-benchmark-jdk17-em-embedded-rest</artifactId> | ||
| <version>3.4.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>evomaster-benchmark-jdk17-em-embedded-rest-spring-rest-example</artifactId> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-dependencies</artifactId> | ||
| <version>3.0.4</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.example</groupId> | ||
| <artifactId>spring-rest-example</artifactId> | ||
| <version>0.0.1</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>testcontainers</artifactId> | ||
| <version>1.19.1</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
|
|
||
| </project> |
142 changes: 142 additions & 0 deletions
142
...est-example/src/main/java/em/embedded/com/example/spring/EmbeddedEvoMasterController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| package em.embedded.com.example.spring; | ||
|
|
||
| import com.sw.project.ProjectApiApplication; | ||
| import org.evomaster.client.java.controller.EmbeddedSutController; | ||
| import org.evomaster.client.java.controller.InstrumentedSutStarter; | ||
| import org.evomaster.client.java.controller.api.dto.SutInfoDto; | ||
| import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto; | ||
| import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType; | ||
| import org.evomaster.client.java.controller.problem.ProblemInfo; | ||
| import org.evomaster.client.java.controller.problem.RestProblem; | ||
| import org.evomaster.client.java.sql.DbSpecification; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.context.ConfigurableApplicationContext; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.testcontainers.containers.GenericContainer; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
| import java.util.*; | ||
|
|
||
| public class EmbeddedEvoMasterController extends EmbeddedSutController { | ||
|
|
||
| private static final GenericContainer mysql = new GenericContainer("mysql:8.0" ) | ||
| .withEnv(new HashMap<String, String>(){{ | ||
| put("MYSQL_ROOT_PASSWORD", "root"); | ||
| put("MYSQL_DATABASE", "example"); | ||
| }}) | ||
| .withExposedPorts(3306) | ||
| .withTmpFs(Collections.singletonMap("/var/lib/mysql", "rw")); | ||
|
|
||
| private ConfigurableApplicationContext ctx; | ||
|
|
||
| private Connection sqlConnection; | ||
| private List<DbSpecification> dbSpecification; | ||
|
|
||
|
|
||
| public EmbeddedEvoMasterController() { | ||
| this(40100); | ||
| } | ||
|
|
||
| public EmbeddedEvoMasterController(int port) { | ||
| setControllerPort(port); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| int port = 40100; | ||
| if (args.length > 0) { | ||
| port = Integer.parseInt(args[0]); | ||
| } | ||
|
|
||
| EmbeddedEvoMasterController controller = new EmbeddedEvoMasterController(port); | ||
| InstrumentedSutStarter starter = new InstrumentedSutStarter(controller); | ||
|
|
||
| starter.start(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSutRunning() { | ||
| return ctx!=null && ctx.isRunning(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPackagePrefixesToCover() { | ||
| return "com.sw.project."; | ||
| } | ||
|
|
||
| @Override | ||
| public List<AuthenticationDto> getInfoForAuthentication() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public ProblemInfo getProblemInfo() { | ||
| return new RestProblem( | ||
| "http://localhost:" + getSutPort() + "/v3/api-docs", | ||
| null | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public SutInfoDto.OutputFormat getPreferredOutputFormat() { | ||
| return SutInfoDto.OutputFormat.JAVA_JUNIT_5; | ||
| } | ||
|
|
||
| @Override | ||
| public String startSut() { | ||
| mysql.start(); | ||
|
|
||
| String host = mysql.getContainerIpAddress(); | ||
| int port = mysql.getMappedPort(3306); | ||
| String url = "jdbc:mysql://"+host+":"+port+"/example?useSSL=false&allowPublicKeyRetrieval=true"; | ||
|
|
||
| ctx = SpringApplication.run(ProjectApiApplication.class, new String[]{ | ||
| "--server.port=0", | ||
| "--spring.datasource.url="+url, | ||
| "--spring.datasource.username=root", | ||
| "--spring.datasource.password=root", | ||
| "--management.server.port=-1", | ||
| "--logging.level.root=OFF", | ||
| "--logging.level.org.springframework=INFO" | ||
| }); | ||
|
|
||
| if (sqlConnection != null) { | ||
| try { | ||
| sqlConnection.close(); | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| JdbcTemplate jdbc = ctx.getBean(JdbcTemplate.class); | ||
| try { | ||
| sqlConnection = jdbc.getDataSource().getConnection(); | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| dbSpecification = Arrays.asList(new DbSpecification(DatabaseType.MYSQL,sqlConnection)); | ||
|
|
||
| return "http://localhost:" + getSutPort(); | ||
| } | ||
|
|
||
| protected int getSutPort() { | ||
| return (Integer) ((Map) ctx.getEnvironment() | ||
| .getPropertySources().get("server.ports").getSource()) | ||
| .get("local.server.port"); | ||
| } | ||
|
|
||
| @Override | ||
| public void stopSut() { | ||
| ctx.stop(); | ||
| mysql.stop(); | ||
| } | ||
|
|
||
| @Override | ||
| public void resetStateOfSUT() { | ||
| } | ||
|
|
||
| @Override | ||
| public List<DbSpecification> getDbSpecifications() { | ||
| return dbSpecification; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.evomaster</groupId> | ||
| <artifactId>evomaster-benchmark-jdk17-em-external-rest</artifactId> | ||
| <version>3.4.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>evomaster-benchmark-jdk17-em-external-rest-spring-rest-example</artifactId> | ||
| <packaging>jar</packaging> | ||
|
|
||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>testcontainers</artifactId> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>4.12</version> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>mysql</groupId> | ||
| <artifactId>mysql-connector-java</artifactId> | ||
| <version>8.0.33</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-shade-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>shade</goal> | ||
| </goals> | ||
| <configuration> | ||
| <finalName>spring-rest-example-evomaster-runner</finalName> | ||
| <transformers> | ||
| <transformer | ||
| implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
| <manifestEntries> | ||
| <Main-Class>em.external.com.example.spring.ExternalEvoMasterController | ||
| </Main-Class> | ||
| <Premain-Class>org.evomaster.client.java.instrumentation.InstrumentingAgent | ||
| </Premain-Class> | ||
| <Agent-Class>org.evomaster.client.java.instrumentation.InstrumentingAgent | ||
| </Agent-Class> | ||
| <Can-Redefine-Classes>true</Can-Redefine-Classes> | ||
| <Can-Retransform-Classes>true</Can-Retransform-Classes> | ||
| </manifestEntries> | ||
| </transformer> | ||
| </transformers> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the SUT counter at the top of this list not getting updated?