package org.ajax4jsf.portlet.application;

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

import javax.faces.application.FacesMessage;
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;
import javax.faces.component.UIViewRoot;

import org.ajax4jsf.portlet.AbstractAjax4jsfPortletTestCase;

public class PortletViewStateTestCase extends AbstractAjax4jsfPortletTestCase {

    ComponentsLoaderImpl loader;
    private UIInput input;
    private UIOutput output;
    
    public PortletViewStateTestCase(String name) {
	super(name);
    }

    public void setUp() throws Exception {
	super.setUp();
    }

    public void tearDown() throws Exception {
	super.tearDown();
    }


    /**
     * 
     */
    private void setupTree() {
	input = new UIInput();
	input.setId("in");
	UIViewRoot viewRoot = facesContext.getViewRoot();
	viewRoot.getChildren().add(input);
	output = new UIOutput();
	output.setId("out");
	viewRoot.getFacets().put("facet",output);
    }

    public final void testSaveMessages() {
	setupActionRequest();
	setupTree();
	String clientId = input.getClientId(facesContext);
	FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,"msg","detail");
	facesContext.addMessage(clientId, facesMessage);
	PortletViewState state = new PortletViewState();
	state.saveMessages(facesContext);
	Map messages = state.getMessages();
	assertEquals(1, messages.size());
	List list = (List)messages.get(clientId);
	assertEquals(1, list.size());
	assertSame(facesMessage, list.get(0));
    }

    public final void testRestore() {
	// TODO - implement test
    }

    public final void testRestoreMessages() {
	// TODO - implement test
    }

    public final void testGetComponentsState() {
	// TODO - implement test
    }

    public final void testGetTreeStructure() {
	// TODO - implement test
    }

}
