Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for MenuService #1217

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/test/java/org/openelisglobal/AppTestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"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", }, excludeFilters = {
"org.openelisglobal.sample.daoimpl","org.openelisglobal.menu.MenuServiceTest", "org.openelisglobal.menu" }, 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.*"),
Expand Down
94 changes: 94 additions & 0 deletions src/test/java/org/openelisglobal/menu/MenuServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.openelisglobal.menu;

import org.openelisglobal.BaseWebContextSensitiveTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
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 java.util.List;

import static org.junit.Assert.*;

public class MenuServiceTest extends BaseWebContextSensitiveTest {
@Autowired
private MenuService menuService;

@Before
public void setUp() {
// Setup code here if needed
}

@After
public void tearDown() {
// Tear down code here if needed
}

@Test
public void testSaveSingleMenuItem() {
Agaba-derrick marked this conversation as resolved.
Show resolved Hide resolved
// Create and save a MenuItem
MenuItem menuItem = new MenuItem();
Menu menu = new Menu();
menu.setElementId("testElement");
menuItem.setMenu(menu);

MenuItem savedItem = menuService.save(menuItem);

// Assertions
assertNotNull(savedItem);

}

@Test
public void testSaveMultipleMenuItems() {
Agaba-derrick marked this conversation as resolved.
Show resolved Hide resolved
// Create and save multiple MenuItems
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<MenuItem> menuItems = List.of(menuItem1, menuItem2);

List<MenuItem> savedItems = menuService.save(menuItems);

// Assertions
assertNotNull(savedItems);
assertEquals(2, savedItems.size());
}

@Test
public void testGetAllActiveMenus() {
Agaba-derrick marked this conversation as resolved.
Show resolved Hide resolved
// Create and save active and inactive MenuItems
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);

// Retrieve all active menus
List<Menu> activeMenus = menuService.getAllActiveMenus();

// Assertions
assertNotNull(activeMenus);
assertFalse(activeMenus.isEmpty());
assertTrue(activeMenus.stream().allMatch(Menu::getIsActive));
}


}

Loading