|
13 | 13 |
|
14 | 14 | package io.dapr.workflows; |
15 | 15 |
|
| 16 | +import com.microsoft.durabletask.CompositeTaskFailedException; |
16 | 17 | import com.microsoft.durabletask.RetryPolicy; |
17 | 18 | import com.microsoft.durabletask.Task; |
| 19 | +import com.microsoft.durabletask.TaskCanceledException; |
18 | 20 | import com.microsoft.durabletask.TaskOptions; |
19 | 21 | import com.microsoft.durabletask.TaskOrchestrationContext; |
20 | 22 |
|
| 23 | +import org.jetbrains.annotations.Nullable; |
21 | 24 | import org.junit.jupiter.api.BeforeEach; |
22 | 25 | import org.junit.jupiter.api.Test; |
23 | 26 | import org.slf4j.Logger; |
24 | 27 |
|
25 | 28 | import java.time.Duration; |
| 29 | +import java.time.Instant; |
26 | 30 | import java.time.ZonedDateTime; |
27 | 31 | import java.util.Arrays; |
28 | 32 | import java.util.List; |
29 | 33 |
|
| 34 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
30 | 35 | import static org.mockito.ArgumentMatchers.any; |
31 | 36 | import static org.mockito.Mockito.mock; |
32 | 37 | import static org.mockito.Mockito.times; |
|
37 | 42 | public class DaprWorkflowContextImplTest { |
38 | 43 | private DaprWorkflowContextImpl context; |
39 | 44 | private TaskOrchestrationContext mockInnerContext; |
| 45 | + private WorkflowContext testWorkflowContext; |
40 | 46 |
|
41 | 47 | @BeforeEach |
42 | 48 | public void setUp() { |
43 | 49 | mockInnerContext = mock(TaskOrchestrationContext.class); |
44 | 50 | context = new DaprWorkflowContextImpl(mockInnerContext); |
| 51 | + testWorkflowContext = new WorkflowContext() { |
| 52 | + @Override |
| 53 | + public Logger getLogger() { |
| 54 | + return null; |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public String getName() { |
| 59 | + return null; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public String getInstanceId() { |
| 64 | + return null; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public Instant getCurrentInstant() { |
| 69 | + return null; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public void complete(Object output) { |
| 74 | + |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public <V> Task<V> waitForExternalEvent(String name, Duration timeout, Class<V> dataType) |
| 79 | + throws TaskCanceledException { |
| 80 | + return null; |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public <V> Task<Void> waitForExternalEvent(String name, Duration timeout) throws TaskCanceledException { |
| 85 | + return null; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public <V> Task<Void> waitForExternalEvent(String name) throws TaskCanceledException { |
| 90 | + return null; |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public <V> Task<V> callActivity(String name, Object input, TaskOptions options, Class<V> returnType) { |
| 95 | + return null; |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public boolean isReplaying() { |
| 100 | + return false; |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public <V> Task<List<V>> allOf(List<Task<V>> tasks) throws CompositeTaskFailedException { |
| 105 | + return null; |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public Task<Task<?>> anyOf(List<Task<?>> tasks) { |
| 110 | + return null; |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public Task<Void> createTimer(Duration duration) { |
| 115 | + return null; |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public <V> V getInput(Class<V> targetType) { |
| 120 | + return null; |
| 121 | + } |
| 122 | + |
| 123 | + @Override |
| 124 | + public <V> Task<V> callSubWorkflow(String name, @Nullable Object input, @Nullable String instanceID, |
| 125 | + @Nullable TaskOptions options, Class<V> returnType) { |
| 126 | + return null; |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public void continueAsNew(Object input, boolean preserveUnprocessedEvents) { |
| 131 | + |
| 132 | + } |
| 133 | + }; |
45 | 134 | } |
46 | 135 |
|
47 | 136 | @Test |
@@ -207,4 +296,17 @@ public void callSubWorkflow() { |
207 | 296 | context.callSubWorkflow(expectedName, expectedInput, String.class); |
208 | 297 | verify(mockInnerContext, times(1)).callSubOrchestrator(expectedName, expectedInput, null, null, String.class); |
209 | 298 | } |
| 299 | + |
| 300 | + @Test |
| 301 | + public void newUuidTest() { |
| 302 | + context.newUuid(); |
| 303 | + verify(mockInnerContext, times(1)).newUUID(); |
| 304 | + } |
| 305 | + |
| 306 | + @Test |
| 307 | + public void newUuidTestNoImplementationExceptionTest() { |
| 308 | + RuntimeException runtimeException = assertThrows(RuntimeException.class, testWorkflowContext::newUuid); |
| 309 | + String expectedMessage = "No implementation found."; |
| 310 | + assertEquals(expectedMessage, runtimeException.getMessage()); |
| 311 | + } |
210 | 312 | } |
0 commit comments