package no.dusken.aranea.web.control; import no.dusken.aranea.model.Person; import no.dusken.aranea.model.Role; import no.dusken.aranea.service.RoleService; import org.junit.Before; import org.junit.Test; import org.springframework.ui.ExtendedModelMap; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import static junit.framework.Assert.*; import static org.mockito.Mockito.*; /** * @author Benjamin Bjørnseth <benjamin@underdusken.no> */ public class FooterControllerTest { private RoleService roleService; private FooterController footerController; @Before public void setUp() throws Exception { roleService = mock(RoleService.class); footerController = new FooterController(); footerController.setRoleService(roleService); } @Test public void testGetFooterView() throws Exception { Role editorRole = new Role(); Role netEditorRole = new Role(); when(roleService.getRolesByName("Ansvarlig redakt\u00f8r")).thenReturn(editorRole); when(roleService.getRolesByName("Nettredakt\u00f8r")).thenReturn(netEditorRole); Person editor = new Person(); editor.setFirstname("ans"); editor.setSurname("red"); editorRole.setPersons(Arrays.asList(editor)); Person netEditor = new Person(); netEditor.setFirstname("net"); netEditor.setSurname("red"); netEditorRole.setPersons(Arrays.asList(netEditor)); ExtendedModelMap model = new ExtendedModelMap(); String view = footerController.getFooterView(model); assertEquals(view, "no/dusken/aranea/base/common/footer"); assertEquals("wrong ansred", editor, model.asMap().get("ansred")); assertEquals("wrong netred", netEditor, model.asMap().get("netred")); } }