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.HtmlSeparator;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;

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

	public SimpleSeparatorImageTest(String name) {
		super(name);
	}
	
	public void testSaveResources(){
		
		Skin skin = SkinFactory.getInstance().getSkin(facesContext);
		Skin defaultSkin = SkinFactory.getInstance().getDefaultSkin(facesContext);
		
		SimpleSeparatorImage img = new SimpleSeparatorImage();
		
		String skinParameter1 = "headerBackgroundColor";
		String headerBackgroundColor = (String) skin.getParameter(facesContext, skinParameter1);
		
		if (null == headerBackgroundColor || "".equals(headerBackgroundColor))
			headerBackgroundColor = (String) defaultSkin.getParameter(facesContext, skinParameter1);
		
		headerBackgroundColor = headerBackgroundColor == null ? "#4169E1" : headerBackgroundColor;
					
		Color color1 = HtmlColor.decode(headerBackgroundColor);
		
		HtmlSeparator separator = new HtmlSeparator(); 
		
		byte [] data = (byte []) img.getDataToStore(facesContext, separator);
		assertNotNull(data);
		
		SimpleSeparatorImage.SimpleSeparatorData separatorData = (SimpleSeparatorImage.SimpleSeparatorData)img.deserializeData(data);
		assertEquals(color1, new Color(separatorData.getColor()));

	}
}
