Search in sources :

Example 16 with Lesson

use of org.acme.schooltimetabling.domain.Lesson in project optaplanner-quickstarts by kiegroup.

the class LessonResourceTest method addAndRemove.

@Test
void addAndRemove() {
    Lesson lesson = given().when().contentType(ContentType.JSON).body(new Lesson("Test subject", "Test teacher", "test studentGroup")).post("/lessons").then().statusCode(201).extract().as(Lesson.class);
    given().when().delete("/lessons/{id}", lesson.getId()).then().statusCode(204);
}
Also used : Lesson(org.acme.schooltimetabling.domain.Lesson) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 17 with Lesson

use of org.acme.schooltimetabling.domain.Lesson in project optaplanner-quickstarts by kiegroup.

the class TimeTableResourceTest method solveDemoDataUntilFeasible.

@Test
@Timeout(600_000)
public void solveDemoDataUntilFeasible() throws InterruptedException {
    timeTableResource.solve();
    TimeTable timeTable;
    do {
        // Use do-while to give the solver some time and avoid retrieving an early infeasible solution.
        // Quick polling (not a Test Thread Sleep anti-pattern)
        // Test is still fast on fast machines and doesn't randomly fail on slow machines.
        Thread.sleep(20L);
        timeTable = timeTableResource.getTimeTable();
    } while (timeTable.getSolverStatus() != SolverStatus.NOT_SOLVING || !timeTable.getScore().isFeasible());
    assertFalse(timeTable.getLessonList().isEmpty());
    for (Lesson lesson : timeTable.getLessonList()) {
        assertNotNull(lesson.getTimeslot());
        assertNotNull(lesson.getRoom());
    }
    assertTrue(timeTable.getScore().isFeasible());
}
Also used : TimeTable(org.acme.schooltimetabling.domain.TimeTable) Lesson(org.acme.schooltimetabling.domain.Lesson) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Timeout(org.junit.jupiter.api.Timeout)

Example 18 with Lesson

use of org.acme.schooltimetabling.domain.Lesson in project optaplanner-quickstarts by kiegroup.

the class TimeTableMessagingHandlerTest method solvingThrowsException.

@Test
@Timeout(TEST_TIMEOUT_SECONDS)
void solvingThrowsException() {
    long problemId = 10L;
    // OptaPlanner doesn't tolerate a null planningId.
    TimeTable timeTableWithIncorrectLesson = new TimeTable(Arrays.asList(new Timeslot(1L, DayOfWeek.MONDAY, LocalTime.NOON, LocalTime.NOON.plusMinutes(30))), Arrays.asList(new Room(1L, "room-A")), Arrays.asList(new Lesson(null, "Math", "A. Touring", "10th grade")));
    sendSolverRequest(new SolverRequest(problemId, timeTableWithIncorrectLesson));
    SolverResponse solverResponse = receiveSolverResponse(MESSAGE_RECEIVE_TIMEOUT_SECONDS);
    assertThat(SolverResponse.ResponseStatus.FAILURE == solverResponse.getResponseStatus());
    assertThat(problemId == solverResponse.getProblemId());
    assertThat(solverResponse.getErrorInfo().getExceptionClassName()).isEqualTo(IllegalArgumentException.class.getName());
    assertThat(solverResponse.getErrorInfo().getExceptionMessage()).startsWith("The planningId (null)");
}
Also used : SolverRequest(org.acme.schooltimetabling.message.SolverRequest) TimeTable(org.acme.schooltimetabling.domain.TimeTable) SolverResponse(org.acme.schooltimetabling.message.SolverResponse) Timeslot(org.acme.schooltimetabling.domain.Timeslot) Room(org.acme.schooltimetabling.domain.Room) Lesson(org.acme.schooltimetabling.domain.Lesson) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

Lesson (org.acme.schooltimetabling.domain.Lesson)18 Test (org.junit.jupiter.api.Test)12 QuarkusTest (io.quarkus.test.junit.QuarkusTest)11 TimeTable (org.acme.schooltimetabling.domain.TimeTable)8 Room (org.acme.schooltimetabling.domain.Room)6 Timeslot (org.acme.schooltimetabling.domain.Timeslot)6 Timeout (org.junit.jupiter.api.Timeout)4 ArrayList (java.util.ArrayList)3 Transactional (javax.transaction.Transactional)2 SolverRequest (org.acme.schooltimetabling.message.SolverRequest)2 SolverResponse (org.acme.schooltimetabling.message.SolverResponse)2 DayOfWeek (java.time.DayOfWeek)1 Duration (java.time.Duration)1 LocalTime (java.time.LocalTime)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 TimeTableConstraintProvider (org.acme.schooltimetabling.solver.TimeTableConstraintProvider)1 Solver (org.optaplanner.core.api.solver.Solver)1