Skip to content

Commit b820d03

Browse files
committed
working on external for pay-publicapi
1 parent 162c4ef commit b820d03

6 files changed

Lines changed: 403 additions & 9 deletions

File tree

jdk_11_maven/cs/rest/pay-publicapi/openapi/publicapi_spec.json

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,32 @@
15581558
}
15591559
}
15601560
},
1561+
"CardDetailsFromResponse" : {
1562+
"type" : "object",
1563+
"properties" : {
1564+
"billing_address" : {
1565+
"$ref" : "#/components/schemas/Address"
1566+
},
1567+
"card_brand" : {
1568+
"type" : "string"
1569+
},
1570+
"card_type" : {
1571+
"type" : "string"
1572+
},
1573+
"cardholder_name" : {
1574+
"type" : "string"
1575+
},
1576+
"expiry_date" : {
1577+
"type" : "string"
1578+
},
1579+
"first_digits_card_number" : {
1580+
"type" : "string"
1581+
},
1582+
"last_digits_card_number" : {
1583+
"type" : "string"
1584+
}
1585+
}
1586+
},
15611587
"CreateAgreementRequest" : {
15621588
"type" : "object",
15631589
"description" : "The Agreement Request Payload",
@@ -1680,7 +1706,7 @@
16801706
"example" : 1200
16811707
},
16821708
"card_details" : {
1683-
"$ref" : "#/components/schemas/CardDetails"
1709+
"$ref" : "#/components/schemas/CardDetailsFromResponse"
16841710
},
16851711
"created_date" : {
16861712
"type" : "string",
@@ -2111,7 +2137,7 @@
21112137
"type" : "object",
21122138
"properties" : {
21132139
"CardDetails" : {
2114-
"$ref" : "#/components/schemas/CardDetails"
2140+
"$ref" : "#/components/schemas/CardDetailsFromResponse"
21152141
},
21162142
"created_date" : {
21172143
"type" : "string",

jdk_11_maven/cs/rest/pay-publicapi/pom.xml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,23 @@
2727
<PACT_CONSUMER_TAG/>
2828
</properties>
2929

30-
<parent>
31-
<groupId>io.dropwizard</groupId>
32-
<artifactId>dropwizard-dependencies</artifactId>
33-
<version>2.1.7</version>
34-
</parent>
30+
<!-- <parent>-->
31+
<!-- <groupId>io.dropwizard</groupId>-->
32+
<!-- <artifactId>dropwizard-dependencies</artifactId>-->
33+
<!-- <version>2.1.7</version>-->
34+
<!-- <relativePath/>-->
35+
<!-- </parent>-->
36+
37+
<dependencyManagement>
38+
<dependencies>
39+
<dependency>
40+
<groupId>io.dropwizard</groupId>
41+
<artifactId>dropwizard-dependencies</artifactId>
42+
<version>2.1.7</version>
43+
<type>pom</type>
44+
</dependency>
45+
</dependencies>
46+
</dependencyManagement>
3547

3648
<dependencies>
3749
<dependency>
@@ -452,8 +464,8 @@
452464
<artifactId>maven-shade-plugin</artifactId>
453465
<version>3.5.0</version>
454466
<configuration>
455-
<outputFile>target/${project.artifactId}-${project.version}-allinone.jar
456-
</outputFile>
467+
<!-- <outputFile>target/${project.artifactId}-${project.version}-allinone.jar-->
468+
<!-- </outputFile>-->
457469
<filters>
458470
<filter>
459471
<artifact>*:*</artifact>
@@ -472,6 +484,7 @@
472484
<goal>shade</goal>
473485
</goals>
474486
<configuration>
487+
<finalName>pay-publicapi-sut</finalName>
475488
<transformers>
476489
<transformer
477490
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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-jdk11-em-external-rest-pay-publicapi</artifactId>
8+
<packaging>jar</packaging>
9+
10+
<parent>
11+
<groupId>org.evomaster</groupId>
12+
<artifactId>evomaster-benchmark-jdk11-em-external-rest</artifactId>
13+
<version>2.0.1-SNAPSHOT</version>
14+
</parent>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.testcontainers</groupId>
19+
<artifactId>testcontainers</artifactId>
20+
<scope>compile</scope>
21+
</dependency>
22+
</dependencies>
23+
24+
<build>
25+
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-shade-plugin</artifactId>
29+
<executions>
30+
<execution>
31+
<phase>package</phase>
32+
<goals>
33+
<goal>shade</goal>
34+
</goals>
35+
<configuration>
36+
<finalName>pay-publicapi-evomaster-runner</finalName>
37+
<transformers>
38+
<transformer
39+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
40+
<manifestEntries>
41+
<Main-Class>em.external.uk.gov.pay.api.app.ExternalEvoMasterController
42+
</Main-Class>
43+
<Premain-Class>org.evomaster.client.java.instrumentation.InstrumentingAgent
44+
</Premain-Class>
45+
<Agent-Class>org.evomaster.client.java.instrumentation.InstrumentingAgent
46+
</Agent-Class>
47+
<Can-Redefine-Classes>true</Can-Redefine-Classes>
48+
<Can-Retransform-Classes>true</Can-Retransform-Classes>
49+
</manifestEntries>
50+
</transformer>
51+
</transformers>
52+
</configuration>
53+
</execution>
54+
</executions>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
59+
60+
</project>
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
package em.external.uk.gov.pay.api.app;
2+
3+
import org.evomaster.client.java.controller.AuthUtils;
4+
import org.evomaster.client.java.controller.ExternalSutController;
5+
import org.evomaster.client.java.controller.InstrumentedSutStarter;
6+
import org.evomaster.client.java.controller.api.dto.SutInfoDto;
7+
import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto;
8+
import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType;
9+
import org.evomaster.client.java.controller.problem.ProblemInfo;
10+
import org.evomaster.client.java.controller.problem.RestProblem;
11+
import org.evomaster.client.java.sql.DbCleaner;
12+
import org.evomaster.client.java.sql.DbSpecification;
13+
import org.h2.tools.Server;
14+
import org.testcontainers.containers.GenericContainer;
15+
import redis.clients.jedis.Jedis;
16+
import redis.clients.jedis.JedisPool;
17+
18+
import java.io.File;
19+
import java.io.InputStream;
20+
import java.nio.file.Files;
21+
import java.nio.file.Path;
22+
import java.nio.file.Paths;
23+
import java.nio.file.StandardCopyOption;
24+
import java.sql.Connection;
25+
import java.sql.DriverManager;
26+
import java.sql.SQLException;
27+
import java.util.Arrays;
28+
import java.util.List;
29+
30+
public class ExternalEvoMasterController extends ExternalSutController {
31+
32+
public static void main(String[] args) {
33+
34+
int controllerPort = 40100;
35+
if (args.length > 0) {
36+
controllerPort = Integer.parseInt(args[0]);
37+
}
38+
int sutPort = 12345;
39+
if (args.length > 1) {
40+
sutPort = Integer.parseInt(args[1]);
41+
}
42+
String jarLocation = "cs/rest/pay-publicapi/target";
43+
if(args.length > 2){
44+
jarLocation = args[2];
45+
}
46+
if(! jarLocation.endsWith(".jar")) {
47+
jarLocation += "/pay-publicapi-sut.jar";
48+
}
49+
int timeoutSeconds = 120;
50+
if(args.length > 3){
51+
timeoutSeconds = Integer.parseInt(args[3]);
52+
}
53+
String command = "java";
54+
if(args.length > 4){
55+
command = args[4];
56+
}
57+
58+
59+
60+
ExternalEvoMasterController controller =
61+
new ExternalEvoMasterController(controllerPort, jarLocation, sutPort, timeoutSeconds, command);
62+
InstrumentedSutStarter starter = new InstrumentedSutStarter(controller);
63+
64+
starter.start();
65+
}
66+
67+
68+
private final int timeoutSeconds;
69+
private final int sutPort;
70+
71+
private String jarLocation;
72+
private final String CONFIG_FILE = "em_config.yaml";
73+
74+
private static final int REDIS_PORT = 6379;
75+
76+
private static final String REDIS_VERSION = "7.2.3";
77+
78+
private static final GenericContainer redisContainer = new GenericContainer("redis:" + REDIS_VERSION)
79+
.withExposedPorts(REDIS_PORT);
80+
81+
private static String REDIS_URL = "";
82+
83+
private static JedisPool jedisPool;
84+
85+
public ExternalEvoMasterController(){
86+
this(40100, "../api/target", 12345, 120, "java");
87+
}
88+
89+
public ExternalEvoMasterController(String jarLocation) {
90+
this();
91+
this.jarLocation = jarLocation;
92+
}
93+
94+
public ExternalEvoMasterController(int controllerPort,
95+
String jarLocation,
96+
int sutPort,
97+
int timeoutSeconds,
98+
String command) {
99+
this.sutPort = sutPort;
100+
this.jarLocation = jarLocation;
101+
this.timeoutSeconds = timeoutSeconds;
102+
setControllerPort(controllerPort);
103+
setJavaCommand(command);
104+
createConfigurationFile();
105+
}
106+
107+
108+
/**
109+
Unfortunately, it seems like Dropwizard is buggy, and has
110+
problems with overriding params without a YML file :(
111+
*/
112+
private void createConfigurationFile() {
113+
114+
//save config to same folder of JAR file
115+
Path path = getConfigPath();
116+
117+
try(InputStream is = this.getClass().getResourceAsStream("/"+ CONFIG_FILE )){
118+
Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING);
119+
} catch (Exception e){
120+
throw new RuntimeException(e);
121+
}
122+
}
123+
124+
private Path getConfigPath(){
125+
return Paths.get(jarLocation)
126+
.toAbsolutePath()
127+
.getParent()
128+
.resolve(CONFIG_FILE)
129+
.normalize();
130+
}
131+
132+
@Override
133+
public String[] getInputParameters() {
134+
return new String[]{"server", getConfigPath().toAbsolutePath().toString()};
135+
}
136+
137+
@Override
138+
public String[] getJVMParameters() {
139+
140+
return new String[]{
141+
"-Ddw.server.applicationConnectors[0].port="+sutPort,
142+
"-Ddw.server.adminConnectors[0].port=0",
143+
"-Ddw.redis.endpoint="+REDIS_URL
144+
};
145+
}
146+
147+
@Override
148+
public String getBaseURL() {
149+
return "http://localhost:"+sutPort;
150+
}
151+
152+
@Override
153+
public String getPathToExecutableJar() {
154+
return jarLocation;
155+
}
156+
157+
@Override
158+
public String getLogMessageOfInitializedServer() {
159+
return "Server: Started";
160+
}
161+
162+
@Override
163+
public long getMaxAwaitForInitializationInSeconds() {
164+
return timeoutSeconds;
165+
}
166+
167+
@Override
168+
public void preStart() {
169+
redisContainer.start();
170+
171+
REDIS_URL = redisContainer.getHost() + redisContainer.getMappedPort(REDIS_PORT);
172+
173+
jedisPool = new JedisPool(redisContainer.getHost(), redisContainer.getMappedPort(REDIS_PORT));
174+
}
175+
176+
@Override
177+
public void postStart() {
178+
179+
resetStateOfSUT();
180+
}
181+
182+
@Override
183+
public void preStop() {
184+
185+
}
186+
187+
@Override
188+
public void postStop() {
189+
redisContainer.stop();
190+
}
191+
192+
@Override
193+
public String getPackagePrefixesToCover() {
194+
return "uk.gov.pay.api.";
195+
}
196+
197+
@Override
198+
public void resetStateOfSUT() {
199+
try (Jedis jedis = jedisPool.getResource()) {
200+
jedis.flushAll();
201+
}
202+
}
203+
204+
@Override
205+
public ProblemInfo getProblemInfo() {
206+
return new RestProblem(
207+
getBaseURL() + "/assets/swagger.json",
208+
null
209+
);
210+
}
211+
212+
@Override
213+
public SutInfoDto.OutputFormat getPreferredOutputFormat() {
214+
return SutInfoDto.OutputFormat.JAVA_JUNIT_5;
215+
}
216+
217+
@Override
218+
public List<AuthenticationDto> getInfoForAuthentication() {
219+
//TODO
220+
return null;
221+
}
222+
223+
224+
@Override
225+
public List<DbSpecification> getDbSpecifications() {
226+
return null;
227+
}
228+
}

0 commit comments

Comments
 (0)