-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[incubator-kie-issues-1557] Marshalling POJO Input/output in user task
- Loading branch information
1 parent
8525f22
commit 3367181
Showing
4 changed files
with
241 additions
and
8 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -31,6 +31,10 @@ | |
import org.kie.kogito.usertask.model.AttachmentInfo; | ||
import org.kie.kogito.usertask.model.CommentInfo; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; | ||
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
|
@@ -39,6 +43,7 @@ | |
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchema; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@QuarkusIntegrationTest | ||
|
@@ -105,6 +110,66 @@ void testJsonSchema() throws IOException { | |
} | ||
} | ||
|
||
@Test | ||
public void testInputOutputsViaJsonTypeProperty() throws Exception { | ||
Traveller traveller = new Traveller("pepe", "rubiales", "[email protected]", "Spanish", null); | ||
|
||
given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(Collections.singletonMap("traveller", traveller)) | ||
.post("/approvals") | ||
.then() | ||
.statusCode(201) | ||
.extract() | ||
.path("id"); | ||
|
||
String taskId = given() | ||
.contentType(ContentType.JSON) | ||
.queryParam("user", "admin") | ||
.queryParam("group", "managers") | ||
.when() | ||
.get("/usertasks/instance") | ||
.then() | ||
.statusCode(200) | ||
.extract() | ||
.path("[0].id"); | ||
|
||
traveller = new Traveller("pepe2", "rubiales2", "[email protected]", "Spanish2", null); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.activateDefaultTypingAsProperty(BasicPolymorphicTypeValidator.builder().build(), DefaultTyping.NON_FINAL, "@type"); | ||
String jsonBody = mapper.writeValueAsString(Map.of("traveller", traveller)); | ||
given().contentType(ContentType.JSON) | ||
.when() | ||
.queryParam("user", "admin") | ||
.queryParam("group", "managers") | ||
.pathParam("taskId", taskId) | ||
.body(jsonBody) | ||
.put("/usertasks/instance/{taskId}/inputs") | ||
.then() | ||
.log().body() | ||
.statusCode(200) | ||
.body("inputs.traveller.firstName", is(traveller.getFirstName())) | ||
.body("inputs.traveller.lastName", is(traveller.getLastName())) | ||
.body("inputs.traveller.email", is(traveller.getEmail())) | ||
.body("inputs.traveller.nationality", is(traveller.getNationality())); | ||
|
||
given().contentType(ContentType.JSON) | ||
.when() | ||
.queryParam("user", "admin") | ||
.queryParam("group", "managers") | ||
.pathParam("taskId", taskId) | ||
.body(jsonBody) | ||
.put("/usertasks/instance/{taskId}/outputs") | ||
.then() | ||
.log().body() | ||
.statusCode(200) | ||
.body("outputs.traveller.firstName", is(traveller.getFirstName())) | ||
.body("outputs.traveller.lastName", is(traveller.getLastName())) | ||
.body("outputs.traveller.email", is(traveller.getEmail())) | ||
.body("outputs.traveller.nationality", is(traveller.getNationality())); | ||
} | ||
|
||
@Test | ||
void testSaveTask() { | ||
Traveller traveller = new Traveller("pepe", "rubiales", "[email protected]", "Spanish"); | ||
|
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 |
---|---|---|
|
@@ -40,12 +40,17 @@ | |
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping; | ||
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator; | ||
|
||
import io.restassured.http.ContentType; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
|
@@ -111,6 +116,66 @@ void testJsonSchemaFiles() { | |
} | ||
} | ||
|
||
@Test | ||
public void testInputOutputsViaJsonTypeProperty() throws Exception { | ||
Traveller traveller = new Traveller("pepe", "rubiales", "[email protected]", "Spanish", null); | ||
|
||
given() | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.body(Collections.singletonMap("traveller", traveller)) | ||
.post("/approvals") | ||
.then() | ||
.statusCode(201) | ||
.extract() | ||
.path("id"); | ||
|
||
String taskId = given() | ||
.contentType(ContentType.JSON) | ||
.queryParam("user", "admin") | ||
.queryParam("group", "managers") | ||
.when() | ||
.get("/usertasks/instance") | ||
.then() | ||
.statusCode(200) | ||
.extract() | ||
.path("[0].id"); | ||
|
||
traveller = new Traveller("pepe2", "rubiales2", "[email protected]", "Spanish2", null); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.activateDefaultTypingAsProperty(BasicPolymorphicTypeValidator.builder().build(), DefaultTyping.NON_FINAL, "@type"); | ||
String jsonBody = mapper.writeValueAsString(Map.of("traveller", traveller)); | ||
given().contentType(ContentType.JSON) | ||
.when() | ||
.queryParam("user", "admin") | ||
.queryParam("group", "managers") | ||
.pathParam("taskId", taskId) | ||
.body(jsonBody) | ||
.put("/usertasks/instance/{taskId}/inputs") | ||
.then() | ||
.log().body() | ||
.statusCode(200) | ||
.body("inputs.traveller.firstName", is(traveller.getFirstName())) | ||
.body("inputs.traveller.lastName", is(traveller.getLastName())) | ||
.body("inputs.traveller.email", is(traveller.getEmail())) | ||
.body("inputs.traveller.nationality", is(traveller.getNationality())); | ||
|
||
given().contentType(ContentType.JSON) | ||
.when() | ||
.queryParam("user", "admin") | ||
.queryParam("group", "managers") | ||
.pathParam("taskId", taskId) | ||
.body(jsonBody) | ||
.put("/usertasks/instance/{taskId}/outputs") | ||
.then() | ||
.log().body() | ||
.statusCode(200) | ||
.body("outputs.traveller.firstName", is(traveller.getFirstName())) | ||
.body("outputs.traveller.lastName", is(traveller.getLastName())) | ||
.body("outputs.traveller.email", is(traveller.getEmail())) | ||
.body("outputs.traveller.nationality", is(traveller.getNationality())); | ||
} | ||
|
||
@Test | ||
void testCommentAndAttachment() { | ||
Traveller traveller = new Traveller("pepe", "rubiales", "[email protected]", "Spanish", null); | ||
|
@@ -371,4 +436,5 @@ void testUpdateTaskInfo() { | |
assertThat(downTaskInfo.getInputParams()).isNotNull(); | ||
assertThat(downTaskInfo.getInputParams().get("traveller")).isNull(); | ||
} | ||
|
||
} |