flight-crew-scheduling-java
/
src
/test
/java
/org
/acme
/flighcrewscheduling
/rest
/FlightCrewSchedulingEnvironmentTest.java
| package org.acme.flighcrewscheduling.rest; | |
| import static io.restassured.RestAssured.given; | |
| import static org.assertj.core.api.Assertions.assertThat; | |
| import java.time.Duration; | |
| import jakarta.inject.Inject; | |
| import ai.timefold.solver.core.api.solver.Solver; | |
| import ai.timefold.solver.core.api.solver.SolverFactory; | |
| import ai.timefold.solver.core.config.solver.EnvironmentMode; | |
| import ai.timefold.solver.core.config.solver.SolverConfig; | |
| import org.acme.flighcrewscheduling.domain.FlightCrewSchedule; | |
| import org.junit.jupiter.api.Test; | |
| import org.junit.jupiter.api.condition.EnabledIfSystemProperty; | |
| import io.quarkus.test.junit.QuarkusTest; | |
| class FlightCrewSchedulingEnvironmentTest { | |
| SolverConfig solverConfig; | |
| void solveFullAssert() { | |
| solve(EnvironmentMode.FULL_ASSERT); | |
| } | |
| void solveStepAssert() { | |
| solve(EnvironmentMode.STEP_ASSERT); | |
| } | |
| void solve(EnvironmentMode environmentMode) { | |
| // Load the problem | |
| FlightCrewSchedule problem = given() | |
| .when().get("/demo-data") | |
| .then() | |
| .statusCode(200) | |
| .extract() | |
| .as(FlightCrewSchedule.class); | |
| // Update the environment | |
| SolverConfig updatedConfig = solverConfig.copyConfig(); | |
| updatedConfig.withEnvironmentMode(environmentMode) | |
| .withTerminationSpentLimit(Duration.ofSeconds(30)) | |
| .getTerminationConfig().withBestScoreLimit(null); | |
| SolverFactory<FlightCrewSchedule> solverFactory = SolverFactory.create(updatedConfig); | |
| // Solve the problem | |
| Solver<FlightCrewSchedule> solver = solverFactory.buildSolver(); | |
| FlightCrewSchedule solution = solver.solve(problem); | |
| assertThat(solution.getScore()).isNotNull(); | |
| } | |
| } |