1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.configserver.state;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.vespa.hosted.node.admin.configserver.state.bindings.HealthResponse;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class HealthResponseTest {
@Test
void deserializationOfNormalResponse() throws Exception {
String jsonResponse = "{\n" +
" \"metrics\": {\n" +
" \"snapshot\": {\n" +
" \"from\": 1.523614569023E9,\n" +
" \"to\": 1.523614629023E9\n" +
" },\n" +
" \"values\": [\n" +
" {\n" +
" \"name\": \"requestsPerSecond\",\n" +
" \"values\": {\n" +
" \"count\": 121,\n" +
" \"rate\": 2.0166666666666666\n" +
" }\n" +
" },\n" +
" {\n" +
" \"name\": \"latencySeconds\",\n" +
" \"values\": {\n" +
" \"average\": 5.537190082644628E-4,\n" +
" \"count\": 121,\n" +
" \"last\": 0.001,\n" +
" \"max\": 0.001,\n" +
" \"min\": 0,\n" +
" \"rate\": 2.0166666666666666\n" +
" }\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"status\": {\"code\": \"up\"},\n" +
" \"time\": 1523614629451\n" +
"}";
HealthResponse response = deserialize(jsonResponse);
assertEquals(response.status.code, "up");
}
private static HealthResponse deserialize(String json) throws Exception {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(json, HealthResponse.class);
}
}
|