-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for the general case of deserializing a subclass
This shows that the issue is not limited to StepError/Exception.
- Loading branch information
1 parent
fc3c642
commit e42333f
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...o/src/main/java/com/inngest/springbootdemo/testfunctions/DeserializeSubclassFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.inngest.springbootdemo.testfunctions; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.inngest.FunctionContext; | ||
import com.inngest.InngestFunction; | ||
import com.inngest.InngestFunctionConfigBuilder; | ||
import com.inngest.Step; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
class Dog { | ||
@JsonProperty("legs") | ||
public int legs; | ||
|
||
public Dog(@JsonProperty("legs") int legs) { | ||
this.legs = legs; | ||
} | ||
} | ||
|
||
class Corgi extends Dog { | ||
@JsonProperty("stumpy") | ||
public boolean stumpy; | ||
|
||
public Corgi(@JsonProperty("legs") int legs, @JsonProperty("stumpy") boolean stumpy) { | ||
super(legs); | ||
|
||
this.stumpy = stumpy; | ||
} | ||
} | ||
|
||
public class DeserializeSubclassFunction extends InngestFunction { | ||
@NotNull | ||
@Override | ||
public InngestFunctionConfigBuilder config(InngestFunctionConfigBuilder builder) { | ||
return builder | ||
.id("DeserializeSubclassFunction") | ||
.name("Deserialize subclass function") | ||
.triggerEvent("test/deserialize.subclass") | ||
.retries(0); | ||
} | ||
|
||
@Override | ||
public String execute(FunctionContext ctx, Step step) { | ||
Dog corgi = step.run("get-corgi", () -> new Corgi(4, true), Dog.class); | ||
|
||
assert(((Corgi) corgi).stumpy == true); | ||
|
||
return "Successfully cast Corgi"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ng-boot-demo/src/test/java/com/inngest/springbootdemo/DeserializationIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.inngest.springbootdemo; | ||
|
||
import com.inngest.Inngest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
import org.junit.jupiter.api.parallel.ExecutionMode; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.LinkedHashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@IntegrationTest | ||
@Execution(ExecutionMode.CONCURRENT) | ||
class DeserializationIntegrationTest { | ||
@Autowired | ||
private DevServerComponent devServer; | ||
|
||
static int sleepTime = 5000; | ||
|
||
@Autowired | ||
private Inngest client; | ||
|
||
@Test | ||
void testShouldDeserializeSubclassCorrectly() throws Exception { | ||
String eventId = InngestFunctionTestHelpers.sendEvent(client, "test/deserialize.subclass").getIds()[0]; | ||
|
||
Thread.sleep(sleepTime); | ||
|
||
RunEntry<Object> run = devServer.runsByEvent(eventId).first(); | ||
Object output = run.getOutput(); | ||
if (output instanceof LinkedHashMap) { | ||
fail("Run threw an exception serialized into a LinkedHashMap:" + output); | ||
} | ||
String outputString = (String) output; | ||
|
||
assertEquals("Completed", run.getStatus() ); | ||
assertNotNull(run.getEnded_at()); | ||
|
||
assertEquals("Successfully cast Corgi", outputString); | ||
} | ||
} |