Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmunozfe committed Sep 20, 2024
1 parent 897169f commit c9f017a
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

@Timeout(10000)
public abstract class AbstractMessagingConsumerIT {
Expand Down Expand Up @@ -121,6 +122,73 @@ void testJobEvent() throws Exception {
.body("data.Jobs[0].id", is(jobId)));
}

@Test
void testProcessInstanceEventCollection() throws Exception {
assumeTrue(shouldRunCollectionTests());
sendProcessInstanceEventCollection();

String processInstanceId1 = "processId-UUID1";
String processInstanceId2 = "processId-UUID2";

await()
.atMost(timeout)
.untilAsserted(() -> given().contentType(ContentType.JSON)
.body("{ \"query\" : \"{ ProcessInstances { id, state } }\" }")
.when().post("/graphql")
.then().log().ifValidationFails().statusCode(200)
.body("data.ProcessInstances.size()", is(2))
.body("data.ProcessInstances[0].id", is(processInstanceId1))
.body("data.ProcessInstances[0].state", is("ACTIVE"))
.body("data.ProcessInstances[1].id", is(processInstanceId2))
.body("data.ProcessInstances[1].state", is("ACTIVE")));

}

@Test
void testUserTaskInstanceEventCollection() throws Exception {
assumeTrue(shouldRunCollectionTests());
sendUserTaskInstanceEventCollection();

String taskId1 = "taskId-UUID1";
String taskId2 = "taskId-UUID2";

await()
.atMost(timeout)
.untilAsserted(() -> given().contentType(ContentType.JSON)
.body("{ \"query\" : \"{ UserTaskInstances { id, state } }\" }")
.when().post("/graphql")
.then().log().ifValidationFails().statusCode(200)
.body("data.UserTaskInstances.size()", is(2))
.body("data.UserTaskInstances[0].id", is(taskId1))
.body("data.UserTaskInstances[0].state", is("IN_PROGRESS"))
.body("data.UserTaskInstances[1].id", is(taskId2))
.body("data.UserTaskInstances[1].state", is("COMPLETED")));
}

@Test
void testProcessDefinitionEventCollection() throws Exception {
assumeTrue(shouldRunCollectionTests());
sendProcessDefinitionEventCollection();

String definitionId = "jsongreet";

await()
.atMost(timeout)
.untilAsserted(() -> given().contentType(ContentType.JSON)
.body("{ \"query\" : \"{ ProcessDefinitions { id, version } }\" }")
.when().post("/graphql")
.then().log().ifValidationFails().statusCode(200)
.body("data.ProcessDefinitions.size()", is(2))
.body("data.ProcessDefinitions[0].id", is(definitionId))
.body("data.ProcessDefinitions[0].version", is("1.0"))
.body("data.ProcessDefinitions[1].id", is(definitionId))
.body("data.ProcessDefinitions[1].version", is("1.1")));
}

protected boolean shouldRunCollectionTests() {
return true; // Default is to run the collection tests
}

protected abstract void sendUserTaskInstanceEvent() throws Exception;

protected abstract void sendProcessInstanceEvent() throws Exception;
Expand All @@ -129,4 +197,9 @@ void testJobEvent() throws Exception {

protected abstract void sendJobEvent() throws Exception;

protected abstract void sendProcessInstanceEventCollection() throws Exception;

protected abstract void sendUserTaskInstanceEventCollection() throws Exception;

protected abstract void sendProcessDefinitionEventCollection() throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package org.kie.kogito.index.service.messaging;

import java.util.Collection;
import java.util.List;

import org.kie.kogito.event.process.ProcessDefinitionDataEvent;
import org.kie.kogito.event.process.ProcessInstanceDataEvent;
import org.kie.kogito.event.usertask.UserTaskInstanceDataEvent;
Expand Down Expand Up @@ -69,4 +72,27 @@ protected void sendJobEvent() throws Exception {
connector.source(KOGITO_JOBS_EVENTS).send(event);
}

protected void sendProcessInstanceEventCollection() throws Exception {
Collection<ProcessInstanceDataEvent<?>> events = List.of(
getProcessCloudEvent("travels", "processId-UUID1", ProcessInstanceState.ACTIVE, null, null, null, "user1"),
getProcessCloudEvent("travels", "processId-UUID2", ProcessInstanceState.ACTIVE, null, null, null, "user2"));
connector.source(KOGITO_PROCESSINSTANCES_EVENTS).send(events);
}

@Override
protected void sendUserTaskInstanceEventCollection() throws Exception {
Collection<UserTaskInstanceDataEvent<?>> events = List.of(
getUserTaskCloudEvent("taskId-UUID1", "travels", "processId-UUID1", null, null, "IN_PROGRESS"),
getUserTaskCloudEvent("taskId-UUID2", "travels", "processId-UUID1", null, null, "COMPLETED"));
connector.source(KOGITO_USERTASKINSTANCES_EVENTS).send(events);
}

@Override
protected void sendProcessDefinitionEventCollection() throws Exception {
Collection<ProcessDefinitionDataEvent> events = List.of(
JsonUtils.getObjectMapper().readValue(readFileContent("process_definition_event.json"), ProcessDefinitionDataEvent.class),
JsonUtils.getObjectMapper().readValue(readFileContent("process_definition_11_event.json"), ProcessDefinitionDataEvent.class));
connector.source(KOGITO_PROCESS_DEFINITIONS_EVENTS).send(events);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ protected void sendJobEvent() throws Exception {
send("job_event.json", KOGITO_JOBS_EVENTS);
}

@Override
protected void sendProcessInstanceEventCollection() throws Exception {
}

@Override
protected void sendUserTaskInstanceEventCollection() throws Exception {
}

@Override
protected void sendProcessDefinitionEventCollection() throws Exception {
}

private void send(String file, String topic) throws Exception {
String json = readFileContent(file);
kafkaClient.produce(json, topic);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"id": "717af02d-645a-4b27-8058-b67ff1fa8edb",
"source": "http://localhost:8080/jsongreet",
"type": "ProcessDefinitionEvent",
"time": "2023-10-19T10:18:01.540311-03:00",
"data": {
"id": "jsongreet",
"name": "Greeting workflow",
"description": "JSON based greeting workflow",
"version": "1.1",
"type": "ProcessDefinitionEvent",
"roles": null,
"addons": [
"source-files",
"cloudevents"
],
"annotations": [
"test2",
"test3",
"test1"
],
"endpoint": "http://localhost:8080/jsongreet",
"source": null,
"metadata": {
"Description": "JSON based greeting workflow",
"annotations": [
"test1",
"test2",
"test3"
],
"Tags": [
"test1",
"test2",
"test3"
]
},
"nodes": [
{
"id": "1",
"name": "Start",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-12",
"metadata": {
"UniqueId": "_jbpm-unique-12",
"state": "ChooseOnLanguage"
}
},
{
"id": "2",
"name": "End",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-13",
"metadata": {
"UniqueId": "_jbpm-unique-13",
"state": "GreetPerson"
}
},
{
"id": "3",
"name": "ChooseOnLanguage",
"type": "INTERNAL",
"uniqueId": "3",
"metadata": {
"UniqueId": "3",
"Variable": "workflowdata",
"state": "ChooseOnLanguage",
"Default": "3_12"
}
},
{
"id": "4",
"name": "GreetInEnglish",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-15",
"metadata": {
"UniqueId": "_jbpm-unique-15",
"state": "GreetInEnglish"
}
},
{
"id": "5",
"name": "GreetInSpanish",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-16",
"metadata": {
"UniqueId": "_jbpm-unique-16",
"state": "GreetInSpanish"
}
},
{
"id": "6",
"name": "GreetPerson",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-17",
"metadata": {
"UniqueId": "_jbpm-unique-17",
"state": "GreetPerson"
}
},
{
"id": "7",
"name": "EmbeddedStart",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-18",
"metadata": {
"UniqueId": "_jbpm-unique-18"
}
},
{
"id": "9",
"name": "greetFunction",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-19",
"metadata": {
"UniqueId": "_jbpm-unique-19",
"action": "greetAction",
"state": "GreetPerson"
}
},
{
"id": "10",
"name": "Script",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-20",
"metadata": {
"UniqueId": "_jbpm-unique-20"
}
},
{
"id": "11",
"name": "EmbeddedEnd",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-21",
"metadata": {
"UniqueId": "_jbpm-unique-21"
}
},
{
"id": "12",
"name": "Join-GreetInEnglish",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-22",
"metadata": {
"UniqueId": "_jbpm-unique-22",
"state": "GreetInEnglish"
}
},
{
"id": "13",
"name": "Join-GreetPerson",
"type": "INTERNAL",
"uniqueId": "_jbpm-unique-23",
"metadata": {
"UniqueId": "_jbpm-unique-23",
"state": "GreetPerson"
}
}
]
},
"specversion": "1.0",
"kogitoprocid": "jsongreet"
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
@TestProfile(KafkaMessageTestProfile.class)
class PostgreSqlMessagingKafkaConsumerIT extends AbstractMessagingKafkaConsumerIT {

@Override
protected boolean shouldRunCollectionTests() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
# under the License.
#

quarkus.log.console.enable=true
quarkus.log.console.level=INFO
quarkus.log.level=DEBUG
quarkus.log.category."org.kie.kogito".level=DEBUG
quarkus.log.category."org.kie.kogito".min-level=DEBUG
quarkus.log.category."io.vertx".level=DEBUG
quarkus.log.category."io.restassured".level=DEBUG
quarkus.log.category."graphql".level=DEBUG
quarkus.log.category."io.smallrye".level=DEBUG



#Data Index
kogito.apps.persistence.type=postgresql
kogito.data-index.domain-indexing=false
Expand Down

0 comments on commit c9f017a

Please sign in to comment.