Skip to content

Commit

Permalink
Implement Tests to check basic Java Record processing result (#4749)
Browse files Browse the repository at this point in the history
Implement series of tests in separate module for Java Record support
  • Loading branch information
micryc authored Oct 7, 2024
1 parent 6c14ceb commit a36f8b5
Show file tree
Hide file tree
Showing 17 changed files with 1,079 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CI/post-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ sc_find="io.swagger.core.v3:swagger-jaxrs2:$SC_VERSION"
sc_replace="io.swagger.core.v3:swagger-jaxrs2:$SC_NEXT_VERSION-SNAPSHOT"
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/SwaggerResolveTest.java

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

#####################
### Copy scripts to temp folder, as they are not available when checking out different branch or repo
Expand Down
4 changes: 4 additions & 0 deletions CI/prepare-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ sc_find="<version>$SC_LAST_RELEASE<\/version>"
sc_replace="<version>$SC_VERSION<\/version>"
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swagger-maven-plugin/README.md

sc_find="<version>$SC_LAST_RELEASE<\/version>"
sc_replace="<version>$SC_VERSION<\/version>"
sed -i -e "s/$sc_find/$sc_replace/g" $CUR/modules/swaggerjava17-support/pom.xml

#####################
### build and test maven ###
#####################
Expand Down
91 changes: 91 additions & 0 deletions modules/swagger-java17-support/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-project</artifactId>
<version>2.2.26-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>swagger-java17-support</artifactId>
<packaging>jar</packaging>
<name>swagger-java17-support</name>
<description>Module for Java 17 specific tests</description>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-models</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey2-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey2-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package io.swagger.v3.java17.Reader;

import io.swagger.v3.java17.matchers.SerializationMatchers;
import io.swagger.v3.java17.resources.JavaRecordWithPathResource;
import io.swagger.v3.java17.resources.OtherJavaRecordWithPathsResource;
import io.swagger.v3.java17.resources.TestControllerWithRecordResource;
import io.swagger.v3.jaxrs2.Reader;
import io.swagger.v3.oas.integration.SwaggerConfiguration;
import io.swagger.v3.oas.models.OpenAPI;
import org.testng.annotations.Test;

import java.util.HashSet;
import java.util.Set;

public class ReaderTest {

@Test
public void TestJavaRecordRef(){
Reader reader = new Reader(new SwaggerConfiguration().openAPI(new OpenAPI()).openAPI31(true));

OpenAPI openAPI = reader.read(TestControllerWithRecordResource.class);
String yaml = "openapi: 3.1.0\n" +
"paths:\n" +
" /v17:\n" +
" post:\n" +
" operationId: opsRecordID\n" +
" responses:\n" +
" default:\n" +
" description: Successful operation\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/JavaRecordResource'\n" +
"components:\n" +
" schemas:\n" +
" JavaRecordResource:\n" +
" type: object\n" +
" properties:\n" +
" test:\n" +
" type: string\n" +
" description: Testing of Java Record Processing\n" +
" isLatest:\n" +
" type: boolean\n" +
" id:\n" +
" type: string\n" +
" age:\n" +
" type: integer\n" +
" format: int32";
SerializationMatchers.assertEqualsToYaml31(openAPI, yaml);
}

@Test
public void TestSetOfRecords(){
Set<Class<?>> classes = new HashSet<>();
classes.add(JavaRecordWithPathResource.class);
classes.add(OtherJavaRecordWithPathsResource.class);

Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(classes);
String yaml = "openapi: 3.0.1\n" +
"paths:\n" +
" /sample/1:\n" +
" post:\n" +
" description: description 1\n" +
" operationId: id 1\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" /sample/2:\n" +
" post:\n" +
" description: description 2\n" +
" operationId: id 2\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" /sample2:\n" +
" get:\n" +
" description: description\n" +
" operationId: Operation Id\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" security:\n" +
" - security_key:\n" +
" - write:pets\n" +
" - read:pets\n" +
" /sample2/2:\n" +
" get:\n" +
" description: description 2\n" +
" operationId: Operation Id 2\n" +
" responses:\n" +
" default:\n" +
" description: default response\n" +
" content:\n" +
" '*/*': {}\n" +
" security:\n" +
" - security_key2:\n" +
" - write:pets\n" +
" - read:pets";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
}
Loading

0 comments on commit a36f8b5

Please sign in to comment.