Skip to content

Commit ab35413

Browse files
Add acceptance tests for Swagger/OpenAPI using Playwright (#457)
* Add acceptance tests for Swagger/OpenAPI using Playwright Added Playwright dependency to `refimpl-tests` and created `SwaggerSpec.groovy` to verify that the Swagger UI is accessible for all services (RM, CM, QM, AM). * test: expand playwright tests Signed-off-by: Andrew Berezovskyi <andriib@kth.se> * test: support basic auth Signed-off-by: Andrew Berezovskyi <andriib@kth.se> * fix: tests with Playwright Signed-off-by: Andrew Berezovskyi <andriib@kth.se> * refactor: rewrite in Java and get rid of Groovy and Spock dependencies Signed-off-by: Andrew Berezovskyi <andriib@kth.se> --------- Signed-off-by: Andrew Berezovskyi <andriib@kth.se> Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Andrew Berezovskyi <andriib@kth.se>
1 parent 01b7f2b commit ab35413

File tree

5 files changed

+288
-168
lines changed

5 files changed

+288
-168
lines changed

src/refimpl-tests/pom.xml

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,16 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1616
<maven.compiler.release>21</maven.compiler.release>
17-
<groovy.version>4.0.28</groovy.version>
1817
</properties>
1918

2019
<build>
2120
<plugins>
22-
<!-- Mandatory plugins for using Spock -->
23-
<plugin>
24-
<!-- The gmavenplus plugin is used to compile Groovy code. To learn more about this plugin,
25-
visit https://github.com/groovy/GMavenPlus/wiki -->
26-
<groupId>org.codehaus.gmavenplus</groupId>
27-
<artifactId>gmavenplus-plugin</artifactId>
28-
<version>4.2.1</version>
29-
<executions>
30-
<execution>
31-
<goals>
32-
<goal>compile</goal>
33-
<goal>compileTests</goal>
34-
</goals>
35-
</execution>
36-
</executions>
37-
</plugin>
38-
<!-- Optional plugins for using Spock -->
39-
<!-- Only required if names of spec classes don't match default Surefire patterns (`*Test` etc.) -->
4021
<plugin>
4122
<artifactId>maven-surefire-plugin</artifactId>
4223
<version>3.5.3</version>
4324
<configuration>
4425
<useModulePath>false</useModulePath> <!-- https://issues.apache.org/jira/browse/SUREFIRE-1809 -->
4526
<useFile>false</useFile>
46-
<includes>
47-
<include>**/*Test</include>
48-
<include>**/*Spec</include>
49-
</includes>
5027
</configuration>
5128
</plugin>
5229
</plugins>
@@ -55,9 +32,9 @@
5532
<dependencyManagement>
5633
<dependencies>
5734
<dependency>
58-
<groupId>org.spockframework</groupId>
59-
<artifactId>spock-bom</artifactId>
60-
<version>2.3-groovy-4.0</version>
35+
<groupId>org.junit</groupId>
36+
<artifactId>junit-bom</artifactId>
37+
<version>5.11.3</version>
6138
<type>pom</type>
6239
<scope>import</scope>
6340
</dependency>
@@ -80,43 +57,21 @@
8057
</dependency>
8158
<dependency>
8259
<groupId>org.testcontainers</groupId>
83-
<artifactId>spock</artifactId>
60+
<artifactId>junit-jupiter</artifactId>
8461
<version>1.21.3</version>
8562
<scope>test</scope>
8663
</dependency>
87-
<!-- Mandatory dependencies for using Spock -->
64+
<!-- Playwright -->
8865
<dependency>
89-
<groupId>org.spockframework</groupId>
90-
<artifactId>spock-core</artifactId>
66+
<groupId>com.microsoft.playwright</groupId>
67+
<artifactId>playwright</artifactId>
68+
<version>1.49.0</version>
9169
<scope>test</scope>
9270
</dependency>
71+
<!-- JUnit 5 -->
9372
<dependency>
94-
<groupId>org.spockframework</groupId>
95-
<artifactId>spock-junit4</artifactId>
96-
<scope>test</scope>
97-
</dependency>
98-
<!-- Optional dependencies for using Spock -->
99-
<dependency> <!-- use a specific Groovy version rather than the one specified by spock-core -->
100-
<groupId>org.apache.groovy</groupId>
101-
<artifactId>groovy</artifactId>
102-
<version>${groovy.version}</version>
103-
</dependency>
104-
<dependency> <!-- enables mocking of classes (in addition to interfaces) -->
105-
<groupId>net.bytebuddy</groupId>
106-
<artifactId>byte-buddy</artifactId>
107-
<version>1.18.2</version>
108-
<scope>test</scope>
109-
</dependency>
110-
<dependency> <!-- enables mocking of classes without default constructor (together with ByteBuddy or CGLIB) -->
111-
<groupId>org.objenesis</groupId>
112-
<artifactId>objenesis</artifactId>
113-
<version>3.4</version>
114-
<scope>test</scope>
115-
</dependency>
116-
<dependency> <!-- only required if Hamcrest matchers are used -->
117-
<groupId>org.hamcrest</groupId>
118-
<artifactId>hamcrest-core</artifactId>
119-
<version>3.0</version>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter</artifactId>
12075
<scope>test</scope>
12176
</dependency>
12277
</dependencies>

src/refimpl-tests/src/test/groovy/OslcSpec.groovy

Lines changed: 0 additions & 112 deletions
This file was deleted.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package co.oslc.refimpl.tests;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.CsvSource;
6+
import org.testcontainers.containers.ComposeContainer;
7+
import org.testcontainers.containers.wait.strategy.Wait;
8+
import org.testcontainers.junit.jupiter.Container;
9+
import org.testcontainers.junit.jupiter.Testcontainers;
10+
11+
import java.io.File;
12+
import java.time.Duration;
13+
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
16+
@Testcontainers
17+
public class OslcTest {
18+
19+
public static final int STARTUP_TIMEOUT = 120;
20+
public static final String RM_SVC = "server-rm";
21+
public static final String CM_SVC = "server-cm";
22+
public static final String QM_SVC = "server-qm";
23+
public static final String AM_SVC = "server-am";
24+
25+
static final int RM_PORT = 8080;
26+
static final int CM_PORT = 8080;
27+
static final int QM_PORT = 8080;
28+
static final int AM_PORT = 8080;
29+
30+
@Container
31+
public static ComposeContainer environment = new ComposeContainer(new File("src/test/resources/docker-compose.yml"))
32+
.withExposedService(RM_SVC, RM_PORT,
33+
Wait.forLogMessage(".*main: Started oejs.Server@.*", 1)
34+
.withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT)))
35+
.withExposedService(CM_SVC, CM_PORT,
36+
Wait.forLogMessage(".*main: Started oejs.Server@.*", 1)
37+
.withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT)))
38+
.withExposedService(QM_SVC, QM_PORT,
39+
Wait.forLogMessage(".*main: Started oejs.Server@.*", 1)
40+
.withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT)))
41+
.withExposedService(AM_SVC, AM_PORT,
42+
Wait.forLogMessage(".*main: Started oejs.Server@.*", 1)
43+
.withStartupTimeout(Duration.ofSeconds(STARTUP_TIMEOUT)))
44+
.withLocalCompose(true);
45+
46+
@ParameterizedTest
47+
@CsvSource({
48+
RM_SVC + ", " + RM_PORT,
49+
CM_SVC + ", " + CM_PORT,
50+
QM_SVC + ", " + QM_PORT,
51+
AM_SVC + ", " + AM_PORT
52+
})
53+
void rootservicesDataTableTest(String svc, int port) {
54+
assertEquals(200, testRootServices(svc, port));
55+
}
56+
57+
@Test
58+
void cmRootservicesTest() {
59+
var svc = CM_SVC;
60+
var port = CM_PORT;
61+
var serviceHost = environment.getServiceHost(svc, port);
62+
var servicePort = environment.getServicePort(svc, port);
63+
System.out.println(serviceHost);
64+
var catalogUrl = "http://%s:%d/services/rootservices".formatted(serviceHost, servicePort);
65+
var getRC = pingUrl(catalogUrl);
66+
assertEquals(200, getRC);
67+
}
68+
69+
private int testRootServices(String svc, int port) {
70+
var serviceHost = environment.getServiceHost(svc, port);
71+
var servicePort = environment.getServicePort(svc, port);
72+
System.out.println(serviceHost);
73+
var catalogUrl = "http://%s:%d/services/rootservices".formatted(serviceHost, servicePort);
74+
return pingUrl(catalogUrl);
75+
}
76+
77+
private int pingUrl(String catalogUrl) {
78+
try (var client = java.net.http.HttpClient.newHttpClient()) {
79+
var request = java.net.http.HttpRequest.newBuilder()
80+
.uri(java.net.URI.create(catalogUrl))
81+
.GET()
82+
.build();
83+
var response = client.send(request, java.net.http.HttpResponse.BodyHandlers.discarding());
84+
var getRC = response.statusCode();
85+
System.out.println("HTTP " + getRC + " for " + catalogUrl);
86+
return getRC;
87+
} catch (Exception e) {
88+
throw new RuntimeException(e);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)