Skip to content

Commit a36f8b5

Browse files
authored
Implement Tests to check basic Java Record processing result (#4749)
Implement series of tests in separate module for Java Record support
1 parent 6c14ceb commit a36f8b5

17 files changed

+1079
-1
lines changed

CI/post-release.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ sc_find="io.swagger.core.v3:swagger-jaxrs2:$SC_VERSION"
4444
sc_replace="io.swagger.core.v3:swagger-jaxrs2:$SC_NEXT_VERSION-SNAPSHOT"
4545
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/SwaggerResolveTest.java
4646

47+
sc_find="<version>$SC_VERSION<\/version>"
48+
sc_replace="<version>$SC_NEXT_VERSION-SNAPSHOT<\/version>"
49+
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swagger-java17-support/pom.xml
4750

4851
#####################
4952
### Copy scripts to temp folder, as they are not available when checking out different branch or repo

CI/prepare-release.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ sc_find="<version>$SC_LAST_RELEASE<\/version>"
7373
sc_replace="<version>$SC_VERSION<\/version>"
7474
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swagger-maven-plugin/README.md
7575

76+
sc_find="<version>$SC_LAST_RELEASE<\/version>"
77+
sc_replace="<version>$SC_VERSION<\/version>"
78+
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swaggerjava17-support/pom.xml
79+
7680
#####################
7781
### build and test maven ###
7882
#####################
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>io.swagger.core.v3</groupId>
7+
<artifactId>swagger-project</artifactId>
8+
<version>2.2.26-SNAPSHOT</version>
9+
<relativePath>../../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>swagger-java17-support</artifactId>
12+
<packaging>jar</packaging>
13+
<name>swagger-java17-support</name>
14+
<description>Module for Java 17 specific tests</description>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.testng</groupId>
18+
<artifactId>testng</artifactId>
19+
<scope>test</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>io.swagger.core.v3</groupId>
23+
<artifactId>swagger-jaxrs2</artifactId>
24+
<version>${project.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>io.swagger.core.v3</groupId>
28+
<artifactId>swagger-core</artifactId>
29+
<version>${project.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.swagger.core.v3</groupId>
33+
<artifactId>swagger-annotations</artifactId>
34+
<version>${project.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.swagger.core.v3</groupId>
38+
<artifactId>swagger-models</artifactId>
39+
<version>${project.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.glassfish.jersey.media</groupId>
43+
<artifactId>jersey-media-multipart</artifactId>
44+
<version>${jersey2-version}</version>
45+
<scope>test</scope>
46+
<exclusions>
47+
<exclusion>
48+
<groupId>javax.annotation</groupId>
49+
<artifactId>javax.annotation-api</artifactId>
50+
</exclusion>
51+
<exclusion>
52+
<groupId>org.javassist</groupId>
53+
<artifactId>javassist</artifactId>
54+
</exclusion>
55+
</exclusions>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.glassfish.jersey.inject</groupId>
59+
<artifactId>jersey-hk2</artifactId>
60+
<version>${jersey2-version}</version>
61+
<scope>test</scope>
62+
<exclusions>
63+
<exclusion>
64+
<groupId>javax.annotation</groupId>
65+
<artifactId>javax.annotation-api</artifactId>
66+
</exclusion>
67+
<exclusion>
68+
<groupId>org.javassist</groupId>
69+
<artifactId>javassist</artifactId>
70+
</exclusion>
71+
</exclusions>
72+
</dependency>
73+
</dependencies>
74+
75+
<build>
76+
<plugins>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>3.11.0</version>
81+
<configuration>
82+
<release>17</release>
83+
</configuration>
84+
</plugin>
85+
</plugins>
86+
</build>
87+
<properties>
88+
<maven.compiler.release>17</maven.compiler.release>
89+
</properties>
90+
91+
</project>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package io.swagger.v3.java17.Reader;
2+
3+
import io.swagger.v3.java17.matchers.SerializationMatchers;
4+
import io.swagger.v3.java17.resources.JavaRecordWithPathResource;
5+
import io.swagger.v3.java17.resources.OtherJavaRecordWithPathsResource;
6+
import io.swagger.v3.java17.resources.TestControllerWithRecordResource;
7+
import io.swagger.v3.jaxrs2.Reader;
8+
import io.swagger.v3.oas.integration.SwaggerConfiguration;
9+
import io.swagger.v3.oas.models.OpenAPI;
10+
import org.testng.annotations.Test;
11+
12+
import java.util.HashSet;
13+
import java.util.Set;
14+
15+
public class ReaderTest {
16+
17+
@Test
18+
public void TestJavaRecordRef(){
19+
Reader reader = new Reader(new SwaggerConfiguration().openAPI(new OpenAPI()).openAPI31(true));
20+
21+
OpenAPI openAPI = reader.read(TestControllerWithRecordResource.class);
22+
String yaml = "openapi: 3.1.0\n" +
23+
"paths:\n" +
24+
" /v17:\n" +
25+
" post:\n" +
26+
" operationId: opsRecordID\n" +
27+
" responses:\n" +
28+
" default:\n" +
29+
" description: Successful operation\n" +
30+
" content:\n" +
31+
" application/json:\n" +
32+
" schema:\n" +
33+
" $ref: '#/components/schemas/JavaRecordResource'\n" +
34+
"components:\n" +
35+
" schemas:\n" +
36+
" JavaRecordResource:\n" +
37+
" type: object\n" +
38+
" properties:\n" +
39+
" test:\n" +
40+
" type: string\n" +
41+
" description: Testing of Java Record Processing\n" +
42+
" isLatest:\n" +
43+
" type: boolean\n" +
44+
" id:\n" +
45+
" type: string\n" +
46+
" age:\n" +
47+
" type: integer\n" +
48+
" format: int32";
49+
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
50+
}
51+
52+
@Test
53+
public void TestSetOfRecords(){
54+
Set<Class<?>> classes = new HashSet<>();
55+
classes.add(JavaRecordWithPathResource.class);
56+
classes.add(OtherJavaRecordWithPathsResource.class);
57+
58+
Reader reader = new Reader(new OpenAPI());
59+
OpenAPI openAPI = reader.read(classes);
60+
String yaml = "openapi: 3.0.1\n" +
61+
"paths:\n" +
62+
" /sample/1:\n" +
63+
" post:\n" +
64+
" description: description 1\n" +
65+
" operationId: id 1\n" +
66+
" responses:\n" +
67+
" default:\n" +
68+
" description: default response\n" +
69+
" content:\n" +
70+
" '*/*': {}\n" +
71+
" /sample/2:\n" +
72+
" post:\n" +
73+
" description: description 2\n" +
74+
" operationId: id 2\n" +
75+
" responses:\n" +
76+
" default:\n" +
77+
" description: default response\n" +
78+
" content:\n" +
79+
" '*/*': {}\n" +
80+
" /sample2:\n" +
81+
" get:\n" +
82+
" description: description\n" +
83+
" operationId: Operation Id\n" +
84+
" responses:\n" +
85+
" default:\n" +
86+
" description: default response\n" +
87+
" content:\n" +
88+
" '*/*': {}\n" +
89+
" security:\n" +
90+
" - security_key:\n" +
91+
" - write:pets\n" +
92+
" - read:pets\n" +
93+
" /sample2/2:\n" +
94+
" get:\n" +
95+
" description: description 2\n" +
96+
" operationId: Operation Id 2\n" +
97+
" responses:\n" +
98+
" default:\n" +
99+
" description: default response\n" +
100+
" content:\n" +
101+
" '*/*': {}\n" +
102+
" security:\n" +
103+
" - security_key2:\n" +
104+
" - write:pets\n" +
105+
" - read:pets";
106+
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
107+
}
108+
}

0 commit comments

Comments
 (0)