Skip to content

Commit 95a1144

Browse files
committed
chore: Codecov
Signed-off-by: Javier Aliaga <javier@diagrid.io>
1 parent e7e8a74 commit 95a1144

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

sdk-workflows/src/test/java/io/dapr/workflows/runtime/WorkflowClassWrapperTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import io.dapr.workflows.WorkflowContext;
1919
import io.dapr.workflows.WorkflowStub;
2020
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.function.Executable;
2122

2223
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
2325
import static org.mockito.Mockito.mock;
2426
import static org.mockito.Mockito.times;
2527
import static org.mockito.Mockito.verify;
@@ -33,6 +35,14 @@ public WorkflowStub create() {
3335
}
3436
}
3537

38+
public static abstract class TestErrorWorkflow implements Workflow {
39+
public TestErrorWorkflow(String s){}
40+
@Override
41+
public WorkflowStub create() {
42+
return WorkflowContext::getInstanceId;
43+
}
44+
}
45+
3646
@Test
3747
public void getName() {
3848
WorkflowClassWrapper<TestWorkflow> wrapper = new WorkflowClassWrapper<>(TestWorkflow.class);
@@ -53,4 +63,19 @@ public void createWithClass() {
5363
verify(mockContext, times(1)).getInstanceId();
5464
}
5565

66+
@Test
67+
public void createWithClassAndVersion() {
68+
TaskOrchestrationContext mockContext = mock(TaskOrchestrationContext.class);
69+
WorkflowClassWrapper<TestWorkflow> wrapper = new WorkflowClassWrapper<>(TestWorkflow.class, "TestWorkflowV1",false);
70+
when(mockContext.getInstanceId()).thenReturn("uuid");
71+
wrapper.create().run(mockContext);
72+
verify(mockContext, times(1)).getInstanceId();
73+
}
74+
75+
@Test
76+
public void createErrorClassAndVersion() {
77+
Executable as = () -> new WorkflowClassWrapper<>(TestErrorWorkflow.class, "TestWorkflowV1",false);
78+
assertThrowsExactly(RuntimeException.class, as);
79+
}
80+
5681
}

sdk-workflows/src/test/java/io/dapr/workflows/runtime/WorkflowRuntimeBuilderTest.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,24 @@ public void registerValidWorkflowClass() {
4747
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerWorkflow(TestWorkflow.class));
4848
}
4949

50+
@Test
51+
public void registerValidVersionWorkflowClass() {
52+
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerWorkflow(TestWorkflow.class,"testWorkflowV1", false));
53+
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerWorkflow(TestWorkflow.class,"testWorkflowV2", true));
54+
}
55+
5056
@Test
5157
public void registerValidWorkflowInstance() {
5258
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerWorkflow(new TestWorkflow()));
5359
}
5460

61+
@Test
62+
public void registerValidVersionWorkflowInstance() {
63+
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerWorkflow(new TestWorkflow(),"testWorkflowV1", false));
64+
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerWorkflow(new TestWorkflow(),"testWorkflowV2", true));
65+
}
66+
67+
5568
@Test
5669
public void registerValidWorkflowActivityClass() {
5770
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerActivity(TestActivity.class));
@@ -62,12 +75,15 @@ public void registerValidWorkflowActivityInstance() {
6275
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerActivity(new TestActivity()));
6376
}
6477

78+
79+
6580
@Test
6681
public void buildTest() {
6782
assertDoesNotThrow(() -> {
6883
try {
6984
WorkflowRuntime runtime = new WorkflowRuntimeBuilder().build();
7085
System.out.println("WorkflowRuntime created");
86+
runtime.close();
7187
} catch (Exception e) {
7288
throw new RuntimeException(e);
7389
}
@@ -82,16 +98,18 @@ public void loggingOutputTest() {
8298

8399
Logger testLogger = mock(Logger.class);
84100

85-
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder(testLogger).registerWorkflow(TestWorkflow.class));
86-
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder(testLogger).registerActivity(TestActivity.class));
101+
var runtimeBuilder = new WorkflowRuntimeBuilder(testLogger);
102+
assertDoesNotThrow(() -> runtimeBuilder.registerWorkflow(TestWorkflow.class));
103+
assertDoesNotThrow(() -> runtimeBuilder.registerActivity(TestActivity.class));
87104

88-
WorkflowRuntimeBuilder workflowRuntimeBuilder = new WorkflowRuntimeBuilder();
105+
var runtime = runtimeBuilder.build();
89106

90-
WorkflowRuntime runtime = workflowRuntimeBuilder.build();
91107
verify(testLogger, times(1))
92108
.info(eq("Registered Workflow: {}"), eq("TestWorkflow"));
93109

94110
verify(testLogger, times(1))
95111
.info(eq("Registered Activity: {}"), eq("TestActivity"));
112+
113+
runtime.close();
96114
}
97115
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2026 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.workflows.runtime;
15+
16+
import io.dapr.durabletask.TaskOrchestration;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.junit.jupiter.api.Assertions.*;
20+
21+
class WorkflowVersionWrapperTest {
22+
23+
@Test
24+
void getVersionProperties() {
25+
var versionWrapper = new WorkflowVersionWrapper("A",true) {
26+
@Override
27+
public String getName() {
28+
return "demo";
29+
}
30+
31+
@Override
32+
public TaskOrchestration create() {
33+
return null;
34+
}
35+
};
36+
37+
assertEquals("A",versionWrapper.getVersionName());
38+
assertEquals(true, versionWrapper.isLatestVersion());
39+
}
40+
}

0 commit comments

Comments
 (0)