package no.dusken.aranea.web.control;
import no.dusken.aranea.model.Page;
import no.dusken.aranea.model.Section;
import no.dusken.aranea.service.PageService;
import no.dusken.aranea.service.SectionService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.Model;
import java.util.LinkedList;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Marvin B. Lillehaug <lillehau@underdusken.no>
*/
public class MeningerControllerTest {
private SectionService sectionService;
private PageService pageService;
private MeningerController controller;
@Before
public void onSetup() {
sectionService = mock(SectionService.class);
pageService = mock(PageService.class);
controller = new MeningerController();
controller.setPageService(pageService);
controller.setSectionService(sectionService);
}
@Test
public void testGetMening() throws Exception {
Section s = new Section(1L);
when(sectionService.getSectionByUrl("meninger", null)).thenReturn(s);
LinkedList<Page> values = new LinkedList<Page>();
when(pageService.getSectionPagePublished(1, s)).thenReturn(values);
Model model = new ExtendedModelMap( );
controller.getMening(model);
List<Page> pages = (List<Page>) model.asMap().get("mening");
assertNotNull("Pages was null", pages);
assertEquals("Wrong List", values, pages);
}
}