-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
build-logic/src/main/groovy/io.micronaut.build.internal.openapi-test-java.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
plugins { | ||
id("io.micronaut.build.internal.openapi-base") | ||
id("java-library") | ||
} | ||
|
||
dependencies { | ||
testAnnotationProcessor(mn.micronaut.inject.java) | ||
testImplementation(mnTest.micronaut.test.junit5) | ||
testRuntimeOnly(libs.junit.jupiter.engine) | ||
testRuntimeOnly(mnLogging.logback.classic) | ||
} | ||
tasks.test { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
id("io.micronaut.build.internal.openapi-test-java") | ||
} | ||
|
||
dependencies { | ||
testAnnotationProcessor(mnJaxrs.micronaut.jaxrs.processor) | ||
testImplementation(mnJaxrs.micronaut.jaxrs.server) | ||
testImplementation(mn.micronaut.http.server.netty) | ||
|
||
testImplementation(mn.snakeyaml) | ||
|
||
testImplementation(mn.micronaut.http.client) | ||
|
||
testAnnotationProcessor(mnSerde.micronaut.serde.processor) | ||
testImplementation(mnSerde.micronaut.serde.jackson) | ||
|
||
testAnnotationProcessor(projects.micronautOpenapi) | ||
testCompileOnly(projects.micronautOpenapiAnnotations) | ||
} |
18 changes: 18 additions & 0 deletions
18
test-suite-java-jaxrs/src/test/java/io/micronaut/open/jaxrs/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.micronaut.open.jaxrs; | ||
|
||
import io.micronaut.runtime.Micronaut; | ||
import io.swagger.v3.oas.annotations.*; | ||
import io.swagger.v3.oas.annotations.info.*; | ||
|
||
@OpenAPIDefinition( | ||
info = @Info( | ||
title = "demo", | ||
version = "0.0" | ||
) | ||
) | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
Micronaut.run(Application.class, args); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
test-suite-java-jaxrs/src/test/java/io/micronaut/open/jaxrs/OpenApiExposedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.micronaut.open.jaxrs; | ||
|
||
import io.micronaut.http.client.BlockingHttpClient; | ||
import io.micronaut.http.client.HttpClient; | ||
import io.micronaut.http.client.annotation.Client; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
@MicronautTest | ||
class OpenApiExposedTest { | ||
|
||
@Test | ||
void openApi(@Client("/") HttpClient httpClient) { | ||
BlockingHttpClient client = httpClient.toBlocking(); | ||
assertDoesNotThrow(() -> client.exchange("/swagger/demo-0.0.yml")); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test-suite-java-jaxrs/src/test/java/io/micronaut/open/jaxrs/OpenApiGeneratedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.micronaut.open.jaxrs; | ||
|
||
import io.micronaut.core.io.ResourceLoader; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@MicronautTest(startApplication = false) | ||
class OpenApiGeneratedTest { | ||
|
||
@Test | ||
void buildGeneratesOpenApi(ResourceLoader resourceLoader) { | ||
assertTrue(resourceLoader.getResource("META-INF/swagger/demo-0.0.yml").isPresent()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test-suite-java-jaxrs/src/test/java/io/micronaut/open/jaxrs/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.micronaut.open.jaxrs; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
|
||
@Path("/user") | ||
class TestController { | ||
|
||
@GET | ||
@Path("/{userId}") | ||
@Produces({ "application/json" }) | ||
String getUser(@PathParam("userId") String userId){ | ||
return "Pong version " + userId; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
test-suite-java-jaxrs/src/test/java/io/micronaut/open/jaxrs/TestControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.micronaut.open.jaxrs; | ||
|
||
import io.micronaut.context.BeanContext; | ||
import io.micronaut.http.client.BlockingHttpClient; | ||
import io.micronaut.http.client.HttpClient; | ||
import io.micronaut.http.client.annotation.Client; | ||
import io.micronaut.runtime.server.EmbeddedServer; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@MicronautTest | ||
class TestControllerTest { | ||
|
||
@Test | ||
void jaxrsOpenApiPathTest(@Client("/") HttpClient httpClient) { | ||
BlockingHttpClient client = httpClient.toBlocking(); | ||
String responseYaml = assertDoesNotThrow(() -> client.retrieve("/swagger/demo-0.0.yml", String.class)); | ||
assertNotNull(responseYaml); | ||
Yaml yaml = new Yaml(); | ||
Map<String, Object> obj = yaml.load(responseYaml); | ||
assertNotNull(obj); | ||
assertInstanceOf(Map.class, obj.get("paths")); | ||
Map<String, Object> paths = (Map<String, Object>) obj.get("paths"); | ||
assertTrue(paths.containsKey("/user/{userId}")); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
test-suite-java-jaxrs/src/test/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
micronaut.router.static-resources.swagger.paths=classpath:META-INF/swagger | ||
micronaut.router.static-resources.swagger.mapping=/swagger/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |