package no.dusken.aranea.web.control; import no.dusken.aranea.model.Banner; import no.dusken.aranea.model.BannerLocation; import no.dusken.aranea.service.BannerLocationService; import org.junit.Before; import org.junit.Test; import org.springframework.ui.ExtendedModelMap; import org.springframework.ui.Model; 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 BannerLocationControllerTest { private BannerLocationController controller; private BannerLocationService bannerLocationService; @Before public void onSetup(){ bannerLocationService = mock(BannerLocationService.class); controller = new BannerLocationController(); controller.setBannerLocationService(bannerLocationService); } @Test public void testHandleBannerLocations() throws Exception { BannerLocation b1 = new BannerLocation(); b1.setBanner(new Banner()); when(bannerLocationService.getEntity(1L)).thenReturn(b1); BannerLocation b2 = new BannerLocation(); b2.setBanner(new Banner()); when(bannerLocationService.getEntity(2L)).thenReturn(b2); Model model = new ExtendedModelMap(); controller.handleBannerLocations(new long[]{1L, 2L}, model); List bannerlocations = (List) model.asMap().get("bannerlocations"); assertNotNull("Bannerlocations was null", bannerlocations); assertEquals("Wrong length", 2, bannerlocations.size()); } @Test public void testHandleBannerLocationsByName() throws Exception { BannerLocation b1 = new BannerLocation(); b1.setBanner(new Banner()); when(bannerLocationService.getByUrl("url1")).thenReturn(b1); BannerLocation b2 = new BannerLocation(); b2.setBanner(new Banner()); when(bannerLocationService.getByUrl("url2")).thenReturn(b2); Model model = new ExtendedModelMap(); controller.handleBannerLocationsByName(new String[]{"url1", "url2"}, model); List bannerlocations = (List) model.asMap().get("bannerlocations"); assertNotNull("Bannerlocations was null", bannerlocations); assertEquals("Wrong length", 2, bannerlocations.size()); } }