|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +package com.microsoft.durabletask.scheduledtasks; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 6 | +import com.fasterxml.jackson.databind.json.JsonMapper; |
| 7 | +import com.microsoft.durabletask.EntityInstanceId; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +import java.time.Duration; |
| 11 | + |
| 12 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 13 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 14 | + |
| 15 | +/** |
| 16 | + * Verifies {@link ScheduleOperationRequest} serializes through the same Jackson configuration the worker uses. |
| 17 | + * <p> |
| 18 | + * Regression guard: the request is the orchestration input for every mutating client operation, so if it has no |
| 19 | + * Jackson-discoverable properties the client fails at {@code scheduleNewOrchestrationInstance} before reaching the |
| 20 | + * backend. This is only exercised end-to-end, so it must be covered here. |
| 21 | + */ |
| 22 | +class ScheduleOperationRequestSerializationTest { |
| 23 | + |
| 24 | + private static final ObjectMapper MAPPER = JsonMapper.builder().findAndAddModules().build(); |
| 25 | + |
| 26 | + @Test |
| 27 | + void serializesWithOptionsPayload() throws Exception { |
| 28 | + ScheduleOperationRequest request = new ScheduleOperationRequest( |
| 29 | + new EntityInstanceId(Schedule.NAME, "s1"), |
| 30 | + ScheduleTransitions.CREATE_SCHEDULE, |
| 31 | + new ScheduleCreationOptions("s1", "orch", Duration.ofSeconds(30)).setOrchestrationInput("world")); |
| 32 | + |
| 33 | + String json = MAPPER.writeValueAsString(request); |
| 34 | + assertNotNull(json); |
| 35 | + |
| 36 | + ScheduleOperationRequest restored = MAPPER.readValue(json, ScheduleOperationRequest.class); |
| 37 | + assertEquals("s1", restored.getEntityId().getKey()); |
| 38 | + assertEquals(ScheduleTransitions.CREATE_SCHEDULE, restored.getOperationName()); |
| 39 | + assertNotNull(restored.getInput()); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void serializesWithNullInput() throws Exception { |
| 44 | + ScheduleOperationRequest request = new ScheduleOperationRequest( |
| 45 | + new EntityInstanceId(Schedule.NAME, "s1"), ScheduleTransitions.PAUSE_SCHEDULE, null); |
| 46 | + |
| 47 | + ScheduleOperationRequest restored = |
| 48 | + MAPPER.readValue(MAPPER.writeValueAsString(request), ScheduleOperationRequest.class); |
| 49 | + assertEquals(ScheduleTransitions.PAUSE_SCHEDULE, restored.getOperationName()); |
| 50 | + } |
| 51 | +} |
0 commit comments