Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ For simplicity, all schemas are also available as JSON/YML files under the folde

* **Spring-batch-rest** (Apache), [jdk_8_maven/cs/rest/original/spring-batch-rest](jdk_8_maven/cs/rest/original/spring-batch-rest), from [https://github.com/chrisgleissner/spring-batch-rest](https://github.com/chrisgleissner/spring-batch-rest)

* **Spring Boot Restful API Example** (MIT), [jdk_17_maven/cs/rest/spring-rest-example](jdk_17_maven/cs/rest/spring-rest-example), from [https://github.com/phantasmicmeans/spring-boot-restful-api-example](https://github.com/phantasmicmeans/spring-boot-restful-api-example)
Copy link
Contributor

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?


* **Tiltaksgjennomføring API** (MIT), [jdk_17_maven/cs/rest/tiltaksgjennomforing-api](jdk_17_maven/cs/rest/tiltaksgjennomforing-api), from [https://github.com/navikt/tiltaksgjennomforing-api](https://github.com/navikt/tiltaksgjennomforing-api)

* **User Management** (MIT), [jdk_8_maven/cs/rest/original/user-management](jdk_8_maven/cs/rest/original/user-management), from [https://github.com/andreagiassi/microservice-rbac-user-management](https://github.com/andreagiassi/microservice-rbac-user-management)
Expand Down
17 changes: 17 additions & 0 deletions dockerfiles/spring-rest-example.dockerfile
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"
38 changes: 38 additions & 0 deletions dockerfiles/spring-rest-example.yaml
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


1 change: 1 addition & 0 deletions jdk_17_maven/em/embedded/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<module>familie-ba-sak</module>
<module>tiltaksgjennomforing-api</module>
<module>ohsome-api</module>
<module>spring-rest-example</module>


<!-- <module>signal-server</module>-->
Expand Down
42 changes: 42 additions & 0 deletions jdk_17_maven/em/embedded/rest/spring-rest-example/pom.xml
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>
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;
}
}
1 change: 1 addition & 0 deletions jdk_17_maven/em/external/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<module>familie-ba-sak</module>
<module>tiltaksgjennomforing-api</module>
<module>ohsome-api</module>
<module>spring-rest-example</module>
</modules>

</project>
70 changes: 70 additions & 0 deletions jdk_17_maven/em/external/rest/spring-rest-example/pom.xml
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>
Loading