diff --git a/src/test/java/org/openelisglobal/AppTestConfig.java b/src/test/java/org/openelisglobal/AppTestConfig.java index c790fd6441..b594fe39fd 100644 --- a/src/test/java/org/openelisglobal/AppTestConfig.java +++ b/src/test/java/org/openelisglobal/AppTestConfig.java @@ -50,8 +50,10 @@ "org.openelisglobal.systemusermodule.service", "org.openelisglobal.rolemodule.service", "org.openelisglobal.systemusermodule.daoimpl", "org.openelisglobal.systemusermodule.service", "org.openelisglobal.login.service", "org.openelisglobal.view", "org.openelisglobal.search.service", + "org.openelisglobal.sample.daoimpl", "org.openelisglobal.menu.MenuServiceTest", "org.openelisglobal.menu", "org.openelisglobal.sample.daoimpl", "org.openelisglobal.common.util", "org.openelisglobal.role", }, excludeFilters = { + @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.patient.controller.*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.dictionary.controller.*.java"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openelisglobal.config.*"), diff --git a/src/test/java/org/openelisglobal/menu/MenuServiceTest.java b/src/test/java/org/openelisglobal/menu/MenuServiceTest.java new file mode 100644 index 0000000000..c3e2417300 --- /dev/null +++ b/src/test/java/org/openelisglobal/menu/MenuServiceTest.java @@ -0,0 +1,75 @@ +package org.openelisglobal.menu; + +import java.util.List; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openelisglobal.BaseWebContextSensitiveTest; +import org.openelisglobal.menu.service.MenuService; +import org.openelisglobal.menu.util.MenuItem; +import org.openelisglobal.menu.valueholder.Menu; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +public class MenuServiceTest extends BaseWebContextSensitiveTest { + @Autowired + private MenuService menuService; + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + @Transactional + public void saveSingleMenuItem_shouldSaveAndReturnMenuItem() { + MenuItem menuItem = new MenuItem(); + Menu menu = new Menu(); + menu.setElementId("testElement"); + menuItem.setMenu(menu); + MenuItem savedItem = menuService.save(menuItem); + Assert.assertNotNull(savedItem); + } + + @Test + @Transactional + public void saveMultipleMenuItems_shouldSaveAndReturnMenuItems() { + MenuItem menuItem1 = new MenuItem(); + Menu menu1 = new Menu(); + menu1.setElementId("testElement1"); + menuItem1.setMenu(menu1); + MenuItem menuItem2 = new MenuItem(); + Menu menu2 = new Menu(); + menu2.setElementId("testElement2"); + menuItem2.setMenu(menu2); + List menuItems = List.of(menuItem1, menuItem2); + List savedItems = menuService.save(menuItems); + Assert.assertNotNull(savedItems); + Assert.assertEquals(2, savedItems.size()); + } + + @Test + @Transactional + public void getAllActiveMenus_shouldReturnOnlyActiveMenus() { + MenuItem activeItem = new MenuItem(); + Menu activeMenu = new Menu(); + activeMenu.setElementId("activeElement"); + activeMenu.setIsActive(true); + activeItem.setMenu(activeMenu); + menuService.save(activeItem); + MenuItem inactiveItem = new MenuItem(); + Menu inactiveMenu = new Menu(); + inactiveMenu.setElementId("inactiveElement"); + inactiveMenu.setIsActive(false); + inactiveItem.setMenu(inactiveMenu); + menuService.save(inactiveItem); + List activeMenus = menuService.getAllActiveMenus(); + Assert.assertNotNull(activeMenus); + Assert.assertFalse(activeMenus.isEmpty()); + Assert.assertTrue(activeMenus.stream().allMatch(Menu::getIsActive)); + } +}