|
23 | 23 | import org.junit.jupiter.api.Test; |
24 | 24 |
|
25 | 25 | import org.springframework.boot.test.json.BasicJsonTester; |
| 26 | +import org.springframework.cloud.client.ServiceInstance; |
26 | 27 |
|
27 | 28 | import static org.assertj.core.api.Assertions.assertThat; |
28 | 29 |
|
@@ -84,6 +85,44 @@ void defaultKubernetesServiceInstanceSerializationTest() throws JsonProcessingEx |
84 | 85 | .isEqualTo("https://host:8080"); |
85 | 86 | } |
86 | 87 |
|
| 88 | + @Test |
| 89 | + void defaultKubernetesServiceInstanceDeserializationTest() throws JsonProcessingException { |
| 90 | + |
| 91 | + String serialized = """ |
| 92 | + { |
| 93 | + "instanceId": "instanceId", |
| 94 | + "serviceId": "serviceId", |
| 95 | + "host": "host", |
| 96 | + "port": 8080, |
| 97 | + "metadata": { |
| 98 | + "k8s_namespace": "spring-k8s" |
| 99 | + }, |
| 100 | + "secure": true, |
| 101 | + "namespace": "namespace", |
| 102 | + "cluster": "cluster", |
| 103 | + "podMetadata": { |
| 104 | + "pod_root": { |
| 105 | + "pod_key": "pod_value" |
| 106 | + } |
| 107 | + }, |
| 108 | + "scheme": "https", |
| 109 | + "uri": "https://host:8080" |
| 110 | + } |
| 111 | + """; |
| 112 | + |
| 113 | + ServiceInstance deserialized = |
| 114 | + new ObjectMapper().readValue(serialized, DefaultKubernetesServiceInstance.class); |
| 115 | + assertThat(deserialized.getInstanceId()).isEqualTo("instanceId"); |
| 116 | + assertThat(deserialized.getServiceId()).isEqualTo("serviceId"); |
| 117 | + assertThat(deserialized.getScheme()).isEqualTo("https"); |
| 118 | + assertThat(deserialized.getHost()).isEqualTo("host"); |
| 119 | + assertThat(deserialized.getPort()).isEqualTo(8080); |
| 120 | + assertThat(deserialized.getUri().toASCIIString()).isEqualTo("https://host:8080"); |
| 121 | + assertThat(deserialized.getMetadata()).containsExactlyInAnyOrderEntriesOf( |
| 122 | + Map.of("k8s_namespace", "spring-k8s") |
| 123 | + ); |
| 124 | + } |
| 125 | + |
87 | 126 | @Test |
88 | 127 | void externalNameServiceInstanceSerializationTest() throws JsonProcessingException { |
89 | 128 | KubernetesExternalNameServiceInstance instance = new KubernetesExternalNameServiceInstance("serviceId", "host", |
|
0 commit comments