/**
 * 
 */
package org.richfaces.renderkit.html.images;

import java.awt.Color;

import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.ajax4jsf.util.HtmlColor;
import org.richfaces.component.html.HtmlToolBar;
import org.richfaces.renderkit.html.images.ToolBarSeparatorImage.SeparatorData;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;

/**
 * @author Anton Belevich
 *
 */
public class ToolBarSeparatorImageTest extends AbstractAjax4JsfTestCase {

	public ToolBarSeparatorImageTest(String name) {
		super(name);
	}
	
	public void testSaveResources(){
		
		ToolBarSeparatorImage img = new DotSeparatorImage();
		
		Skin skin = SkinFactory.getInstance().getSkin(facesContext);
		Skin defaultSkin = SkinFactory.getInstance().getDefaultSkin(facesContext);
		
		String skinParameter1 = "headerBackgroundColor";
		String headerBackgroundColor = (String) skin.getParameter(facesContext, skinParameter1);
		
		if (null == headerBackgroundColor || "".equals(headerBackgroundColor))
			headerBackgroundColor = (String) defaultSkin.getParameter(facesContext, skinParameter1);
		
		headerBackgroundColor = headerBackgroundColor == null ? "#224986" : headerBackgroundColor;
					
		Color color1 = HtmlColor.decode(headerBackgroundColor);
		
		String skinParameter2 = "headerGradientColor";
		String headerGradientColor = (String) skin.getParameter(facesContext, skinParameter2);
		
		if (null == headerGradientColor || "".equals(headerGradientColor))
			headerGradientColor = (String) defaultSkin.getParameter(facesContext, skinParameter2);
		
		headerGradientColor = headerGradientColor == null ? "#CCCCFF" : headerGradientColor;
		
		Color color2 = HtmlColor.decode(headerGradientColor);
		
		String skinParameter3 = "headerTextColor";
		String headerTextColor = (String) skin.getParameter(facesContext, skinParameter3);
		
		if (null == headerTextColor || "".equals(headerTextColor))
			headerTextColor = (String) defaultSkin.getParameter(facesContext, skinParameter3);
		
		headerTextColor = headerTextColor == null ? "#000000" : headerTextColor;
		
		Color color3 = HtmlColor.decode(headerTextColor);
		
		String skinParameter4 = "headerSizeFont";
		String headerSizeFont = (String) skin.getParameter(facesContext, skinParameter4);
		
		if (null == headerSizeFont || "".equals(headerSizeFont))
			headerSizeFont = (String) defaultSkin.getParameter(facesContext, skinParameter4);
		
		headerSizeFont = headerSizeFont == null ? "11px" : headerSizeFont;
		
		headerSizeFont = headerSizeFont.substring(0, headerSizeFont.indexOf("px"));
		
		HtmlToolBar toolBar = new HtmlToolBar();
		
		byte [] data = (byte []) img.getDataToStore(facesContext, toolBar);
		assertNotNull(data);
		SeparatorData separatorData = (SeparatorData)img.deserializeData(data);		
		
		assertNotNull(separatorData);
		assertEquals(color1, new Color(separatorData.getHeaderBackgroundColor()));
		assertEquals(color2, new Color(separatorData.getHeaderGradientColor()));
		assertEquals(color3, new Color(separatorData.getHeaderTextColor()));
		assertEquals(Integer.parseInt(headerSizeFont), separatorData.getFontSize());
		
	}
}
