/**
 * License Agreement.
 *
 *  JBoss RichFaces - Ajax4jsf Component Library
 *
 * Copyright (C) 2007  Exadel, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

package org.ajax4jsf.component;

import java.util.List;
import java.util.Map;


/**
 * @author Nick Belaevski
 * @since 3.3.0
 */

public class QueuedPollTest extends AbstractQueueComponentTest {

	/**
	 * @param name
	 */
	public QueuedPollTest(String name) {
		super(name);
	}

	private void setFlag(String name) {
		Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
		requestMap.put(name, Boolean.TRUE);
	}
	
	public void testQueuedDefaultPollRequestDelay() throws Exception {
		setFlag("queuedDefaultPollEnabled");
		renderView("/queue-poll.xhtml");
		
		TestsResult result = getTestsResult();
		List<RequestData> dataList = result.getDataList();
		
		assertEquals(1, dataList.size());
		checkRequestData(dataList.get(0), null, 600, 1600, false);
	}
	
	public void testQueuedPollRequestDelay() throws Exception {
		setFlag("queuedDelayedPollEnabled");
		renderView("/queue-poll.xhtml");
		
		TestsResult result = getTestsResult();
		List<RequestData> dataList = result.getDataList();
		
		assertEquals(1, dataList.size());
		checkRequestData(dataList.get(0), null, 300, 1300, false);
	}
	
	public void testDelayedQueueDefaultPollRequestDelay() throws Exception {
		setFlag("delayedQueueDefaultPollEnabled");
		renderView("/queue-poll.xhtml");
		
		TestsResult result = getTestsResult();
		List<RequestData> dataList = result.getDataList();
		
		assertEquals(1, dataList.size());
		checkRequestData(dataList.get(0), null, 1500, 2500, false);
	}
	
	public void testDelayedQueuePollRequestDelay() throws Exception {
		setFlag("delayedQueueDelayedPollEnabled");
		renderView("/queue-poll.xhtml");
		
		TestsResult result = getTestsResult();
		List<RequestData> dataList = result.getDataList();
		
		assertEquals(1, dataList.size());
		checkRequestData(dataList.get(0), null, 2400, 3400, false);
	}
	
	public void testUnqueuedDefaultPollRequestDelay() throws Exception {
		setFlag("unqueuedDefaultPollEnabled");
		renderView("/queue-poll.xhtml");
		
		TestsResult result = getTestsResult();
		List<RequestData> dataList = result.getDataList();
		
		assertEquals(1, dataList.size());
		checkRequestData(dataList.get(0), null, 700, 1700, false);
	}
	
	public void testunQueuedPollRequestDelay() throws Exception {
		setFlag("unqueuedDelayedPollEnabled");
		renderView("/queue-poll.xhtml");
		
		TestsResult result = getTestsResult();
		List<RequestData> dataList = result.getDataList();
		
		assertEquals(1, dataList.size());
		checkRequestData(dataList.get(0), null, 950, 1950, false);
	}
}
