|
26 | 26 | import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
27 | 27 | import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
28 | 28 | import co.elastic.clients.elasticsearch.core.SearchRequest;
|
| 29 | +import co.elastic.clients.elasticsearch.ilm.ExplainLifecycleResponse; |
| 30 | +import co.elastic.clients.elasticsearch.ilm.explain_lifecycle.LifecycleExplainManaged; |
| 31 | +import co.elastic.clients.elasticsearch.ilm.explain_lifecycle.LifecycleExplainUnmanaged; |
29 | 32 | import co.elastic.clients.elasticsearch.indices.GetMappingResponse;
|
30 | 33 | import co.elastic.clients.json.JsonData;
|
31 | 34 | import co.elastic.clients.testkit.ModelTestCase;
|
32 | 35 | import org.junit.jupiter.api.Test;
|
33 | 36 |
|
| 37 | +import java.io.StringReader; |
34 | 38 | import java.util.function.Consumer;
|
35 | 39 |
|
36 | 40 | public class VariantsTest extends ModelTestCase {
|
@@ -281,4 +285,28 @@ public void testContainerWithOptionalVariants() {
|
281 | 285 | assertEquals(2.0, fsq2.functionScore().functions().get(0).linear().untyped().placement().decay(), 0.001);
|
282 | 286 | }
|
283 | 287 | }
|
| 288 | + |
| 289 | + @Test |
| 290 | + public void testBooleanVariantTag() { |
| 291 | + |
| 292 | + String jsonT = "{\"indices\":{\"test\":{\"index\":\"test\",\"managed\":true,\"policy\":\"my_policy\",\"index_creation_date_millis\":1736785235558,\"time_since_index_creation\":\"27.75d\",\"lifecycle_date_millis\":1736785235558,\"age\":\"27.75d\",\"phase\":\"warm\",\"phase_time_millis\":1739183166898,\"action\":\"migrate\",\"action_time_millis\":1739183166898,\"step\":\"check-migration\",\"step_time_millis\":1739183166898,\"step_info\":{\"message\":\"Waiting for all shard copies to be active\",\"shards_left_to_allocate\":-1,\"all_shards_active\":false,\"number_of_replicas\":1},\"phase_execution\":{\"policy\":\"my_policy\",\"phase_definition\":{\"min_age\":\"10d\",\"actions\":{\"forcemerge\":{\"max_num_segments\":1}}},\"version\":1,\"modified_date_in_millis\":1739183005443}}}}"; |
| 293 | + |
| 294 | + ExplainLifecycleResponse respT = fromJson(jsonT,ExplainLifecycleResponse.class); |
| 295 | + |
| 296 | + // if managed is "true" then the variant class must be Managed |
| 297 | + assertTrue(respT.indices().get("test").isTrue()); |
| 298 | + assertTrue(respT.indices().get("test")._get().getClass().equals(LifecycleExplainManaged.class)); |
| 299 | + |
| 300 | + String jsonF = "{\"indices\":{\"test\":{\"index\":\"test\",\"managed\":false}}}"; |
| 301 | + |
| 302 | + ExplainLifecycleResponse respF = fromJson(jsonF,ExplainLifecycleResponse.class); |
| 303 | + |
| 304 | + // if managed is "false" then the variant class must be Unmanaged |
| 305 | + assertTrue(respF.indices().get("test").isFalse()); |
| 306 | + assertTrue(respF.indices().get("test")._get().getClass().equals(LifecycleExplainUnmanaged.class)); |
| 307 | + |
| 308 | + // roundtrip isn't the same |
| 309 | + // ExplainLifecycleResponse respT2 = checkJsonRoundtrip(respT, jsonT); |
| 310 | + // ExplainLifecycleResponse respF2 = checkJsonRoundtrip(respF, jsonF); |
| 311 | + } |
284 | 312 | }
|
0 commit comments