Skip to content

Commit 0844f67

Browse files
sdelamotimyates
andauthored
tck: HealthResult serialization (#10624)
* tck: HealthResult serialization This pull request adds the HealthResult serialization test introduced in #10526 as a TCK test. * Unused imports and whitespace * Try to fix the build... Switching base seems to have broken things --------- Co-authored-by: Tim Yates <[email protected]>
1 parent e11a18e commit 0844f67

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2017-2024 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micronaut.http.server.tck.tests.endpoints.health;
17+
18+
import io.micronaut.context.annotation.Requires;
19+
import io.micronaut.health.HealthStatus;
20+
import io.micronaut.http.HttpRequest;
21+
import io.micronaut.http.HttpStatus;
22+
import io.micronaut.http.annotation.Controller;
23+
import io.micronaut.http.annotation.Get;
24+
import io.micronaut.http.tck.AssertionUtils;
25+
import io.micronaut.http.tck.HttpResponseAssertion;
26+
import io.micronaut.json.JsonMapper;
27+
import io.micronaut.management.health.indicator.HealthResult;
28+
import org.junit.jupiter.api.Test;
29+
30+
import java.io.IOException;
31+
import java.util.Collections;
32+
33+
import static io.micronaut.http.tck.TestScenario.asserts;
34+
35+
@SuppressWarnings({
36+
"java:S5960", // We're allowed assertions, as these are used in tests only
37+
"checkstyle:MissingJavadocType",
38+
"checkstyle:DesignForExtension"
39+
})
40+
public class HealthResultTest {
41+
42+
private static final String SPEC_NAME = "HealthResultTest";
43+
44+
/**
45+
* This test verifies the available JSON Mapper is able to serialize a {@link HealthResult}.
46+
*
47+
* @throws IOException Exception thrown while getting the server under test.
48+
*/
49+
@Test
50+
public void healthResultSerialization() throws IOException {
51+
// standard header name with mixed case
52+
asserts(SPEC_NAME,
53+
HttpRequest.GET("/healthresult"),
54+
(server, request) -> AssertionUtils.assertDoesNotThrow(server, request, HttpResponseAssertion.builder()
55+
.status(HttpStatus.OK)
56+
.body("{\"name\":\"db\",\"status\":\"DOWN\",\"details\":{\"foo\":\"bar\"}}")
57+
.build()));
58+
}
59+
60+
@Controller("/healthresult")
61+
@Requires(property = "spec.name", value = SPEC_NAME)
62+
public static class QuestionController {
63+
private final JsonMapper jsonMapper;
64+
65+
public QuestionController(JsonMapper jsonMapper) {
66+
this.jsonMapper = jsonMapper;
67+
}
68+
69+
@Get
70+
String index() throws IOException {
71+
return jsonMapper.writeValueAsString(HealthResult.builder("db", HealthStatus.DOWN)
72+
.details(Collections.singletonMap("foo", "bar"))
73+
.build());
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)