diff --git a/src/test/java/catering/inventory/InventoryInitializerIntegrationTests.java b/src/test/java/catering/inventory/InventoryInitializerIntegrationTests.java new file mode 100644 index 0000000..692883e --- /dev/null +++ b/src/test/java/catering/inventory/InventoryInitializerIntegrationTests.java @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +// SPDX-FileCopyrightText: 2024 swt23w23 +package catering.inventory; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Set; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.salespointframework.inventory.UniqueInventory; +import org.salespointframework.inventory.UniqueInventoryItem; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import catering.catalog.CateringCatalog; + +@SpringBootTest +class InventoryInitializerIntegrationTests { + @Autowired + UniqueInventory inventory; + @Autowired + CateringCatalog cateringCatalog; + + InventoryInitializer inventoryInitializer; + + @BeforeEach + void init() { + inventoryInitializer = new InventoryInitializer(inventory, cateringCatalog); + } + + /** + * Test if the inventory items are only created once. + * + * After the first startup, + * the catalog entries will only be changed through the inventory interfaces, + * which automatically keep the catalog in sync. + */ + @Test + void onlyRunOnce() { + // the first run is already done + Set before = inventory.findAll().stream().collect(Collectors.toSet()); + inventoryInitializer.initialize(); + Set after = inventory.findAll().stream().collect(Collectors.toSet()); + + assertThat(before).hasSameElementsAs(after); + } +}