Add integration test for InventoryInitializer

This commit is contained in:
Simon Bruder 2024-01-08 21:36:23 +01:00
parent d0ac59de87
commit 9ec41df27f
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC

View file

@ -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<UniqueInventoryItem> 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<UniqueInventoryItem> before = inventory.findAll().stream().collect(Collectors.toSet());
inventoryInitializer.initialize();
Set<UniqueInventoryItem> after = inventory.findAll().stream().collect(Collectors.toSet());
assertThat(before).hasSameElementsAs(after);
}
}