Skip to content

Commit

Permalink
[KOGITO-7985] Job service integration tests improvements (#1497)
Browse files Browse the repository at this point in the history
* KOGITO-7985 Job service integration tests improvements
  • Loading branch information
tiagodolphine authored Nov 23, 2022
1 parent dd37301 commit 7c7f510
Show file tree
Hide file tree
Showing 43 changed files with 731 additions and 391 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.kie.kogito.test.TestUtils.assertJobsAndProcessOnDataIndex;

public abstract class BaseProcessTimerIT implements JobServiceHealthAware {

Expand All @@ -42,11 +43,16 @@ public abstract class BaseProcessTimerIT implements JobServiceHealthAware {
//Timers Tests
@Test
public void testTimers() {
String id = createTimer(new RequestPayload("PT02S"), TIMERS);
String id = createTimer(new RequestPayload("PT01S"), TIMERS);
Object id2 = getTimerById(id, TIMERS);
assertThat(id).isEqualTo(id2);
await().atMost(TIMEOUT)
.untilAsserted(() -> getTimerWithStatusCode(id, 404, TIMERS));
assertJobsAndProcessOnDataIndex(dataIndexUrl(), TIMERS, id, "COMPLETED", "EXECUTED", TIMEOUT);
}

public String dataIndexUrl() {
return null;
}

@Test
Expand All @@ -55,6 +61,7 @@ public void testCancelTimer() {
Object id2 = deleteTimer(id, TIMERS);
assertThat(id).isEqualTo(id2);
getTimerWithStatusCode(id, 404, TIMERS);
assertJobsAndProcessOnDataIndex(dataIndexUrl(), TIMERS, id, "ABORTED", "CANCELED", TIMEOUT);
}

//Cycle Timers Tests
Expand All @@ -64,25 +71,31 @@ public void testTimerCycle() {
String id2 = getTimerById(id, TIMERS_CYCLE);
assertThat(id).isEqualTo(id2);
await().atMost(TIMEOUT)
.untilAsserted(() -> getTimerWithStatusCode(id, 404, TIMERS));
.untilAsserted(() -> getTimerWithStatusCode(id, 404, TIMERS_CYCLE));
assertJobsAndProcessOnDataIndex(dataIndexUrl(), TIMERS_CYCLE, id, "COMPLETED", "EXECUTED", TIMEOUT);
}

@Test
public void testDeleteTimerCycle() {
String id = createTimer(new RequestPayload("R20/PT1S"), TIMERS_CYCLE);
String id = createTimer(new RequestPayload("R20/PT10S"), TIMERS_CYCLE);
String id2 = getTimerById(id, TIMERS_CYCLE);
assertThat(id).isEqualTo(id2);
deleteTimer(id, TIMERS_CYCLE);
await().atMost(TIMEOUT)
.untilAsserted(() -> getTimerWithStatusCode(id, 404, TIMERS_CYCLE));
await().atMost(TIMEOUT)
.untilAsserted(() -> assertJobsAndProcessOnDataIndex(dataIndexUrl(), TIMERS_CYCLE, id, "ABORTED", "CANCELED", TIMEOUT));
}

//Boundary Timers Tests
@Test
public void testBoundaryTimersOnTask() {
String id = createTimer(new RequestPayload("PT02S"), TIMERS_ON_TASK);
String id = createTimer(new RequestPayload("PT01S"), TIMERS_ON_TASK);
String id2 = getTimerById(id, TIMERS_ON_TASK);
assertThat(id).isEqualTo(id2);
await().atMost(TIMEOUT)
.untilAsserted(() -> getTimerWithStatusCode(id, 404, TIMERS_ON_TASK));
assertJobsAndProcessOnDataIndex(dataIndexUrl(), TIMERS_ON_TASK, id, "COMPLETED", "EXECUTED", TIMEOUT);
}

@Test
Expand All @@ -91,6 +104,7 @@ public void testDeleteBoundaryTimersOnTask() {
String id2 = getTimerById(id, TIMERS_ON_TASK);
assertThat(id).isEqualTo(id2);
deleteTimer(id, TIMERS_ON_TASK);
assertJobsAndProcessOnDataIndex(dataIndexUrl(), TIMERS_ON_TASK, id, "ABORTED", "CANCELED", TIMEOUT);
}

private ValidatableResponse getTimerWithStatusCode(String id, int code, String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package org.kie.kogito.test;

import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.awaitility.Awaitility;
import org.kie.kogito.test.quarkus.kafka.KafkaTestClient;

import io.restassured.http.ContentType;
Expand All @@ -28,6 +30,7 @@
import static io.restassured.RestAssured.given;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

public class TestUtils {
Expand Down Expand Up @@ -123,4 +126,47 @@ public static JsonPath waitForEvent(KafkaTestClient kafkaClient, String topic, l
assertThat(countDownLatch.await(seconds, TimeUnit.SECONDS)).isTrue();
return new JsonPath(cloudEvent.get());
}

public static void assertJobsAndProcessOnDataIndex(String dataIndexURL, String processId, String processInstanceId, String processStatus, String jobStatus, Duration timeout) {
if (dataIndexURL != null) {
String query = "{ \"query\" : " +
"\"{ProcessInstances (where : {" +
" id: {equal : \\\"" + processInstanceId + "\\\" }" +
" }) {" +
" id,processId,state" +
" }" +
"}\"" +
"}";
Awaitility.await()
.atMost(timeout)
.untilAsserted(() -> given()
.baseUri(dataIndexURL)
.contentType(ContentType.JSON)
.body(query)
.when().post("/graphql")
.then().statusCode(200)
.body("data.ProcessInstances.size()", is(1))
.body("data.ProcessInstances[0].id", is(processInstanceId))
.body("data.ProcessInstances[0].processId", is(processId))
.body("data.ProcessInstances[0].state", is(processStatus)));

String queryJobs = "{ \"query\" : " +
"\"{Jobs (where : {" +
" processInstanceId: {equal : \\\"" + processInstanceId + "\\\" }" +
" }) {" +
" status" +
" }" +
"}\"" +
"}";

given()
.baseUri(dataIndexURL)
.contentType(ContentType.JSON)
.body(queryJobs)
.when().post("/graphql")
.then().statusCode(200)
.body("data.Jobs.size()", is(1))
.body("data.Jobs[0].status", is(jobStatus));
}
}
}

This file was deleted.

Loading

0 comments on commit 7c7f510

Please sign in to comment.