Skip to content

Commit

Permalink
fix some other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Oct 2, 2024
1 parent e3913df commit d496dbe
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.acme.travels.VisaApplication;
import org.acme.travels.VisaResolution;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.kie.kogito.Model;
import org.kie.kogito.auth.IdentityProviders;
Expand Down Expand Up @@ -98,7 +97,6 @@ public void testTravelNoVisaRequired() {
}

@Test
@Disabled
public void testTravelVisaRequired() {
String processInstance = whenNewTravel(TRAVELLER_FROM_POLAND, TRIP_TO_US);
thenProcessIsActive(processInstance);
Expand Down Expand Up @@ -173,8 +171,7 @@ private void thenProcessIsActive(String id) {
}

private void thenProcessIsCompleted(String id) {
ProcessInstance<? extends Model> processInstance = travelsProcess.instances().findById(id).get();
assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
assertThat(travelsProcess.instances().findById(id)).isEmpty();
}

private void thenHotelAndFlightAreChosen(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.kie.kogito.examples;

import java.util.Collections;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
Expand All @@ -30,22 +32,24 @@
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;

import jakarta.inject.Inject;
import jakarta.inject.Named;

import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.kie.kogito.test.utils.ProcessInstancesTestUtils.abort;

@SuppressWarnings("rawtypes")
import jakarta.inject.Inject;
import jakarta.inject.Named;

@QuarkusTest
@QuarkusTestResource(value = InfinispanQuarkusTestResource.Conditional.class)
@QuarkusTestResource(value = KafkaQuarkusTestResource.Conditional.class)
public class PersonsRestIT {

private static String USER_TASK_BASE_PATH = "/usertasks/instance";

@Inject
@Named("persons")
Process<? extends Model> personProcess;
Expand Down Expand Up @@ -236,19 +240,45 @@ public void testChildPersonsRestWithSecurityPolicyAndLifeCycles() {
.body("[0].name", is("ChildrenHandling"))
.extract()
.path("[0].id");

assertThat(taskId).isNotNull();
// test claim task
String fixedOrderPayload = "{}";
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(fixedOrderPayload).when().post("/persons/" + firstCreatedId + "/ChildrenHandling/" + taskId + "?phase=claim&user=admin")

String userTaskId = given()
.basePath(USER_TASK_BASE_PATH)
.queryParam("user", "admin")
.queryParam("group", "admins")
.contentType(ContentType.JSON)
.when()
.get()
.then()
.statusCode(200).body("id", is(firstCreatedId));
// test release task
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(fixedOrderPayload).when().post("/persons/" + firstCreatedId + "/ChildrenHandling/" + taskId + "?phase=release&user=admin")
.statusCode(200)
.extract()
.body()
.path("[0].id");
given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "release")
.queryParam("user", "admin")
.queryParam("group", "admins")
.body(Collections.emptyMap())
.when()
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200).body("id", is(firstCreatedId));
// test skip
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(fixedOrderPayload).when().post("/persons/" + firstCreatedId + "/ChildrenHandling/" + taskId + "?phase=skip&user=admin")
.statusCode(200);

given()
.contentType(ContentType.JSON)
.basePath(USER_TASK_BASE_PATH)
.queryParam("transitionId", "skip")
.queryParam("user", "admin")
.queryParam("group", "admins")
.body(Collections.emptyMap())
.when()
.post("/{userTaskId}/transition", userTaskId)
.then()
.statusCode(200).body("id", is(firstCreatedId));
.statusCode(200);

// get all persons make sure there is zero
given().accept(ContentType.JSON).when().get("/persons").then().statusCode(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,10 @@ public void testApprovalProcessViaPhases() {
ut.setOutput("approved", false);
ut.transition(DefaultUserTaskLifeCycle.COMPLETE, Collections.emptyMap(), userIdentity);
});
assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());

Model result = (Model) processInstance.variables();
assertEquals(4, result.toMap().size());
assertEquals(result.toMap().get("approver"), "manager");
assertEquals(result.toMap().get("firstLineApproval"), true);
assertEquals(result.toMap().get("secondLineApproval"), false);
// at this point the process instance does not exits.

assertThat(approvalsProcess.instances().findById(processInstance.id())).isEmpty();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

import jakarta.inject.Inject;
import jakarta.inject.Named;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import jakarta.inject.Inject;
import jakarta.inject.Named;

@QuarkusTest
@QuarkusTestResource(value = InfinispanQuarkusTestResource.class)
@QuarkusTestResource(value = KafkaQuarkusTestResource.class)
Expand Down

0 comments on commit d496dbe

Please sign in to comment.