mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-06-30 17:43:43 +02:00
I forgot to update them in commits743e459d41
,90d368a95b
,7fbd26d84c
, and2d87b3928b
. It also adds swt23w23 as copyright owner on the time recording, as this was forgotten when the attributions had initially been added.
98 lines
3.6 KiB
Java
98 lines
3.6 KiB
Java
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2023-2024 swt23w23
|
|
package catering.staff;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.salespointframework.core.Currencies.EURO;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.Set;
|
|
|
|
import org.javamoney.moneta.Money;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.salespointframework.order.OrderManagement;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
import catering.order.CustomCart;
|
|
import catering.order.CustomOrder;
|
|
import catering.order.OrderType;
|
|
import catering.users.User;
|
|
import catering.users.UserManagement;
|
|
import org.springframework.test.annotation.DirtiesContext;
|
|
|
|
@SpringBootTest
|
|
class StaffManagmentIntegrationTest {
|
|
|
|
@Autowired
|
|
private StaffManagement staffManagement;
|
|
|
|
@Autowired
|
|
private OrderManagement<CustomOrder> orderManagement;
|
|
|
|
@Autowired
|
|
private UserManagement userManagement;
|
|
|
|
private User defaultUser;
|
|
|
|
Employee e1;
|
|
Employee e2;
|
|
Employee e3;
|
|
Employee e4;
|
|
Employee e5;
|
|
Employee e6;
|
|
|
|
CustomOrder c1;
|
|
CustomOrder c2;
|
|
CustomOrder c3;
|
|
CustomOrder c4;
|
|
CustomOrder c5;
|
|
CustomOrder c6;
|
|
CustomOrder c7;
|
|
|
|
CustomOrder createCustomOrder(LocalDateTime start, LocalDateTime end, Set<Employee> staff) {
|
|
CustomOrder order = orderManagement.save(new CustomOrder(defaultUser.getUserAccount().getId(),
|
|
new CustomCart(OrderType.EVENT_CATERING, start, end)));
|
|
staff.forEach(order::addEmployee);
|
|
return orderManagement.save(order);
|
|
}
|
|
|
|
@BeforeEach
|
|
void addEmployees() {
|
|
defaultUser = userManagement.createCustomer("sarah", "Baum Weg", "123", "Sarah Klaus");
|
|
|
|
e1 = staffManagement.save(new Employee("Alan Turing", JobType.COOK, Money.of(10, EURO)));
|
|
e2 = staffManagement.save(new Employee("Ada Lovelace", JobType.COOK, Money.of(10, EURO)));
|
|
e3 = staffManagement.save(new Employee("Donald Knuth", JobType.COOK, Money.of(10, EURO)));
|
|
e4 = staffManagement.save(new Employee("Grace Hopper", JobType.SERVICE, Money.of(10, EURO)));
|
|
e5 = staffManagement.save(new Employee("John von Neumann", JobType.SERVICE, Money.of(10, EURO)));
|
|
e6 = staffManagement.save(new Employee("Noam Chomsky", JobType.SERVICE, Money.of(10, EURO)));
|
|
|
|
c1 = createCustomOrder(LocalDateTime.of(2023, 10, 27, 6, 0), LocalDateTime.of(2023, 10, 27, 20, 0), Set.of(e1));
|
|
c2 = createCustomOrder(LocalDateTime.of(2023, 10, 27, 8, 0), LocalDateTime.of(2023, 10, 27, 16, 0), Set.of(e2));
|
|
c3 = createCustomOrder(LocalDateTime.of(2023, 10, 27, 18, 0), LocalDateTime.of(2023, 10, 27, 22, 0),
|
|
Set.of(e3));
|
|
c4 = createCustomOrder(LocalDateTime.of(2023, 10, 27, 16, 0), LocalDateTime.of(2023, 10, 27, 18, 0),
|
|
Set.of(e4));
|
|
c5 = createCustomOrder(LocalDateTime.of(2023, 10, 27, 8, 0), LocalDateTime.of(2023, 10, 27, 12, 0), Set.of(e5));
|
|
c6 = createCustomOrder(LocalDateTime.of(2023, 10, 21, 12, 0), LocalDateTime.of(2023, 10, 21, 22, 0),
|
|
Set.of(e6));
|
|
c7 = createCustomOrder(LocalDateTime.of(2023, 10, 27, 19, 0), LocalDateTime.of(2023, 10, 28, 12, 0), Set.of(e2, e3));
|
|
}
|
|
|
|
@Test
|
|
@DirtiesContext
|
|
void getAvailableEmployees() throws Exception {
|
|
Set<Employee> availableService = staffManagement.getAvailableStaffByJob(JobType.SERVICE,
|
|
LocalDateTime.of(2023, 10, 27, 16, 0), LocalDateTime.of(2023, 10, 27, 18, 0));
|
|
Set<Employee> availableCook = staffManagement.getAvailableStaffByJob(JobType.COOK,
|
|
LocalDateTime.of(2023, 10, 27, 16, 0), LocalDateTime.of(2023, 10, 27, 18, 0));
|
|
|
|
assertThat(availableCook.size()).isEqualTo(0);
|
|
assertThat(availableService.size()).isEqualTo(2);
|
|
assertThat(availableService).contains(e5, e6);
|
|
}
|
|
|
|
}
|