-
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.
- Loading branch information
1 parent
ad9685b
commit 8faaf8c
Showing
3 changed files
with
87 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
37 changes: 37 additions & 0 deletions
37
...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,37 @@ | ||
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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@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(); | ||
String output = (String) run.getOutput(); | ||
|
||
assertEquals("Completed", run.getStatus() ); | ||
assertNotNull(run.getEnded_at()); | ||
|
||
assertEquals("Successfully cast Corgi", output); | ||
} | ||
} |