Skip to content

Commit 8445f65

Browse files
Fix assignment check for getDataObject with tests (#125)
1 parent fc7a7c1 commit 8445f65

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ See [samples](https://github.com/indeedeng/iwf-java-samples) for how to use this
99
## Gradle
1010
```gradle
1111
// https://mvnrepository.com/artifact/io.iworkflow/iwf-java-sdk
12-
implementation 'io.iworkflow:iwf-java-sdk:1.2.4'
12+
implementation 'io.iworkflow:iwf-java-sdk:1.2.5'
1313
```
1414
## Maven
1515
```
1616
<!-- https://mvnrepository.com/artifact/io.iworkflow/iwf-java-sdk -->
1717
<dependency>
1818
<groupId>io.iworkflow</groupId>
1919
<artifactId>iwf-java-sdk</artifactId>
20-
<version>1.2.4</version>
20+
<version>1.2.5</version>
2121
<type>pom</type>
2222
</dependency>
2323

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ signing {
150150
}
151151

152152
group = "io.iworkflow"
153-
version = "1.2.4"
153+
version = "1.2.5"
154154

155155
nexusPublishing {
156156
repositories {

src/main/java/io/iworkflow/core/persistence/DataObjectsRWImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public <T> T getDataObject(String key, Class<T> type) {
3535
}
3636

3737
Class<?> registeredType = keyToTypeMap.get(key);
38-
if (!registeredType.isAssignableFrom(type)) {
38+
if (!type.isAssignableFrom(registeredType)) {
3939
throw new IllegalArgumentException(
4040
String.format(
4141
"registered type %s is not assignable from %s",

src/test/java/io/iworkflow/integ/PersistenceTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ public void testPersistenceWorkflow() throws InterruptedException {
3535
client.getWorkflowDataObjects(BasicPersistenceWorkflow.class, wfId, runId, Arrays.asList(BasicPersistenceWorkflow.TEST_DATA_OBJECT_KEY));
3636
Assertions.assertEquals(
3737
"query-start-query-decide", map.get(BasicPersistenceWorkflow.TEST_DATA_OBJECT_KEY));
38-
Map<String, Object> allQueryAttributes =
39-
client.getAllDataObjects(BasicPersistenceWorkflow.class, wfId, runId);
40-
Assertions.assertEquals(
41-
"query-start-query-decide", allQueryAttributes.get(BasicPersistenceWorkflow.TEST_DATA_OBJECT_KEY));
42-
Assertions.assertEquals(
43-
1, allQueryAttributes.size());
38+
Map<String, Object> allDataObjects = client.getAllDataObjects(BasicPersistenceWorkflow.class, wfId, runId);
39+
Assertions.assertEquals(3, allDataObjects.size());
40+
41+
Assertions.assertEquals("query-start-query-decide", allDataObjects.get(BasicPersistenceWorkflow.TEST_DATA_OBJECT_KEY));
42+
4443
Assertions.assertEquals("test-value-2", output);
4544

4645
final Map<String, Object> searchAttributes1 = client.getWorkflowSearchAttributes(BasicPersistenceWorkflow.class,

src/test/java/io/iworkflow/integ/persistence/BasicPersistenceWorkflow.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import io.iworkflow.core.persistence.DataObjectDef;
66
import io.iworkflow.core.persistence.PersistenceFieldDef;
77
import io.iworkflow.core.persistence.SearchAttributeDef;
8+
import io.iworkflow.gen.models.Context;
89
import io.iworkflow.gen.models.SearchAttributeValueType;
10+
import io.iworkflow.integ.basic.FakContextImpl;
911
import org.springframework.stereotype.Component;
1012

1113
import java.util.Arrays;
@@ -14,6 +16,9 @@
1416
@Component
1517
public class BasicPersistenceWorkflow implements Workflow {
1618
public static final String TEST_DATA_OBJECT_KEY = "data-obj-1";
19+
public static final String TEST_DATA_OBJECT_MODEL_1 = "data-obj-2";
20+
21+
public static final String TEST_DATA_OBJECT_MODEL_2 = "data-obj-3";
1722

1823
public static final String TEST_SEARCH_ATTRIBUTE_KEYWORD = "CustomKeywordField";
1924
public static final String TEST_SEARCH_ATTRIBUTE_INT = "CustomIntField";
@@ -27,6 +32,8 @@ public List<StateDef> getStates() {
2732
public List<PersistenceFieldDef> getPersistenceSchema() {
2833
return Arrays.asList(
2934
DataObjectDef.create(String.class, TEST_DATA_OBJECT_KEY),
35+
DataObjectDef.create(Context.class, TEST_DATA_OBJECT_MODEL_1),
36+
DataObjectDef.create(FakContextImpl.class, TEST_DATA_OBJECT_MODEL_2),
3037
SearchAttributeDef.create(SearchAttributeValueType.INT, TEST_SEARCH_ATTRIBUTE_INT),
3138
SearchAttributeDef.create(SearchAttributeValueType.KEYWORD, TEST_SEARCH_ATTRIBUTE_KEYWORD)
3239
);

src/test/java/io/iworkflow/integ/persistence/BasicPersistenceWorkflowState1.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
import io.iworkflow.core.command.CommandResults;
1010
import io.iworkflow.core.communication.Communication;
1111
import io.iworkflow.core.persistence.Persistence;
12+
import io.iworkflow.integ.basic.FakContextImpl;
1213

1314
import java.util.Arrays;
1415

1516
import static io.iworkflow.integ.persistence.BasicPersistenceWorkflow.TEST_DATA_OBJECT_KEY;
17+
import static io.iworkflow.integ.persistence.BasicPersistenceWorkflow.TEST_DATA_OBJECT_MODEL_1;
18+
import static io.iworkflow.integ.persistence.BasicPersistenceWorkflow.TEST_DATA_OBJECT_MODEL_2;
1619
import static io.iworkflow.integ.persistence.BasicPersistenceWorkflow.TEST_SEARCH_ATTRIBUTE_INT;
1720
import static io.iworkflow.integ.persistence.BasicPersistenceWorkflow.TEST_SEARCH_ATTRIBUTE_KEYWORD;
1821

@@ -32,6 +35,15 @@ public Class<String> getInputType() {
3235
@Override
3336
public CommandRequest start(Context context, String input, Persistence persistence, final Communication communication) {
3437
persistence.setDataObject(TEST_DATA_OBJECT_KEY, "query-start");
38+
39+
// it's allowed to set a child class to a parent
40+
persistence.setDataObject(TEST_DATA_OBJECT_MODEL_1, new FakContextImpl());
41+
persistence.setDataObject(TEST_DATA_OBJECT_MODEL_1, new io.iworkflow.gen.models.Context());
42+
43+
// but it's not allowed to set a parent to child
44+
//persistence.setDataObject(TEST_DATA_OBJECT_MODEL_2, new io.iworkflow.gen.models.Context());
45+
persistence.setDataObject(TEST_DATA_OBJECT_MODEL_2, new FakContextImpl());
46+
3547
persistence.setStateLocal("test-key", "test-value-1");
3648
persistence.recordStateEvent("event-1", "event-1");
3749
persistence.recordStateEvent("event-2", "event-1", 2, "event-3");
@@ -44,6 +56,13 @@ public CommandRequest start(Context context, String input, Persistence persisten
4456
public StateDecision decide(Context context, String input, CommandResults commandResults, Persistence persistence, final Communication communication) {
4557
String str = persistence.getDataObject(TEST_DATA_OBJECT_KEY, String.class);
4658
persistence.setDataObject(TEST_DATA_OBJECT_KEY, str + "-query-decide");
59+
60+
// it's not allowed to assign a parent to child
61+
persistence.getDataObject(TEST_DATA_OBJECT_MODEL_1, io.iworkflow.gen.models.Context.class);
62+
// but it's allowed to assign child to parent
63+
persistence.getDataObject(TEST_DATA_OBJECT_MODEL_2, io.iworkflow.gen.models.Context.class);
64+
persistence.getDataObject(TEST_DATA_OBJECT_MODEL_2, FakContextImpl.class);
65+
4766
String testVal2 = persistence.getStateLocal("test-key", String.class);
4867
if (testVal2.equals("test-value-1")) {
4968
persistence.setStateLocal("test-key", "test-value-2");

0 commit comments

Comments
 (0)