-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
graal: reflect-config.json for hateoas classes (#10547)
- Loading branch information
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
http-server-tck/src/main/java/io/micronaut/http/server/tck/tests/hateoas/JsonErrorTest.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,76 @@ | ||
/* | ||
* Copyright 2017-2023 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.http.server.tck.tests.hateoas; | ||
|
||
import io.micronaut.core.value.OptionalMultiValues; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.client.exceptions.HttpClientResponseException; | ||
import io.micronaut.http.hateoas.*; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.function.Executable; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static io.micronaut.http.tck.TestScenario.asserts; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
@SuppressWarnings({ | ||
"java:S5960", // We're allowed assertions, as these are used in tests only | ||
"checkstyle:MissingJavadocType", | ||
"checkstyle:DesignForExtension" | ||
}) | ||
public class JsonErrorTest { | ||
private static final String SPEC_NAME = "JsonErrorTest"; | ||
|
||
/** | ||
* @throws IOException Exception thrown while getting the server under test. | ||
*/ | ||
@Test | ||
public void responseCanBeBoundToJsonError() throws IOException { | ||
asserts(SPEC_NAME, | ||
HttpRequest.GET("/jsonError"), | ||
(server, request) -> { | ||
Executable e = () -> server.exchange(request, JsonError.class); | ||
HttpClientResponseException ex = Assertions.assertThrows(HttpClientResponseException.class, e); | ||
Optional<JsonError> jsonErrorOptional = ex.getResponse().getBody(JsonError.class); | ||
assertTrue(jsonErrorOptional.isPresent()); | ||
JsonError jsonError = jsonErrorOptional.get(); | ||
assertEquals("Not Found", jsonError.getMessage()); | ||
OptionalMultiValues<Link> links = jsonError.getLinks(); | ||
assertFalse(links.isEmpty()); | ||
links.getFirst("self").ifPresent(link -> { | ||
assertEquals("/jsonError", link.getHref()); | ||
assertFalse(link.isTemplated()); | ||
}); | ||
OptionalMultiValues<Resource> resourceOptionalMultiValues = jsonError.getEmbedded(); | ||
assertFalse(resourceOptionalMultiValues.isEmpty()); | ||
|
||
Optional<List<Resource>> errorsOptional = resourceOptionalMultiValues.get("errors"); | ||
assertTrue(errorsOptional.isPresent()); | ||
List<Resource> resources = errorsOptional.get(); | ||
Optional<GenericResource> genericResourceOptional = resources.stream() | ||
.filter(resource -> resource instanceof GenericResource) | ||
.map(GenericResource.class::cast) | ||
.findFirst(); | ||
assertTrue(genericResourceOptional.isPresent()); | ||
assertEquals("Page Not Found", genericResourceOptional.get().getAdditionalProperties().get("message")); | ||
}); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
http-server-tck/src/main/java/io/micronaut/http/server/tck/tests/hateoas/VndErrorTest.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,79 @@ | ||
/* | ||
* Copyright 2017-2023 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.http.server.tck.tests.hateoas; | ||
|
||
import io.micronaut.core.value.OptionalMultiValues; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.client.exceptions.HttpClientResponseException; | ||
import io.micronaut.http.hateoas.GenericResource; | ||
import io.micronaut.http.hateoas.Link; | ||
import io.micronaut.http.hateoas.Resource; | ||
import io.micronaut.http.hateoas.VndError; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.function.Executable; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static io.micronaut.http.tck.TestScenario.asserts; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
@SuppressWarnings({ | ||
"java:S5960", // We're allowed assertions, as these are used in tests only | ||
"checkstyle:MissingJavadocType", | ||
"checkstyle:DesignForExtension" | ||
}) | ||
public class VndErrorTest { | ||
private static final String SPEC_NAME = "VndErrorTest"; | ||
|
||
/** | ||
* @throws IOException Exception thrown while getting the server under test. | ||
*/ | ||
@Test | ||
public void responseCanBeBoundToVndError() throws IOException { | ||
asserts(SPEC_NAME, | ||
HttpRequest.GET("/vndError"), | ||
(server, request) -> { | ||
Executable e = () -> server.exchange(request, VndError.class); | ||
HttpClientResponseException ex = Assertions.assertThrows(HttpClientResponseException.class, e); | ||
Optional<VndError> vndErrorOptional = ex.getResponse().getBody(VndError.class); | ||
assertTrue(vndErrorOptional.isPresent()); | ||
VndError vndError = vndErrorOptional.get(); | ||
assertEquals("Not Found", vndError.getMessage()); | ||
OptionalMultiValues<Link> links = vndError.getLinks(); | ||
assertFalse(links.isEmpty()); | ||
links.getFirst("self").ifPresent(link -> { | ||
assertEquals("/vndError", link.getHref()); | ||
assertFalse(link.isTemplated()); | ||
}); | ||
OptionalMultiValues<Resource> resourceOptionalMultiValues = vndError.getEmbedded(); | ||
assertFalse(resourceOptionalMultiValues.isEmpty()); | ||
|
||
Optional<List<Resource>> errorsOptional = resourceOptionalMultiValues.get("errors"); | ||
assertTrue(errorsOptional.isPresent()); | ||
List<Resource> resources = errorsOptional.get(); | ||
Optional<GenericResource> genericResourceOptional = resources.stream() | ||
.filter(resource -> resource instanceof GenericResource) | ||
.map(GenericResource.class::cast) | ||
.findFirst(); | ||
assertTrue(genericResourceOptional.isPresent()); | ||
assertEquals("Page Not Found", genericResourceOptional.get().getAdditionalProperties().get("message")); | ||
}); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
http/src/main/resources/META-INF/native-image/io.micronaut.http.hateoas/reflect-config.json
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,35 @@ | ||
[ | ||
{ | ||
"name": "io.micronaut.http.hateoas.GenericResource", | ||
"queryAllDeclaredMethods": true, | ||
"allDeclaredFields": true, | ||
"queryAllDeclaredConstructors": true, | ||
"methods": [ | ||
{ | ||
"name": "addProperty", | ||
"parameterTypes": [ | ||
"java.lang.String", | ||
"java.lang.Object" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "io.micronaut.http.hateoas.Resource", | ||
"queryAllDeclaredMethods": true, | ||
"methods": [ | ||
{ | ||
"name": "deserialize", | ||
"parameterTypes": [ | ||
"io.micronaut.http.hateoas.GenericResource" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "io.micronaut.http.hateoas.JsonError", | ||
"queryAllDeclaredMethods": true, | ||
"allDeclaredFields": true, | ||
"queryAllDeclaredConstructors": true | ||
} | ||
] |