Author: alevkovsky
Date: 2008-11-22 09:49:50 -0500 (Sat, 22 Nov 2008)
New Revision: 11304
Added:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/EditorRendererTest.java
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/html/
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/html/images/
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/html/images/EditorIconTest.java
trunk/sandbox/ui/editor/src/test/resources/editorFull.properties
trunk/sandbox/ui/editor/src/test/resources/myplugins.properties
Removed:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/rendekit/
Modified:
trunk/sandbox/ui/editor/src/main/config/component/editor.xml
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorIcons.java
trunk/sandbox/ui/editor/src/test/java/org/richfaces/component/EditorComponentTest.java
Log:
Editor: Add JUnits with javadocs
Modified: trunk/sandbox/ui/editor/src/main/config/component/editor.xml
===================================================================
--- trunk/sandbox/ui/editor/src/main/config/component/editor.xml 2008-11-22 13:11:17 UTC
(rev 11303)
+++ trunk/sandbox/ui/editor/src/main/config/component/editor.xml 2008-11-22 14:49:50 UTC
(rev 11304)
@@ -7,7 +7,7 @@
<classname>org.richfaces.component.html.HtmlEditor</classname>
<superclass>org.richfaces.component.UIEditor</superclass>
<test>
- <classname>org.richfaces.component.EditorComponentTest</classname>
+ <classname>org.richfaces.component.html.HtmlEditorComponentTest</classname>
<superclassname>org.ajax4jsf.tests.AbstractAjax4JsfTestCase</superclassname>
</test>
<description>
@@ -22,8 +22,8 @@
<superclass>
org.ajax4jsf.webapp.taglib.HtmlComponentTagBase
</superclass>
- <test>
- </test>
+ <test>
+ </test>
</tag>
&ui_component_attributes;
&ui_input_attributes;
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorIcons.java
===================================================================
---
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorIcons.java 2008-11-22
13:11:17 UTC (rev 11303)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/html/images/EditorIcons.java 2008-11-22
14:49:50 UTC (rev 11304)
@@ -50,13 +50,13 @@
public abstract class EditorIcons extends Java2Dresource {
/** Additional background color parameter name in skin */
- private final String ADDITIONAL_BACKGROUND_COLOR =
"additionalBackgroundColor";
+ public final static String ADDITIONAL_BACKGROUND_COLOR =
"additionalBackgroundColor";
/** SelectControl color parameter name in skin */
- private final String SELECT_CONTROL_COLOR = "selectControlColor";
+ public final static String SELECT_CONTROL_COLOR = "selectControlColor";
/** Panel border color parameter name in skin */
- private final String PANEL_BORDER_COLOR = "panelBorderColor";
+ public final static String PANEL_BORDER_COLOR = "panelBorderColor";
/** General text color parameter name in skin */
- private final String GENERAL_TEXT_COLOR = "generalTextColor";
+ public final static String GENERAL_TEXT_COLOR = "generalTextColor";
/** Icon sub border transparency value */
private final int SUB_BORDER_TRANSPARENCY = 150;
@@ -76,13 +76,18 @@
* @see
org.ajax4jsf.resource.InternetResourceBase#getDataToStore(javax.faces.context.FacesContext,
java.lang.Object)
*/
protected Object getDataToStore(FacesContext context, Object data) {
- String additionalBackgroundColor = getSkinParameter(context,
- ADDITIONAL_BACKGROUND_COLOR);
- String selectControlColor = getSkinParameter(context,
- SELECT_CONTROL_COLOR);
- String panelBorderColor = getSkinParameter(context, PANEL_BORDER_COLOR);
- String generalTextColor = getSkinParameter(context, GENERAL_TEXT_COLOR);
+ Skin skin = SkinFactory.getInstance().getSkin(context);
+ Skin defaultSkin = SkinFactory.getInstance().getDefaultSkin(context);
+ String additionalBackgroundColor = getSkinParameter(skin, defaultSkin,
+ context, ADDITIONAL_BACKGROUND_COLOR);
+ String selectControlColor = getSkinParameter(skin, defaultSkin,
+ context, SELECT_CONTROL_COLOR);
+ String panelBorderColor = getSkinParameter(skin, defaultSkin, context,
+ PANEL_BORDER_COLOR);
+ String generalTextColor = getSkinParameter(skin, defaultSkin, context,
+ GENERAL_TEXT_COLOR);
+
byte[] ret = new byte[12];
Zipper2 zipper2 = new Zipper2(ret);
zipper2.addColor(HtmlColor.decode(additionalBackgroundColor).getRGB());
@@ -113,13 +118,13 @@
/**
* Method to get skin parameter value by parameter name
*
+ * @param skin - current component skin
+ * @param defaultSkin - default richfaces skin
* @param context - faces context instance
* @param parameterName - name of the skin parameter
* @return string value of parameter
*/
- private String getSkinParameter(FacesContext context, String parameterName) {
- Skin skin = SkinFactory.getInstance().getSkin(context);
- Skin defaultSkin = SkinFactory.getInstance().getDefaultSkin(context);
+ private String getSkinParameter(Skin skin, Skin defaultSkin, FacesContext context,
String parameterName) {
String value = (String) skin.getParameter(context, parameterName);
if (null == value || "".equals(value)) {
value = (String) defaultSkin.getParameter(context, parameterName);
Modified:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/component/EditorComponentTest.java
===================================================================
---
trunk/sandbox/ui/editor/src/test/java/org/richfaces/component/EditorComponentTest.java 2008-11-22
13:11:17 UTC (rev 11303)
+++
trunk/sandbox/ui/editor/src/test/java/org/richfaces/component/EditorComponentTest.java 2008-11-22
14:49:50 UTC (rev 11304)
@@ -20,13 +20,20 @@
*/
package org.richfaces.component;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
import javax.faces.component.UIForm;
import javax.faces.component.html.HtmlForm;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.commons.lang.StringUtils;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
/**
* Editor component Junit Test
@@ -34,43 +41,33 @@
*
*/
public class EditorComponentTest extends AbstractAjax4JsfTestCase {
-
+
+ /** UIForm instance */
UIForm form;
+ /** UIEditor instance */
UIEditor editor;
+
+ /** Set with required javascripts for Editor */
+ private static Set<String> javaScripts = new HashSet<String>();
- private final static String SEAM_TEXT_EXPRESSION_1 = "It's easy to make
*emphasis*, |monospace|,\n"
- + "~deleted text~, super^scripts^ or _underlines_.";
+ static {
+ javaScripts.add("org.ajax4jsf.javascript.PrototypeScript");
+ javaScripts.add("org.ajax4jsf.javascript.AjaxScript");
+ javaScripts.add("scripts/tiny_mce/tiny_mce_src.js");
+ javaScripts.add("scripts/editor.js");
+ }
- private final static String SEAM_TEXT_EXPRESSION_2 = "+This is a big
heading\n"
- + "You /must/ have some text following a heading!\n"
- + "++This is a smaller heading\n"
- + "This is the first paragraph. We can split it across multiple\n"
- + "lines, but we must end it with a blank line.\n"
- + "This is the second paragraph.";
-
- private final static String SEAM_TEXT_EXPRESSION_3 = "An ordered list:\n"
- + "\\#first item\n" + "\\#second item\n"
- + "\\#and even the /third/ item\n" + "An unordered list:\n"
- + "\\=an item\n" + "\\=another item\n";
-
- private final static String SEAM_TEXT_EXPRESSION_4 = "The other guy said:\n"
- + "\"Nyeah nyeah-nee\n"
- + "/nyeah/ nyeah!\"\n"
- + "But what do you think he means by \"nyeah-nee\"?";
-
- private final static String SEAM_TEXT_EXPRESSION_5 = "You can write down equations
like 2*3=6 and HTML tags\n"
- + "like <body> using the escape character: \\.";
-
- private final static String SEAM_TEXT_EXPRESSION_6 = "My code doesn't
work:\n"
- + "`for (int i=0; i<100; i--)\n"
- + "{\n"
- + "doSomething();\n"
- + "}`\n" + "Any ideas?";
-
+ /**
+ * Constructor with test name parameter
+ * @param name
+ */
public EditorComponentTest(String name) {
super(name);
}
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
public void setUp() throws Exception {
super.setUp();
form = new HtmlForm();
@@ -78,63 +75,89 @@
facesContext.getViewRoot().getChildren().add(form);
editor = (UIEditor) application.createComponent("org.richfaces.Editor");
+ editor.setId("editor");
+ editor.setValue("Some value");
form.getChildren().add(editor);
}
-
- public void testRenderer() throws Exception {
+
+ /**
+ * Method to test if required style is present on page
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testEditorStyles() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
+ List links = page.getDocumentHtmlElement().getHtmlElementsByTagName(
+ "link");
+ if (links.size() == 0) {
+ fail();
+ }
+ for (int i = 0; i < links.size(); i++) {
+ HtmlElement link = (HtmlElement) links.get(i);
+ assertTrue(link.getAttributeValue("href").contains(
+ "css/editor.xcss"));
+ }
}
+
+ /**
+ * Method to test if required scripts is present on page
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testEditorScripts() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List scripts = page.getDocumentHtmlElement().getHtmlElementsByTagName(
+ "script");
- public void testSeamTextConverting1() throws Exception {
- assertSeamConverting(SEAM_TEXT_EXPRESSION_1);
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ String srcAttr = item.getSrcAttribute();
+ if (item.getFirstDomChild() != null) {
+ String scriptBodyString = item.getFirstDomChild().toString();
+ assertTrue(scriptBodyString.contains("RichEditor"));
+ }
+ if (StringUtils.isNotBlank(srcAttr)) {
+ boolean found = false;
+ for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+ String src = (String) srcIt.next();
+ found = srcAttr.contains(src);
+ if (found) {
+ break;
+ }
+ }
+ assertTrue(found);
+ }
+ }
}
-
- public void testSeamTextConverting2() throws Exception {
- assertSeamConverting(SEAM_TEXT_EXPRESSION_2);
- }
-
- public void testSeamTextConverting3() throws Exception {
- assertSeamConverting(SEAM_TEXT_EXPRESSION_3);
- }
-
- public void testSeamTextConverting4() throws Exception {
- assertSeamConverting(SEAM_TEXT_EXPRESSION_4);
- }
-
- public void testSeamTextConverting5() throws Exception {
- assertSeamConverting(SEAM_TEXT_EXPRESSION_5);
- }
-
- public void testSeamTextConverting6() throws Exception {
- assertSeamConverting(SEAM_TEXT_EXPRESSION_6);
- }
-
+
/**
- * Method to assert converting from Seam Text to html and back
- * @param seamTextExpression
+ * Method to test Editor rendering
* @throws Exception
*/
- private void assertSeamConverting(String seamTextExpression)
- throws Exception {
- editor.setUseSeamText(true);
- editor.setValue(seamTextExpression);
-
+ public void testEditorRendering() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
-
- String convertedValue = null;
- HtmlElement component = page.getHtmlElementById(editor
+ HtmlElement htmlDiv = page.getHtmlElementById(editor
.getClientId(facesContext));
- convertedValue = component.getFirstDomChild().asText();
-
- editor.setSubmittedValue(convertedValue);
- editor.validate(facesContext);
-
- // TODO: Must be uncomented when html convertion to Seam Text will be implemented in
SeamTextConverter
- //assertEquals(seamTextExpression, editor.getValue().toString());
+ assertNotNull(htmlDiv);
+ assertEquals(htmlDiv.getTagName(), "div");
+ HtmlElement htmlTextArea = page.getHtmlElementById(editor
+ .getClientId(facesContext)
+ + UIEditor.EDITOR_TEXT_AREA_ID_SUFFIX);
+ assertNotNull(htmlTextArea);
+ assertEquals(htmlTextArea.getTagName(), "textarea");
+ String style = htmlTextArea.getAttribute("style");
+ assertNotNull(style);
+ assertTrue(style.contains("visibility: hidden"));
+ String value = htmlTextArea.getFirstDomChild().asText();
+ assertEquals("Some value", value);
}
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
public void tearDown() throws Exception {
super.tearDown();
}
Added:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/EditorRendererTest.java
===================================================================
--- trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/EditorRendererTest.java
(rev 0)
+++
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/EditorRendererTest.java 2008-11-22
14:49:50 UTC (rev 11304)
@@ -0,0 +1,259 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.richfaces.renderkit;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.faces.component.UIParameter;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIEditor;
+
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlScript;
+
+public class EditorRendererTest extends AbstractAjax4JsfTestCase {
+
+ /** Name of test property file with configuration parameters */
+ private final static String PARAMETERS_PROPERTY_FILE_NAME = "editorFull";
+ /** Name of test property file with custom plugins parameters */
+ private final static String CUSTOM_PLUGINS_PROPERTY_FILE_NAME = "myplugins";
+
+ /** Test f:param name */
+ private final static String FPARAM_NAME = "fparam_name";
+ /** Test f:param value */
+ private final static String FPARAM_VALUE = "fparam_value";
+
+ /** UIEditor instance */
+ private UIEditor editor;
+
+ /**
+ * Constructor with test name parameter
+ * @param name
+ */
+ public EditorRendererTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ editor = (UIEditor) application.createComponent("org.richfaces.Editor");
+ editor.setValue("Some value");
+
+ UIParameter param1 = (UIParameter) application
+ .createComponent("javax.faces.Parameter");
+ param1.setName(FPARAM_NAME);
+ param1.setValue(FPARAM_VALUE);
+ editor.getChildren().add(param1);
+
+ facesContext.getViewRoot().getChildren().add(editor);
+ }
+
+
+ /**
+ * Method to test EditorRenderer writing configuration script parameters
+ * from properties file.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testWritingScriptParametersFromProperties() throws Exception {
+
+ editor.setConfiguration(PARAMETERS_PROPERTY_FILE_NAME);
+ Properties parameters = loadProperties(PARAMETERS_PROPERTY_FILE_NAME);
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ List scripts = page.getDocumentHtmlElement().getHtmlElementsByTagName(
+ "script");
+
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ if (item.getFirstDomChild() != null) {
+ String scriptBodyString = item.getFirstDomChild().toString();
+ for (Object key : parameters.keySet()) {
+ String keyString = key.toString();
+ String valueString = (parameters.get(key)).toString();
+ if (valueString.indexOf("\"") != -1) {
+ valueString = valueString.replaceAll("\"", "");
+ }
+ assertTrue("writed script parameters not contains '"
+ + keyString + "'", scriptBodyString
+ .contains(keyString));
+ assertTrue("writed script parameters not contains '"
+ + valueString + "'", scriptBodyString
+ .contains(valueString));
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Method to test EditorRenderer writing configuration script parameters
+ * from f:params children.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testWritingScriptParametersFromFParams() throws Exception {
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ List scripts = page.getDocumentHtmlElement().getHtmlElementsByTagName(
+ "script");
+
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ if (item.getFirstDomChild() != null) {
+ String scriptBodyString = item.getFirstDomChild().toString();
+ assertTrue(
+ "writed script parameters not contains defined in Editor f:param",
+ scriptBodyString.contains(FPARAM_NAME));
+ assertTrue(
+ "writed script parameters not contains defined in Editor f:param",
+ scriptBodyString.contains(FPARAM_VALUE));
+ }
+
+ }
+
+ }
+
+ /**
+ * Method to test EditorRenderer writing configuration script parameters
+ * from UIEditor attributes.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testWritingScriptParametersFromAttributes() throws Exception {
+ editor.setAutoResize(true);
+ editor.setDialogType("window");
+ editor.setHeight(300);
+ editor.setWidth(300);
+ editor.setLanguage("ru");
+ editor.setPlugins("safari,spellchecker,pagebreak");
+ editor.setReadonly(true);
+ editor.setSkin("o2k7");
+ editor.setTheme("advanced");
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ List scripts = page.getDocumentHtmlElement().getHtmlElementsByTagName(
+ "script");
+
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ if (item.getFirstDomChild() != null) {
+ String scriptBodyString = item.getFirstDomChild().toString();
+ assertTrue(scriptBodyString
+ .contains("tinyMceParams.auto_resize = true"));
+ assertTrue(scriptBodyString
+ .contains("tinyMceParams.dialog_type ="));
+ assertTrue(scriptBodyString.contains(editor.getDialogType()));
+ assertTrue(scriptBodyString
+ .contains("tinyMceParams.width = 300"));
+ assertTrue(scriptBodyString
+ .contains("tinyMceParams.height = 300"));
+ assertTrue(scriptBodyString
+ .contains("tinyMceParams.language ="));
+ assertTrue(scriptBodyString.contains(editor.getLanguage()));
+ assertTrue(scriptBodyString.contains("tinyMceParams.plugins ="));
+ assertTrue(scriptBodyString.contains(editor.getPlugins()));
+ assertTrue(scriptBodyString.contains("tinyMceParams.theme ="));
+ assertTrue(scriptBodyString.contains(editor.getTheme()));
+ assertTrue(scriptBodyString.contains("tinyMceParams.skin ="));
+ assertTrue(scriptBodyString.contains(editor.getSkin()));
+ assertTrue(scriptBodyString
+ .contains("tinyMceParams.readonly = true"));
+ }
+
+ }
+
+ }
+
+ /**
+ * Method to test EditorRenderer writing custom plugins loading calls from
+ * properties file.
+ *
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public void testWritingScriptParametersForCustomPlugins() throws Exception {
+
+ editor.setCustomPlugins(CUSTOM_PLUGINS_PROPERTY_FILE_NAME);
+ Properties parameters = loadProperties(CUSTOM_PLUGINS_PROPERTY_FILE_NAME);
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ List scripts = page.getDocumentHtmlElement().getHtmlElementsByTagName(
+ "script");
+
+ for (Iterator it = scripts.iterator(); it.hasNext();) {
+ HtmlScript item = (HtmlScript) it.next();
+ if (item.getFirstDomChild() != null) {
+ String scriptBodyString = item.getFirstDomChild().toString();
+ for (Object key : parameters.keySet()) {
+ String keyString = key.toString();
+ String valueString = (parameters.get(key)).toString();
+ if (valueString.indexOf("\"") != -1) {
+ valueString = valueString.replaceAll("\"", "");
+ }
+ assertTrue(scriptBodyString.contains("tinymce.PluginManager.load("));
+ assertTrue(scriptBodyString.contains(keyString));
+ assertTrue(scriptBodyString.contains(valueString));
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Method to load properties from property file
+ *
+ * @param name - properties file name
+ * @return Properties
+ * @throws IOException
+ */
+ private Properties loadProperties(String name) throws IOException {
+ Properties properties = new Properties();
+
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ InputStream is = loader.getResourceAsStream(name + ".properties");
+ if (is == null) {
+ fail("Can't load propertioes file for test");
+ }
+ properties.load(is);
+ return properties;
+ }
+
+}
Property changes on:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/EditorRendererTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/html/images/EditorIconTest.java
===================================================================
---
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/html/images/EditorIconTest.java
(rev 0)
+++
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/html/images/EditorIconTest.java 2008-11-22
14:49:50 UTC (rev 11304)
@@ -0,0 +1,114 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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.richfaces.renderkit.html.images;
+
+import java.awt.Color;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.util.HtmlColor;
+import org.richfaces.renderkit.html.images.EditorAdvancedThemeIcons;
+import org.richfaces.renderkit.html.images.EditorIcons;
+import org.richfaces.renderkit.html.images.EditorSimpleThemeIcons;
+import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
+
+/**
+ * Editor icon images resource classes test
+ *
+ * @author Alexandr Levkovsky
+ *
+ */
+public class EditorIconTest extends AbstractAjax4JsfTestCase{
+
+ public EditorIconTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Method to test resource classes saving of parameters functionality
+ */
+ public void testSaveResources(){
+
+ EditorAdvancedThemeIcons advIcon = new EditorAdvancedThemeIcons();
+ EditorSimpleThemeIcons simpleIcon = new EditorSimpleThemeIcons();
+
+ Skin skin = SkinFactory.getInstance().getSkin(facesContext);
+ Skin defaultSkin = SkinFactory.getInstance().getDefaultSkin(facesContext);
+
+ String additionalBackgroundColor = getSkinParameter(skin, defaultSkin, facesContext,
EditorIcons.ADDITIONAL_BACKGROUND_COLOR);
+ String selectControlColor = getSkinParameter(skin, defaultSkin, facesContext,
+ EditorIcons.SELECT_CONTROL_COLOR);
+ String panelBorderColor = getSkinParameter(skin, defaultSkin, facesContext,
EditorIcons.PANEL_BORDER_COLOR);
+ String generalTextColor = getSkinParameter(skin, defaultSkin, facesContext,
EditorIcons.GENERAL_TEXT_COLOR);
+
+ assertNotNull(additionalBackgroundColor);
+ assertNotNull(selectControlColor);
+ assertNotNull(panelBorderColor);
+ assertNotNull(generalTextColor);
+
+ Color color1 = HtmlColor.decode(additionalBackgroundColor);
+ Color color2 = HtmlColor.decode(selectControlColor);
+ Color color3 = HtmlColor.decode(panelBorderColor);
+ Color color4 = HtmlColor.decode(generalTextColor);
+
+ byte [] data = (byte []) advIcon.getDataToStore(facesContext, null);
+
+ assertNotNull(data);
+ Object [] results = (Object [])advIcon.deserializeData(data);
+ assertNotNull(results);
+
+ assertEquals(color1, results[0]);
+ assertEquals(color2, results[1]);
+ assertEquals(color3, results[2]);
+ assertEquals(color4, results[3]);
+
+ data = (byte []) simpleIcon.getDataToStore(facesContext, null);
+
+ assertNotNull(data);
+ results = (Object [])simpleIcon.deserializeData(data);
+ assertNotNull(results);
+
+ assertEquals(color1, results[0]);
+ assertEquals(color2, results[1]);
+ assertEquals(color3, results[2]);
+ assertEquals(color4, results[3]);
+ }
+
+ /**
+ * Method to get skin parameter value by parameter name
+ *
+ * @param skin - current component skin
+ * @param defaultSkin - default richfaces skin
+ * @param context - faces context instance
+ * @param parameterName - name of the skin parameter
+ * @return string value of parameter
+ */
+ private String getSkinParameter(Skin skin, Skin defaultSkin, FacesContext context,
String parameterName) {
+ String value = (String) skin.getParameter(context, parameterName);
+ if (null == value || "".equals(value)) {
+ value = (String) defaultSkin.getParameter(context, parameterName);
+ }
+ return value;
+
+ }
+}
Property changes on:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/renderkit/html/images/EditorIconTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/sandbox/ui/editor/src/test/resources/editorFull.properties
===================================================================
--- trunk/sandbox/ui/editor/src/test/resources/editorFull.properties
(rev 0)
+++ trunk/sandbox/ui/editor/src/test/resources/editorFull.properties 2008-11-22 14:49:50
UTC (rev 11304)
@@ -0,0 +1,10 @@
+plugins =
"safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template"
+theme_advanced_buttons1 =
"save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect"
+theme_advanced_buttons2 =
"cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor"
+theme_advanced_buttons3 =
"tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen"
+theme_advanced_buttons4 =
"insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak"
+theme_advanced_buttons5 = "|,myemotions,|"
+theme_advanced_toolbar_location = "top"
+theme_advanced_toolbar_align = "left"
+theme_advanced_statusbar_location = "bottom"
+theme_advanced_resizing = true
\ No newline at end of file
Property changes on: trunk/sandbox/ui/editor/src/test/resources/editorFull.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/sandbox/ui/editor/src/test/resources/myplugins.properties
===================================================================
--- trunk/sandbox/ui/editor/src/test/resources/myplugins.properties
(rev 0)
+++ trunk/sandbox/ui/editor/src/test/resources/myplugins.properties 2008-11-22 14:49:50
UTC (rev 11304)
@@ -0,0 +1 @@
+myemotions=/tiny-custom-plugins/myemotions/editor_plugin.js
\ No newline at end of file
Property changes on: trunk/sandbox/ui/editor/src/test/resources/myplugins.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native