diff --git a/CHANGELOG.md b/CHANGELOG.md index f3551d3e..c3c9b43f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Unreleased +* Add getSuspendPostUri and getResumePostUri getters to HttpManagementPayload ([#264](https://github.com/microsoft/durabletask-java/pull/264)) * Adding rewind client API ([#253](https://github.com/microsoft/durabletask-java/pull/253)). Note: orchestration processing for rewind is supported with Azure Functions but not with the standalone `GrpcDurableTaskWorker`. * Add distributed tracing (OpenTelemetry) support with W3C Trace Context propagation ([#266](https://github.com/microsoft/durabletask-java/pull/266)) diff --git a/azurefunctions/build.gradle b/azurefunctions/build.gradle index fc5f86fd..0cfd9959 100644 --- a/azurefunctions/build.gradle +++ b/azurefunctions/build.gradle @@ -22,6 +22,13 @@ dependencies { implementation group: 'com.microsoft.azure.functions', name: 'azure-functions-java-library', version: '3.2.3' implementation "com.google.protobuf:protobuf-java:${protocVersion}" compileOnly "com.microsoft.azure.functions:azure-functions-java-spi:1.1.0" + testImplementation platform('org.junit:junit-bom:5.14.2') + testImplementation 'org.junit.jupiter:junit-jupiter' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +test { + useJUnitPlatform() } sourceCompatibility = JavaVersion.VERSION_1_8 diff --git a/azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/HttpManagementPayload.java b/azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/HttpManagementPayload.java index dace60b7..43e16ac9 100644 --- a/azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/HttpManagementPayload.java +++ b/azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/HttpManagementPayload.java @@ -93,7 +93,25 @@ public String getPurgeHistoryDeleteUri() { * @return The HTTP URL for posting instance restart commands. */ public String getRestartPostUri() { - return restartPostUri; + return this.restartPostUri; + } + + /** + * Gets the HTTP POST instance suspend endpoint. + * + * @return The HTTP URL for posting instance suspend commands. + */ + public String getSuspendPostUri() { + return this.suspendPostUri; + } + + /** + * Gets the HTTP POST instance resume endpoint. + * + * @return The HTTP URL for posting instance resume commands. + */ + public String getResumePostUri() { + return this.resumePostUri; } /** @@ -102,7 +120,7 @@ public String getRestartPostUri() { * @return The HTTP URL for posting instance rewind commands. */ public String getRewindPostUri() { - return rewindPostUri; + return this.rewindPostUri; } } diff --git a/azurefunctions/src/test/java/com/microsoft/durabletask/azurefunctions/HttpManagementPayloadTest.java b/azurefunctions/src/test/java/com/microsoft/durabletask/azurefunctions/HttpManagementPayloadTest.java new file mode 100644 index 00000000..2798164b --- /dev/null +++ b/azurefunctions/src/test/java/com/microsoft/durabletask/azurefunctions/HttpManagementPayloadTest.java @@ -0,0 +1,83 @@ +package com.microsoft.durabletask.azurefunctions; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Unit tests for {@link HttpManagementPayload}. + */ +public class HttpManagementPayloadTest { + + private static final String INSTANCE_ID = "test-instance-id"; + private static final String INSTANCE_STATUS_URL = "http://localhost:7071/runtime/webhooks/durabletask/instances/test-instance-id"; + private static final String QUERY_STRING = "code=abc123"; + + private HttpManagementPayload createPayload() { + return new HttpManagementPayload(INSTANCE_ID, INSTANCE_STATUS_URL, QUERY_STRING); + } + + @Test + @DisplayName("getId should return the instance ID") + public void getId_ReturnsInstanceId() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_ID, payload.getId()); + } + + @Test + @DisplayName("getStatusQueryGetUri should return correct URL") + public void getStatusQueryGetUri_ReturnsCorrectUrl() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_STATUS_URL + "?" + QUERY_STRING, payload.getStatusQueryGetUri()); + } + + @Test + @DisplayName("getSendEventPostUri should return correct URL") + public void getSendEventPostUri_ReturnsCorrectUrl() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_STATUS_URL + "/raiseEvent/{eventName}?" + QUERY_STRING, payload.getSendEventPostUri()); + } + + @Test + @DisplayName("getTerminatePostUri should return correct URL") + public void getTerminatePostUri_ReturnsCorrectUrl() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_STATUS_URL + "/terminate?reason={text}&" + QUERY_STRING, payload.getTerminatePostUri()); + } + + @Test + @DisplayName("getPurgeHistoryDeleteUri should return correct URL") + public void getPurgeHistoryDeleteUri_ReturnsCorrectUrl() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_STATUS_URL + "?" + QUERY_STRING, payload.getPurgeHistoryDeleteUri()); + } + + @Test + @DisplayName("getRestartPostUri should return correct URL") + public void getRestartPostUri_ReturnsCorrectUrl() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_STATUS_URL + "/restart?" + QUERY_STRING, payload.getRestartPostUri()); + } + + @Test + @DisplayName("getSuspendPostUri should return correct URL") + public void getSuspendPostUri_ReturnsCorrectUrl() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_STATUS_URL + "/suspend?reason={text}&" + QUERY_STRING, payload.getSuspendPostUri()); + } + + @Test + @DisplayName("getResumePostUri should return correct URL") + public void getResumePostUri_ReturnsCorrectUrl() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_STATUS_URL + "/resume?reason={text}&" + QUERY_STRING, payload.getResumePostUri()); + } + + @Test + @DisplayName("getRewindPostUri should return correct URL") + public void getRewindPostUri_ReturnsCorrectUrl() { + HttpManagementPayload payload = createPayload(); + assertEquals(INSTANCE_STATUS_URL + "/rewind?reason={text}&" + QUERY_STRING, payload.getRewindPostUri()); + } +}