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 2372351
Show file tree
Hide file tree
Showing 5 changed files with 127 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
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 2372351

Please sign in to comment.