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 java.util.List;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Marvin B. Lillehaug <lillehau@underdusken.no>
*/
public class BannerLocationTest {
private BannerLocationService service;
private BannerLocationController controller;
@Before
public void onSetup(){
controller = new BannerLocationController();
service = mock(BannerLocationService.class);
controller.setBannerLocationService(service);
}
@Test
public void testSeveralBannerLocations() throws Exception {
Banner a = new Banner();
BannerLocation bl1 = new BannerLocation();
BannerLocation bl2 = new BannerLocation();
bl1.setBanner(a);
bl2.setBanner(a);
when(service.getEntity(1L)).thenReturn(bl1);
when(service.getEntity(2L)).thenReturn(bl2);
ExtendedModelMap model = new ExtendedModelMap();
String mav = controller.handleBannerLocations(new long[]{1, 2}, model);
assertEquals("Wrong number of bannerlocations", 2, ((List)model.asMap().get("bannerlocations")).size());
}
}