mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 12:09:35 +01:00
feat(production): Produktionsauftrag umterminieren und abfragen (US-P17)
Reschedule (PLANNED/RELEASED) mit Datumsvalidierung und List-Endpoint mit optionaler Filterung nach Datum/Status als Full Vertical Slice. Lasttests um neue Szenarien erweitert.
This commit is contained in:
parent
d63ac899e7
commit
ad33eed2f4
17 changed files with 1061 additions and 8 deletions
|
|
@ -0,0 +1,140 @@
|
|||
package de.effigenix.application.production;
|
||||
|
||||
import de.effigenix.domain.production.*;
|
||||
import de.effigenix.shared.common.Quantity;
|
||||
import de.effigenix.shared.common.RepositoryError;
|
||||
import de.effigenix.shared.common.Result;
|
||||
import de.effigenix.shared.common.UnitOfMeasure;
|
||||
import de.effigenix.shared.security.ActorId;
|
||||
import de.effigenix.shared.security.AuthorizationPort;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@DisplayName("ListProductionOrders Use Case")
|
||||
class ListProductionOrdersTest {
|
||||
|
||||
@Mock private ProductionOrderRepository productionOrderRepository;
|
||||
@Mock private AuthorizationPort authPort;
|
||||
|
||||
private ListProductionOrders listProductionOrders;
|
||||
private ActorId performedBy;
|
||||
|
||||
private static final LocalDate PLANNED_DATE = LocalDate.now().plusDays(7);
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
listProductionOrders = new ListProductionOrders(productionOrderRepository, authPort);
|
||||
performedBy = ActorId.of("admin-user");
|
||||
}
|
||||
|
||||
private ProductionOrder sampleOrder() {
|
||||
return ProductionOrder.reconstitute(
|
||||
ProductionOrderId.of("order-1"),
|
||||
RecipeId.of("recipe-1"),
|
||||
ProductionOrderStatus.PLANNED,
|
||||
null,
|
||||
Quantity.of(new BigDecimal("100"), UnitOfMeasure.KILOGRAM).unsafeGetValue(),
|
||||
PLANNED_DATE,
|
||||
Priority.NORMAL,
|
||||
null,
|
||||
null,
|
||||
OffsetDateTime.now(ZoneOffset.UTC),
|
||||
OffsetDateTime.now(ZoneOffset.UTC),
|
||||
1L
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should list all orders")
|
||||
void should_ListAll() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_READ)).thenReturn(true);
|
||||
when(productionOrderRepository.findAll()).thenReturn(Result.success(List.of(sampleOrder())));
|
||||
|
||||
var result = listProductionOrders.execute(performedBy);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
assertThat(result.unsafeGetValue()).hasSize(1);
|
||||
verify(productionOrderRepository).findAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should delegate to findByDateRange")
|
||||
void should_DelegateToFindByDateRange() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_READ)).thenReturn(true);
|
||||
var from = LocalDate.now();
|
||||
var to = LocalDate.now().plusDays(30);
|
||||
when(productionOrderRepository.findByDateRange(from, to)).thenReturn(Result.success(List.of(sampleOrder())));
|
||||
|
||||
var result = listProductionOrders.executeByDateRange(from, to, performedBy);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
verify(productionOrderRepository).findByDateRange(from, to);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should delegate to findByStatus")
|
||||
void should_DelegateToFindByStatus() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_READ)).thenReturn(true);
|
||||
when(productionOrderRepository.findByStatus(ProductionOrderStatus.PLANNED))
|
||||
.thenReturn(Result.success(List.of(sampleOrder())));
|
||||
|
||||
var result = listProductionOrders.executeByStatus(ProductionOrderStatus.PLANNED, performedBy);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
verify(productionOrderRepository).findByStatus(ProductionOrderStatus.PLANNED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should delegate to findByDateRangeAndStatus")
|
||||
void should_DelegateToFindByDateRangeAndStatus() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_READ)).thenReturn(true);
|
||||
var from = LocalDate.now();
|
||||
var to = LocalDate.now().plusDays(30);
|
||||
when(productionOrderRepository.findByDateRangeAndStatus(from, to, ProductionOrderStatus.PLANNED))
|
||||
.thenReturn(Result.success(List.of(sampleOrder())));
|
||||
|
||||
var result = listProductionOrders.executeByDateRangeAndStatus(from, to, ProductionOrderStatus.PLANNED, performedBy);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
verify(productionOrderRepository).findByDateRangeAndStatus(from, to, ProductionOrderStatus.PLANNED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when unauthorized")
|
||||
void should_Fail_When_Unauthorized() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_READ)).thenReturn(false);
|
||||
|
||||
var result = listProductionOrders.execute(performedBy);
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
assertThat(result.unsafeGetError()).isInstanceOf(ProductionOrderError.Unauthorized.class);
|
||||
verify(productionOrderRepository, never()).findAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when repository returns error")
|
||||
void should_Fail_When_RepositoryError() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_READ)).thenReturn(true);
|
||||
when(productionOrderRepository.findAll())
|
||||
.thenReturn(Result.failure(new RepositoryError.DatabaseError("connection lost")));
|
||||
|
||||
var result = listProductionOrders.execute(performedBy);
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
assertThat(result.unsafeGetError()).isInstanceOf(ProductionOrderError.RepositoryFailure.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
package de.effigenix.application.production;
|
||||
|
||||
import de.effigenix.application.production.command.RescheduleProductionOrderCommand;
|
||||
import de.effigenix.domain.production.*;
|
||||
import de.effigenix.shared.common.Quantity;
|
||||
import de.effigenix.shared.common.RepositoryError;
|
||||
import de.effigenix.shared.common.Result;
|
||||
import de.effigenix.shared.common.UnitOfMeasure;
|
||||
import de.effigenix.shared.persistence.UnitOfWork;
|
||||
import de.effigenix.shared.security.ActorId;
|
||||
import de.effigenix.shared.security.AuthorizationPort;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@DisplayName("RescheduleProductionOrder Use Case")
|
||||
class RescheduleProductionOrderTest {
|
||||
|
||||
@Mock private ProductionOrderRepository productionOrderRepository;
|
||||
@Mock private AuthorizationPort authPort;
|
||||
@Mock private UnitOfWork unitOfWork;
|
||||
|
||||
private RescheduleProductionOrder rescheduleProductionOrder;
|
||||
private ActorId performedBy;
|
||||
|
||||
private static final LocalDate PLANNED_DATE = LocalDate.now().plusDays(7);
|
||||
private static final LocalDate NEW_DATE = LocalDate.now().plusDays(14);
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
rescheduleProductionOrder = new RescheduleProductionOrder(productionOrderRepository, authPort, unitOfWork);
|
||||
performedBy = ActorId.of("admin-user");
|
||||
lenient().when(unitOfWork.executeAtomically(any())).thenAnswer(inv -> ((Supplier<?>) inv.getArgument(0)).get());
|
||||
}
|
||||
|
||||
private RescheduleProductionOrderCommand validCommand() {
|
||||
return new RescheduleProductionOrderCommand("order-1", NEW_DATE);
|
||||
}
|
||||
|
||||
private ProductionOrder orderWithStatus(ProductionOrderStatus status) {
|
||||
return ProductionOrder.reconstitute(
|
||||
ProductionOrderId.of("order-1"),
|
||||
RecipeId.of("recipe-1"),
|
||||
status,
|
||||
status == ProductionOrderStatus.IN_PROGRESS ? BatchId.of("batch-1") : null,
|
||||
Quantity.of(new BigDecimal("100"), UnitOfMeasure.KILOGRAM).unsafeGetValue(),
|
||||
PLANNED_DATE,
|
||||
Priority.NORMAL,
|
||||
null,
|
||||
null,
|
||||
OffsetDateTime.now(ZoneOffset.UTC),
|
||||
OffsetDateTime.now(ZoneOffset.UTC),
|
||||
1L
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should reschedule PLANNED order")
|
||||
void should_Reschedule_PlannedOrder() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_WRITE)).thenReturn(true);
|
||||
when(productionOrderRepository.findById(ProductionOrderId.of("order-1")))
|
||||
.thenReturn(Result.success(Optional.of(orderWithStatus(ProductionOrderStatus.PLANNED))));
|
||||
when(productionOrderRepository.save(any())).thenReturn(Result.success(null));
|
||||
|
||||
var result = rescheduleProductionOrder.execute(validCommand(), performedBy);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
assertThat(result.unsafeGetValue().plannedDate()).isEqualTo(NEW_DATE);
|
||||
verify(productionOrderRepository).save(any(ProductionOrder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should reschedule RELEASED order")
|
||||
void should_Reschedule_ReleasedOrder() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_WRITE)).thenReturn(true);
|
||||
when(productionOrderRepository.findById(ProductionOrderId.of("order-1")))
|
||||
.thenReturn(Result.success(Optional.of(orderWithStatus(ProductionOrderStatus.RELEASED))));
|
||||
when(productionOrderRepository.save(any())).thenReturn(Result.success(null));
|
||||
|
||||
var result = rescheduleProductionOrder.execute(validCommand(), performedBy);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
assertThat(result.unsafeGetValue().plannedDate()).isEqualTo(NEW_DATE);
|
||||
verify(productionOrderRepository).save(any(ProductionOrder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when order is IN_PROGRESS")
|
||||
void should_Fail_When_InProgress() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_WRITE)).thenReturn(true);
|
||||
when(productionOrderRepository.findById(ProductionOrderId.of("order-1")))
|
||||
.thenReturn(Result.success(Optional.of(orderWithStatus(ProductionOrderStatus.IN_PROGRESS))));
|
||||
|
||||
var result = rescheduleProductionOrder.execute(validCommand(), performedBy);
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
assertThat(result.unsafeGetError()).isInstanceOf(ProductionOrderError.InvalidStatusTransition.class);
|
||||
verify(productionOrderRepository, never()).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when new date is in the past")
|
||||
void should_Fail_When_DateInPast() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_WRITE)).thenReturn(true);
|
||||
when(productionOrderRepository.findById(ProductionOrderId.of("order-1")))
|
||||
.thenReturn(Result.success(Optional.of(orderWithStatus(ProductionOrderStatus.PLANNED))));
|
||||
|
||||
var pastDateCmd = new RescheduleProductionOrderCommand("order-1", LocalDate.now().minusDays(1));
|
||||
var result = rescheduleProductionOrder.execute(pastDateCmd, performedBy);
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
assertThat(result.unsafeGetError()).isInstanceOf(ProductionOrderError.PlannedDateInPast.class);
|
||||
verify(productionOrderRepository, never()).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when order not found")
|
||||
void should_Fail_When_OrderNotFound() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_WRITE)).thenReturn(true);
|
||||
when(productionOrderRepository.findById(ProductionOrderId.of("order-1")))
|
||||
.thenReturn(Result.success(Optional.empty()));
|
||||
|
||||
var result = rescheduleProductionOrder.execute(validCommand(), performedBy);
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
assertThat(result.unsafeGetError()).isInstanceOf(ProductionOrderError.ProductionOrderNotFound.class);
|
||||
verify(productionOrderRepository, never()).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when unauthorized")
|
||||
void should_Fail_When_Unauthorized() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_WRITE)).thenReturn(false);
|
||||
|
||||
var result = rescheduleProductionOrder.execute(validCommand(), performedBy);
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
assertThat(result.unsafeGetError()).isInstanceOf(ProductionOrderError.Unauthorized.class);
|
||||
verify(productionOrderRepository, never()).save(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when repository returns error")
|
||||
void should_Fail_When_RepositoryError() {
|
||||
when(authPort.can(performedBy, ProductionAction.PRODUCTION_ORDER_WRITE)).thenReturn(true);
|
||||
when(productionOrderRepository.findById(ProductionOrderId.of("order-1")))
|
||||
.thenReturn(Result.failure(new RepositoryError.DatabaseError("connection lost")));
|
||||
|
||||
var result = rescheduleProductionOrder.execute(validCommand(), performedBy);
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
assertThat(result.unsafeGetError()).isInstanceOf(ProductionOrderError.RepositoryFailure.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -706,6 +706,130 @@ class ProductionOrderTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("reschedule()")
|
||||
class Reschedule {
|
||||
|
||||
private ProductionOrder orderWithStatus(ProductionOrderStatus status) {
|
||||
return ProductionOrder.reconstitute(
|
||||
ProductionOrderId.of("order-1"),
|
||||
RecipeId.of("recipe-123"),
|
||||
status,
|
||||
status == ProductionOrderStatus.IN_PROGRESS || status == ProductionOrderStatus.COMPLETED
|
||||
? BatchId.of("batch-1") : null,
|
||||
Quantity.of(new BigDecimal("100"), UnitOfMeasure.KILOGRAM).unsafeGetValue(),
|
||||
FUTURE_DATE,
|
||||
Priority.NORMAL,
|
||||
null,
|
||||
null,
|
||||
OffsetDateTime.now(ZoneOffset.UTC).minusHours(1),
|
||||
OffsetDateTime.now(ZoneOffset.UTC).minusHours(1),
|
||||
1L
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should reschedule PLANNED order")
|
||||
void should_Reschedule_When_Planned() {
|
||||
var order = orderWithStatus(ProductionOrderStatus.PLANNED);
|
||||
var beforeUpdate = order.updatedAt();
|
||||
var newDate = LocalDate.now().plusDays(14);
|
||||
|
||||
var result = order.reschedule(newDate);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
assertThat(order.plannedDate()).isEqualTo(newDate);
|
||||
assertThat(order.status()).isEqualTo(ProductionOrderStatus.PLANNED);
|
||||
assertThat(order.updatedAt()).isAfter(beforeUpdate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should reschedule RELEASED order")
|
||||
void should_Reschedule_When_Released() {
|
||||
var order = orderWithStatus(ProductionOrderStatus.RELEASED);
|
||||
var beforeUpdate = order.updatedAt();
|
||||
var newDate = LocalDate.now().plusDays(14);
|
||||
|
||||
var result = order.reschedule(newDate);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
assertThat(order.plannedDate()).isEqualTo(newDate);
|
||||
assertThat(order.status()).isEqualTo(ProductionOrderStatus.RELEASED);
|
||||
assertThat(order.updatedAt()).isAfter(beforeUpdate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should accept today as new date")
|
||||
void should_Succeed_When_RescheduledToToday() {
|
||||
var order = orderWithStatus(ProductionOrderStatus.PLANNED);
|
||||
var today = LocalDate.now();
|
||||
|
||||
var result = order.reschedule(today);
|
||||
|
||||
assertThat(result.isSuccess()).isTrue();
|
||||
assertThat(order.plannedDate()).isEqualTo(today);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when rescheduling IN_PROGRESS order")
|
||||
void should_Fail_When_InProgress() {
|
||||
var order = orderWithStatus(ProductionOrderStatus.IN_PROGRESS);
|
||||
|
||||
var result = order.reschedule(LocalDate.now().plusDays(14));
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
var err = (ProductionOrderError.InvalidStatusTransition) result.unsafeGetError();
|
||||
assertThat(err.current()).isEqualTo(ProductionOrderStatus.IN_PROGRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when rescheduling COMPLETED order")
|
||||
void should_Fail_When_Completed() {
|
||||
var order = orderWithStatus(ProductionOrderStatus.COMPLETED);
|
||||
|
||||
var result = order.reschedule(LocalDate.now().plusDays(14));
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
var err = (ProductionOrderError.InvalidStatusTransition) result.unsafeGetError();
|
||||
assertThat(err.current()).isEqualTo(ProductionOrderStatus.COMPLETED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when rescheduling CANCELLED order")
|
||||
void should_Fail_When_Cancelled() {
|
||||
var order = orderWithStatus(ProductionOrderStatus.CANCELLED);
|
||||
|
||||
var result = order.reschedule(LocalDate.now().plusDays(14));
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
var err = (ProductionOrderError.InvalidStatusTransition) result.unsafeGetError();
|
||||
assertThat(err.current()).isEqualTo(ProductionOrderStatus.CANCELLED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should fail when new date is in the past")
|
||||
void should_Fail_When_DateInPast() {
|
||||
var order = orderWithStatus(ProductionOrderStatus.PLANNED);
|
||||
var yesterday = LocalDate.now().minusDays(1);
|
||||
|
||||
var result = order.reschedule(yesterday);
|
||||
|
||||
assertThat(result.isFailure()).isTrue();
|
||||
var err = (ProductionOrderError.PlannedDateInPast) result.unsafeGetError();
|
||||
assertThat(err.date()).isEqualTo(yesterday);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("should not change status on reschedule")
|
||||
void should_NotChangeStatus_When_Rescheduled() {
|
||||
var order = orderWithStatus(ProductionOrderStatus.RELEASED);
|
||||
|
||||
order.reschedule(LocalDate.now().plusDays(30));
|
||||
|
||||
assertThat(order.status()).isEqualTo(ProductionOrderStatus.RELEASED);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("reconstitute()")
|
||||
class Reconstitute {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import java.time.LocalDate;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
|
|
@ -829,6 +830,274 @@ class ProductionOrderControllerIntegrationTest extends AbstractIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("POST /api/production/production-orders/{id}/reschedule – Umterminieren")
|
||||
class RescheduleProductionOrderEndpoint {
|
||||
|
||||
@Test
|
||||
@DisplayName("PLANNED Order umterminieren → 200")
|
||||
void reschedule_plannedOrder_returns200() throws Exception {
|
||||
String orderId = createPlannedOrder();
|
||||
LocalDate newDate = LocalDate.now().plusDays(30);
|
||||
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(newDate);
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.plannedDate").value(newDate.toString()))
|
||||
.andExpect(jsonPath("$.status").value("PLANNED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("RELEASED Order umterminieren → 200")
|
||||
void reschedule_releasedOrder_returns200() throws Exception {
|
||||
String orderId = createReleasedOrder();
|
||||
LocalDate newDate = LocalDate.now().plusDays(30);
|
||||
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(newDate);
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.plannedDate").value(newDate.toString()))
|
||||
.andExpect(jsonPath("$.status").value("RELEASED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("IN_PROGRESS Order umterminieren → 409")
|
||||
void reschedule_inProgressOrder_returns409() throws Exception {
|
||||
String orderId = createInProgressOrder();
|
||||
LocalDate newDate = LocalDate.now().plusDays(30);
|
||||
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(newDate);
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.code").value("PRODUCTION_ORDER_INVALID_STATUS_TRANSITION"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Vergangenes Datum → 400")
|
||||
void reschedule_pastDate_returns400() throws Exception {
|
||||
String orderId = createPlannedOrder();
|
||||
LocalDate pastDate = LocalDate.now().minusDays(1);
|
||||
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(pastDate);
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$.code").value("PRODUCTION_ORDER_PLANNED_DATE_IN_PAST"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("COMPLETED Order umterminieren → 409")
|
||||
void reschedule_completedOrder_returns409() throws Exception {
|
||||
String[] orderAndBatch = createInProgressOrderWithCompletedBatch();
|
||||
String orderId = orderAndBatch[0];
|
||||
|
||||
// Complete the order
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/complete", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(LocalDate.now().plusDays(30));
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.code").value("PRODUCTION_ORDER_INVALID_STATUS_TRANSITION"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("CANCELLED Order umterminieren → 409")
|
||||
void reschedule_cancelledOrder_returns409() throws Exception {
|
||||
String orderId = createPlannedOrder();
|
||||
|
||||
// Cancel the order
|
||||
String cancelJson = """
|
||||
{"reason": "Testgrund"}
|
||||
""";
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/cancel", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(cancelJson))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(LocalDate.now().plusDays(30));
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.code").value("PRODUCTION_ORDER_INVALID_STATUS_TRANSITION"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Reschedule auf heute (Grenzwert) → 200")
|
||||
void reschedule_today_returns200() throws Exception {
|
||||
String orderId = createPlannedOrder();
|
||||
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(LocalDate.now());
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", orderId)
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.plannedDate").value(LocalDate.now().toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Nicht existierende Order → 400")
|
||||
void reschedule_notFound_returns400() throws Exception {
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(LocalDate.now().plusDays(30));
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", java.util.UUID.randomUUID().toString())
|
||||
.header("Authorization", "Bearer " + adminToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(jsonPath("$.code").value("PRODUCTION_ORDER_NOT_FOUND"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Nicht autorisiert → 403")
|
||||
void reschedule_unauthorized_returns403() throws Exception {
|
||||
String orderId = createPlannedOrder();
|
||||
LocalDate newDate = LocalDate.now().plusDays(30);
|
||||
|
||||
String json = """
|
||||
{"newPlannedDate": "%s"}
|
||||
""".formatted(newDate);
|
||||
|
||||
mockMvc.perform(post("/api/production/production-orders/{id}/reschedule", orderId)
|
||||
.header("Authorization", "Bearer " + viewerToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(json))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("GET /api/production/production-orders – Auflisten")
|
||||
class ListProductionOrdersEndpoint {
|
||||
|
||||
@Test
|
||||
@DisplayName("Alle Orders auflisten → 200")
|
||||
void listAll_returns200() throws Exception {
|
||||
createPlannedOrder();
|
||||
createPlannedOrder();
|
||||
|
||||
mockMvc.perform(get("/api/production/production-orders")
|
||||
.header("Authorization", "Bearer " + adminToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(org.hamcrest.Matchers.greaterThanOrEqualTo(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Nach Status filtern → 200")
|
||||
void listByStatus_returns200() throws Exception {
|
||||
createPlannedOrder();
|
||||
createReleasedOrder();
|
||||
|
||||
mockMvc.perform(get("/api/production/production-orders")
|
||||
.param("status", "PLANNED")
|
||||
.header("Authorization", "Bearer " + adminToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$[0].status").value("PLANNED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Nach Datumsbereich filtern → 200")
|
||||
void listByDateRange_returns200() throws Exception {
|
||||
createPlannedOrder();
|
||||
|
||||
mockMvc.perform(get("/api/production/production-orders")
|
||||
.param("dateFrom", LocalDate.now().toString())
|
||||
.param("dateTo", LocalDate.now().plusDays(30).toString())
|
||||
.header("Authorization", "Bearer " + adminToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(org.hamcrest.Matchers.greaterThanOrEqualTo(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Nach Datumsbereich und Status filtern → 200")
|
||||
void listByDateRangeAndStatus_returns200() throws Exception {
|
||||
createPlannedOrder();
|
||||
|
||||
mockMvc.perform(get("/api/production/production-orders")
|
||||
.param("dateFrom", LocalDate.now().toString())
|
||||
.param("dateTo", LocalDate.now().plusDays(30).toString())
|
||||
.param("status", "PLANNED")
|
||||
.header("Authorization", "Bearer " + adminToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$[0].status").value("PLANNED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Leere Ergebnisse bei nicht matchendem Datumsbereich → 200 mit []")
|
||||
void listByDateRange_noMatch_returnsEmptyList() throws Exception {
|
||||
createPlannedOrder();
|
||||
|
||||
mockMvc.perform(get("/api/production/production-orders")
|
||||
.param("dateFrom", LocalDate.now().plusYears(10).toString())
|
||||
.param("dateTo", LocalDate.now().plusYears(11).toString())
|
||||
.header("Authorization", "Bearer " + adminToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Nur dateFrom ohne dateTo → alle auflisten (kein Range-Filter)")
|
||||
void listWithOnlyDateFrom_returnsAll() throws Exception {
|
||||
createPlannedOrder();
|
||||
|
||||
mockMvc.perform(get("/api/production/production-orders")
|
||||
.param("dateFrom", LocalDate.now().toString())
|
||||
.header("Authorization", "Bearer " + adminToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(org.hamcrest.Matchers.greaterThanOrEqualTo(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Nicht autorisiert → 403")
|
||||
void list_unauthorized_returns403() throws Exception {
|
||||
mockMvc.perform(get("/api/production/production-orders")
|
||||
.header("Authorization", "Bearer " + viewerToken))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Hilfsmethoden ====================
|
||||
|
||||
private String createPlannedOrder() throws Exception {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue