File size: 3,788 Bytes
f568829 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
package org.acme.flighcrewscheduling.rest;
import static io.restassured.RestAssured.get;
import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import java.time.Duration;
import ai.timefold.solver.core.api.solver.SolverStatus;
import org.acme.flighcrewscheduling.domain.FlightCrewSchedule;
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
@QuarkusTest
class FlightCrewSchedulingResourceTest {
@Test
void solveDemoDataUntilFeasible() {
FlightCrewSchedule schedule = given()
.when().get("/demo-data")
.then()
.statusCode(200)
.extract()
.as(FlightCrewSchedule.class);
String jobId = given()
.contentType(ContentType.JSON)
.body(schedule)
.expect().contentType(ContentType.TEXT)
.when().post("/schedules")
.then()
.statusCode(200)
.extract()
.asString();
await()
.atMost(Duration.ofMinutes(1))
.pollInterval(Duration.ofMillis(500L))
.until(() -> SolverStatus.NOT_SOLVING.name().equals(
get("/schedules/" + jobId + "/status")
.jsonPath().get("solverStatus")));
FlightCrewSchedule solution = get("/schedules/" + jobId).then().extract().as(FlightCrewSchedule.class);
assertThat(solution.getSolverStatus()).isEqualTo(SolverStatus.NOT_SOLVING);
assertThat(solution.getFlightAssignments().stream()
.allMatch(assignment -> assignment.getEmployee() != null)).isTrue();
assertThat(solution.getScore().isFeasible()).isTrue();
}
@Test
void analyze() {
FlightCrewSchedule schedule = given()
.when().get("/demo-data")
.then()
.statusCode(200)
.extract()
.as(FlightCrewSchedule.class);
String jobId = given()
.contentType(ContentType.JSON)
.body(schedule)
.expect().contentType(ContentType.TEXT)
.when().post("/schedules")
.then()
.statusCode(200)
.extract()
.asString();
await()
.atMost(Duration.ofMinutes(1))
.pollInterval(Duration.ofMillis(500L))
.until(() -> SolverStatus.NOT_SOLVING.name().equals(
get("/schedules/" + jobId + "/status")
.jsonPath().get("solverStatus")));
FlightCrewSchedule solution = get("/schedules/" + jobId).then().extract().as(FlightCrewSchedule.class);
String analysis = given()
.contentType(ContentType.JSON)
.body(solution)
.expect().contentType(ContentType.JSON)
.when()
.put("/schedules/analyze")
.then()
.extract()
.asString();
// There are too many constraints to validate
assertThat(analysis).isNotNull();
String analysis2 = given()
.contentType(ContentType.JSON)
.queryParam("fetchPolicy", "FETCH_SHALLOW")
.body(solution)
.expect().contentType(ContentType.JSON)
.when()
.put("/schedules/analyze")
.then()
.extract()
.asString();
// There are too many constraints to validate
assertThat(analysis2).isNotNull();
}
} |