Skip to content

Commit f1f18b8

Browse files
Dedicated integration test module + better setup for MTX sidecar there (#217)
+ New module `bookshop-integration-tests` (based on `mvn com.sap.cds:cds-maven-plugin:addIntegrationTest`) wraps the `FeatureTogglesIT` and all MTX sidecar-related setup. + `pm2` is used instead of `forever`. JaCoCo and surefire config generated by the template are removed. --------- Co-authored-by: Marc Becker <[email protected]>
1 parent 7c17187 commit f1f18b8

File tree

5 files changed

+125
-65
lines changed

5 files changed

+125
-65
lines changed

integration-tests/pom.xml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>my</groupId>
8+
<artifactId>bookshop-parent</artifactId>
9+
<version>${revision}</version>
10+
</parent>
11+
12+
<artifactId>bookshop-integration-tests</artifactId>
13+
14+
<name>bookshop-integration-tests</name>
15+
16+
<properties>
17+
<sidecar.dir>../mtx/sidecar</sidecar.dir>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>my</groupId>
23+
<artifactId>bookshop</artifactId>
24+
<version>${revision}</version>
25+
<exclusions>
26+
<exclusion>
27+
<groupId>ch.qos.logback</groupId>
28+
<artifactId>logback-classic</artifactId>
29+
</exclusion>
30+
</exclusions>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.security</groupId>
41+
<artifactId>spring-security-test</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
</dependencies>
45+
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-surefire-plugin</artifactId>
51+
<version>3.0.0</version>
52+
<configuration>
53+
<failIfNoTests>false</failIfNoTests>
54+
</configuration>
55+
</plugin>
56+
57+
<plugin>
58+
<!-- Tests ending with *IT.java will be executed here -->
59+
<groupId>org.apache.maven.plugins</groupId>
60+
<artifactId>maven-failsafe-plugin</artifactId>
61+
<version>3.0.0</version>
62+
<executions>
63+
<execution>
64+
<id>integration-tests</id>
65+
<phase>integration-test</phase>
66+
<goals>
67+
<goal>integration-test</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
73+
<plugin>
74+
<groupId>com.sap.cds</groupId>
75+
<artifactId>cds-maven-plugin</artifactId>
76+
<version>${cds.services.version}</version>
77+
<executions>
78+
<!-- Following steps start and stop MTX sidecar for tests executed by failsafe plugin -->
79+
<execution>
80+
<id>install-sidecar</id>
81+
<goals>
82+
<goal>npm</goal>
83+
</goals>
84+
<phase>pre-integration-test</phase>
85+
<configuration>
86+
<arguments>install</arguments>
87+
<skip>${skipTests}</skip>
88+
<workingDirectory>${sidecar.dir}</workingDirectory>
89+
</configuration>
90+
</execution>
91+
92+
<execution>
93+
<id>start-sidecar</id>
94+
<goals>
95+
<goal>npx</goal>
96+
</goals>
97+
<phase>pre-integration-test</phase>
98+
<configuration>
99+
<arguments>pm2 -l sidecar.log --time start --name=sidecar npm -- run start</arguments>
100+
<skip>${skipTests}</skip>
101+
<workingDirectory>${sidecar.dir}</workingDirectory>
102+
</configuration>
103+
</execution>
104+
105+
<execution>
106+
<id>stop-sidecar</id>
107+
<goals>
108+
<goal>npx</goal>
109+
</goals>
110+
<phase>post-integration-test</phase>
111+
<configuration>
112+
<arguments>pm2 delete sidecar</arguments>
113+
<skip>${skipTests}</skip>
114+
<workingDirectory>${sidecar.dir}</workingDirectory>
115+
</configuration>
116+
</execution>
117+
</executions>
118+
</plugin>
119+
</plugins>
120+
</build>
121+
</project>

srv/src/test/java/my/bookshop/FeatureTogglesIT.java renamed to integration-tests/src/test/java/my/bookshop/it/FeatureTogglesIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package my.bookshop;
1+
package my.bookshop.it;
22

33
import static org.hamcrest.CoreMatchers.containsString;
44
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;

mtx/sidecar/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
},
2626
"devDependencies": {
2727
"sqlite3": "^5",
28-
"forever": "^4"
28+
"pm2": "^5.3.0"
2929
},
3030
"engines": {
3131
"node": "^16"
3232
},
3333
"scripts": {
3434
"start": "cds run",
35-
"build": "npm install && npx cds build ../.. --for mtx-sidecar && cd gen && npm install",
36-
"startAsync": "forever start -o out.log -e err.log node_modules/.bin/cds run",
37-
"stopAsync": "forever stopall"
35+
"build": "npm install && npx cds build ../.. --for mtx-sidecar && cd gen && npm install"
3836
}
3937
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
<modules>
2828
<module>srv</module>
29+
<module>integration-tests</module>
2930
</modules>
3031

3132
<dependencyManagement>

srv/pom.xml

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
<name>bookshop</name>
1616

17-
<properties>
18-
<sidecar.dir>../mtx/sidecar</sidecar.dir>
19-
</properties>
20-
2117
<!-- ACTUAL DEPENDENCIES -->
2218
<dependencies>
2319
<!-- CDS DEPENDENCIES -->
@@ -208,64 +204,8 @@
208204
<basePackage>cds.gen</basePackage>
209205
</configuration>
210206
</execution>
211-
212-
<!-- Following steps start and stop MTX sidecar for tests executed by failsafe plugin -->
213-
<execution>
214-
<id>install-sidecar</id>
215-
<goals>
216-
<goal>npm</goal>
217-
</goals>
218-
<phase>pre-integration-test</phase>
219-
<configuration>
220-
<arguments>install</arguments>
221-
<skip>${skipTests}</skip>
222-
<workingDirectory>${sidecar.dir}</workingDirectory>
223-
</configuration>
224-
</execution>
225-
226-
<execution>
227-
<id>start-sidecar</id>
228-
<goals>
229-
<goal>npm</goal>
230-
</goals>
231-
<phase>pre-integration-test</phase>
232-
<configuration>
233-
<arguments>run startAsync</arguments>
234-
<skip>${skipTests}</skip>
235-
<workingDirectory>${sidecar.dir}</workingDirectory>
236-
</configuration>
237-
</execution>
238-
239-
<execution>
240-
<id>stop-sidecar</id>
241-
<goals>
242-
<goal>npm</goal>
243-
</goals>
244-
<phase>post-integration-test</phase>
245-
<configuration>
246-
<arguments>run stopAsync</arguments>
247-
<skip>${skipTests}</skip>
248-
<workingDirectory>${sidecar.dir}</workingDirectory>
249-
</configuration>
250-
</execution>
251207
</executions>
252208
</plugin>
253-
254-
<plugin>
255-
<!-- Tests ending with *IT.java will be executed here -->
256-
<groupId>org.apache.maven.plugins</groupId>
257-
<artifactId>maven-failsafe-plugin</artifactId>
258-
<executions>
259-
<execution>
260-
<id>integration-tests</id>
261-
<phase>integration-test</phase>
262-
<goals>
263-
<goal>integration-test</goal>
264-
</goals>
265-
</execution>
266-
</executions>
267-
</plugin>
268-
269209
</plugins>
270210
</build>
271211

0 commit comments

Comments
 (0)