From 9ec41df27fd5ce5e76fd5ba55172b9eefb6b9921 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 8 Jan 2024 21:36:23 +0100 Subject: [PATCH] Add integration test for InventoryInitializer --- .../InventoryInitializerIntegrationTests.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/test/java/catering/inventory/InventoryInitializerIntegrationTests.java 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); + } +}