Author: A.Skokov
Date: 2007-05-14 05:08:21 -0400 (Mon, 14 May 2007)
New Revision: 742
Modified:
trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component/InputNumberSliderComponentTest.java
Log:
tests fixed
Modified:
trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component/InputNumberSliderComponentTest.java
===================================================================
---
trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component/InputNumberSliderComponentTest.java 2007-05-14
09:06:57 UTC (rev 741)
+++
trunk/richfaces/inputnumber-slider/src/test/java/org/richfaces/component/InputNumberSliderComponentTest.java 2007-05-14
09:08:21 UTC (rev 742)
@@ -21,24 +21,9 @@
package org.richfaces.component;
-import java.awt.Dimension;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import javax.faces.component.UICommand;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIForm;
-import javax.faces.component.UIViewRoot;
-import javax.faces.component.html.HtmlCommandLink;
-import javax.faces.component.html.HtmlForm;
-import javax.faces.context.FacesContext;
-import javax.faces.el.EvaluationException;
-import javax.faces.el.PropertyNotFoundException;
-import javax.faces.el.ValueBinding;
-import javax.servlet.http.HttpServletResponse;
-
+import com.gargoylesoftware.htmlunit.KeyValuePair;
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.html.*;
import org.ajax4jsf.framework.resource.InternetResource;
import org.ajax4jsf.framework.resource.InternetResourceBuilder;
import org.ajax4jsf.framework.resource.Java2Dresource;
@@ -51,18 +36,23 @@
import org.richfaces.renderkit.html.images.SliderFieldGradient;
import org.richfaces.renderkit.html.images.SliderTrackGradient;
-import com.gargoylesoftware.htmlunit.KeyValuePair;
-import com.gargoylesoftware.htmlunit.Page;
-import com.gargoylesoftware.htmlunit.html.DomNode;
-import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
-import com.gargoylesoftware.htmlunit.html.HtmlElement;
-import com.gargoylesoftware.htmlunit.html.HtmlInput;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.gargoylesoftware.htmlunit.html.HtmlScript;
+import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.html.HtmlCommandLink;
+import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.*;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
-/**
- * Unit test for simple Component.
- */
+/** Unit test for simple Component. */
public class InputNumberSliderComponentTest extends AbstractAjax4JsfTestCase {
private UIForm form = null;
@@ -71,108 +61,128 @@
private static Set javaScripts = new HashSet();
/**
- * Create the test case
- *
- * @param testName
- * name of the test case
- */
-
+ * Create the test case
+ *
+ * @param testName
+ * name of the test case
+ */
+
static {
- javaScripts.add("prototype.js");
+ javaScripts.add("org.ajax4jsf.framework.resource.PrototypeScript");
javaScripts.add("org.ajax4jsf.framework.ajax.AjaxScript");
-
javaScripts.add("org/richfaces/renderkit/html/script/SliderScript.js");
+ javaScripts.add("script/SliderScript.js");
javaScripts.add("org/richfaces/renderkit/html/scripts/browser_info.js");
javaScripts.add("org/richfaces/renderkit/html/scripts/events.js");
}
-
+
public InputNumberSliderComponentTest(String testName) {
- super(testName);
+ super(testName);
}
public void setUp() throws Exception {
- super.setUp();
+ super.setUp();
- form = new HtmlForm();
- facesContext.getViewRoot().getChildren().add(form);
+ form = new HtmlForm();
+ facesContext.getViewRoot().getChildren().add(form);
- command = new HtmlCommandLink();
- command.setId("command");
- form.getChildren().add(command);
-
- slider = application.createComponent(UIInputNumberSlider.COMPONENT_TYPE);
- slider.setId("slider");
- form.getChildren().add(slider);
+ command = new HtmlCommandLink();
+ command.setId("command");
+ form.getChildren().add(command);
+
+ slider = application.createComponent(
+ UIInputNumberSlider.COMPONENT_TYPE);
+ slider.setId("slider");
+ form.getChildren().add(slider);
}
public void tearDown() throws Exception {
- super.tearDown();
- this.form = null;
- this.slider = null;
- this.command = null;
+ super.tearDown();
+ this.form = null;
+ this.slider = null;
+ this.command = null;
}
/**
* Test component renders correctly
- *
+ *
* @throws Exception
*/
public void testComponent() throws Exception {
- HtmlPage renderedView = renderView();
+ HtmlPage renderedView = renderView();
- HtmlElement htmlSlider =
renderedView.getHtmlElementById(slider.getClientId(facesContext));
+ HtmlElement htmlSlider = renderedView.getHtmlElementById(
+ slider.getClientId(facesContext));
- assertNotNull(htmlSlider);
+ assertNotNull(htmlSlider);
- assertTrue(htmlSlider.getAttributeValue("class").contains("rich-slider"));
-
- HtmlInput htmlSliderInput = (HtmlInput)
renderedView.getHtmlElementById(slider.getClientId(facesContext) + "Input");
-
- assertNotNull(htmlSliderInput);
-
- assertTrue(htmlSliderInput.getClassAttribute().contains("dr-insldr-field
rich-inslider-field"));
- assertTrue(htmlSliderInput.getTypeAttribute().equals("text"));
-
- DomNode numContainer = htmlSliderInput.getParentNode().getPreviousSibling();
- assertTrue(((HtmlElement)numContainer).getAttributeValue("class").contains("dr-insldr-right-num
rich-inslider-right-num"));
- assertTrue(((HtmlElement)(numContainer.getPreviousSibling())).getAttributeValue("class").contains("dr-insldr-left-num
rich-inslider-left-num"));
-
- HtmlElement tip = renderedView.getHtmlElementById(slider.getClientId(facesContext) +
"Tip");
- assertTrue(tip.getAttributeValue("class").contains("dr-insldr-tip
rich-inslider-tip"));
-
- HtmlElement handle = renderedView.getHtmlElementById(slider.getClientId(facesContext) +
"Handle");
- assertTrue(handle.getAttributeValue("class").contains("dr-insldr-handler
rich-inslider-handler"));
-
- HtmlElement track = (HtmlElement)tip.getParentNode().getNextSibling();
- assertTrue(track.getAttributeValue("class").contains("dr-insldr-track
rich-inslider-track"));
+ assertTrue(htmlSlider.getAttributeValue("class").contains(
+ "rich-slider"));
+
+ HtmlInput htmlSliderInput = (HtmlInput) renderedView.getHtmlElementById(
+ slider.getClientId(facesContext) + "Input");
+
+ assertNotNull(htmlSliderInput);
+
+ assertTrue(htmlSliderInput.getClassAttribute().contains(
+ "dr-insldr-field rich-inslider-field"));
+ assertTrue(htmlSliderInput.getTypeAttribute().equals("text"));
+
+ DomNode numContainer = htmlSliderInput.getParentNode()
+ .getPreviousSibling();
+ assertTrue(((HtmlElement) numContainer).getAttributeValue(
+ "class").contains(
+ "dr-insldr-right-num rich-inslider-right-num"));
+ assertTrue(((HtmlElement) (numContainer.getPreviousSibling()))
+ .getAttributeValue("class").contains(
+ "dr-insldr-left-num rich-inslider-left-num"));
+
+ HtmlElement tip = renderedView.getHtmlElementById(slider.getClientId(
+ facesContext) + "Tip");
+ assertTrue(tip.getAttributeValue("class").contains(
+ "dr-insldr-tip rich-inslider-tip"));
+
+ HtmlElement handle = renderedView.getHtmlElementById(slider.getClientId(
+ facesContext) + "Handle");
+ assertTrue(handle.getAttributeValue("class").contains(
+ "dr-insldr-handler rich-inslider-handler"));
+
+ HtmlElement track = (HtmlElement) tip.getParentNode().getNextSibling();
+ assertTrue(track.getAttributeValue("class").contains(
+ "dr-insldr-track rich-inslider-track"));
}
-
+
public void testHiddenInput() throws Exception {
- slider.getAttributes().put("showInput",Boolean.FALSE);
- HtmlPage renderedView = renderView();
- HtmlInput htmlSliderInput = (HtmlInput)
renderedView.getHtmlElementById(slider.getClientId(facesContext) + "Input");
- assertTrue(htmlSliderInput.getTypeAttribute().equals("hidden"));
+ slider.getAttributes().put("showInput", Boolean.FALSE);
+ HtmlPage renderedView = renderView();
+ HtmlInput htmlSliderInput = (HtmlInput) renderedView.getHtmlElementById(
+ slider.getClientId(facesContext) + "Input");
+ assertTrue(htmlSliderInput.getTypeAttribute().equals("hidden"));
}
-
+
public void testRenderStyle() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
+ //System.out.println(page.asXml());
List links =
page.getDocumentElement().getHtmlElementsByTagName("link");
assertEquals(1, links.size());
HtmlElement link = (HtmlElement) links.get(0);
-
assertTrue(link.getAttributeValue("href").contains("org/richfaces/renderkit/html/css/slider.xcss"));
+
assertTrue(link.getAttributeValue("href").contains("css/slider.xcss"));
}
-
+
public void testRenderScript() throws Exception {
HtmlPage page = renderView();
assertNotNull(page);
- List scripts =
page.getDocumentElement().getHtmlElementsByTagName("script");
+ //System.out.println(page.asXml());
+ List scripts = page.getDocumentElement().getHtmlElementsByTagName(
+ "script");
for (Iterator it = scripts.iterator(); it.hasNext();) {
HtmlScript item = (HtmlScript) it.next();
String srcAttr = item.getSrcAttribute();
if (StringUtils.isNotBlank(srcAttr)) {
boolean found = false;
- for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();) {
+ for (Iterator srcIt = javaScripts.iterator(); srcIt.hasNext();)
+ {
String src = (String) srcIt.next();
found = srcAttr.contains(src);
@@ -185,148 +195,176 @@
}
}
}
-
+
public void testImages() throws Exception {
- InternetResource image = InternetResourceBuilder.getInstance().createResource(null,
SliderFieldGradient.class.getName());
- Dimension imageDim = ((Java2Dresource)image).getDimensions(facesContext, null);
- assertTrue( imageDim.getWidth() == 31 && imageDim.getHeight() == 55);
-
- image = InternetResourceBuilder.getInstance().createResource(null,
SliderTrackGradient.class.getName());
- imageDim = ((Java2Dresource)image).getDimensions(facesContext, null);
- assertTrue( imageDim.getWidth() == 7 && imageDim.getHeight() == 10);
+ InternetResource image = InternetResourceBuilder.getInstance()
+ .createResource(null, SliderFieldGradient.class.getName());
+ Dimension imageDim = ((Java2Dresource) image).getDimensions(
+ facesContext, null);
+ assertTrue(imageDim.getWidth() == 31 && imageDim.getHeight() == 55);
- image = InternetResourceBuilder.getInstance().createResource(null,
SliderArrowImage.class.getName());
- imageDim = ((Java2Dresource)image).getDimensions(facesContext, null);
- assertTrue( imageDim.getWidth() == 7 && imageDim.getHeight() == 8);
+ image = InternetResourceBuilder.getInstance().createResource(null,
+ SliderTrackGradient.class.getName());
+ imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
+ assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 10);
- image = InternetResourceBuilder.getInstance().createResource(null,
SliderArrowSelectedImage.class.getName());
- imageDim = ((Java2Dresource)image).getDimensions(facesContext, null);
- assertTrue( imageDim.getWidth() == 7 && imageDim.getHeight() == 8);
+ image = InternetResourceBuilder.getInstance().createResource(null,
+ SliderArrowImage.class.getName());
+ imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
+ assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 8);
+
+ image = InternetResourceBuilder.getInstance().createResource(null,
+ SliderArrowSelectedImage.class.getName());
+ imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
+ assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 8);
}
-
+
public void testRenderImages() throws Exception {
- renderView();
- InternetResourceBuilder builder = ResourceBuilderImpl.getInstance();
- InternetResource resource =
builder.getResource("org/richfaces/renderkit/html/css/slider.xcss");
- assertNotNull(resource);
- String uri = "http:" + resource.getUri(facesContext, null);
- Page page = webClient.getPage(uri);
- assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
+ renderView();
+ InternetResourceBuilder builder = ResourceBuilderImpl.getInstance();
+ InternetResource resource = builder.getResource("css/slider.xcss");
+ assertNotNull(resource);
+ String uri = "http:" + resource.getUri(facesContext, null);
+ Page page = webClient.getPage(uri);
+ assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse
+ .SC_OK);
- String[] resources = new String[] {
- SliderArrowImage.class.getName(),
- SliderArrowSelectedImage.class.getName(),
- SliderFieldGradient.class.getName(),
- SliderTrackGradient.class.getName()
- };
-
- for (int i = 0; i < resources.length; i++) {
- resource = builder.getResource(resources[i]);
- assertNotNull(resource);
- uri = "http:" + resource.getUri(facesContext, null);
- page = webClient.getPage(uri);
- assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
- ImageInfo info = new ImageInfo();
- info.setInput(page.getWebResponse().getContentAsStream());
- //image recognizable?
- assertTrue(info.check());
- assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
- }
+ String[] resources = new String[]{
+ SliderArrowImage.class.getName(),
+ SliderArrowSelectedImage.class.getName(),
+ SliderFieldGradient.class.getName(),
+ SliderTrackGradient.class.getName()
+ };
+
+ for (int i = 0; i < resources.length; i++) {
+ resource = builder.getResource(resources[i]);
+ assertNotNull(resource);
+ uri = "http:" + resource.getUri(facesContext, null);
+ page = webClient.getPage(uri);
+ assertTrue(page.getWebResponse().getStatusCode()
+ == HttpServletResponse.SC_OK);
+ ImageInfo info = new ImageInfo();
+ info.setInput(page.getWebResponse().getContentAsStream());
+ //image recognizable?
+ assertTrue(info.check());
+ assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
+ }
}
-
+
public void testUpdate() throws Exception {
- //tests if component handles value bindings correctly
- HtmlPage renderedView = renderView();
-
- String value = "66";
-
- HtmlInput htmlSliderInput = (HtmlInput)
renderedView.getHtmlElementById(slider.getClientId(facesContext) + "Input");
- htmlSliderInput.setValueAttribute(value);
-
- HtmlAnchor htmlLink = (HtmlAnchor)
renderedView.getHtmlElementById(command.getClientId(facesContext));
- htmlLink.click();
+ //tests if component handles value bindings correctly
+ HtmlPage renderedView = renderView();
- List lastParameters = this.webConnection.getLastParameters();
- for (Iterator iterator = lastParameters.iterator(); iterator.hasNext();) {
- KeyValuePair keyValue = (KeyValuePair) iterator.next();
-
- externalContext.addRequestParameterMap((String) keyValue.getKey(), (String)
keyValue.getValue());
- }
+ String value = "66";
- UIViewRoot root = facesContext.getViewRoot();
- root.processDecodes(facesContext);
- root.processValidators(facesContext);
- root.processUpdates(facesContext);
- root.processApplication(facesContext);
-
- renderedView = renderView();
- assertTrue( value.equals(((UIInputNumberSlider)slider).getValue()) );
+ HtmlInput htmlSliderInput = (HtmlInput) renderedView.getHtmlElementById(
+ slider.getClientId(facesContext) + "Input");
+ htmlSliderInput.setValueAttribute(value);
+
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(
+ command.getClientId(facesContext));
+ htmlLink.click();
+
+ List lastParameters = this.webConnection.getLastParameters();
+ for (Iterator iterator = lastParameters.iterator(); iterator.hasNext();)
+ {
+ KeyValuePair keyValue = (KeyValuePair) iterator.next();
+
+ externalContext.addRequestParameterMap((String) keyValue.getKey(),
+ (String) keyValue.getValue());
+ }
+ externalContext.addRequestParameterMap(slider.getClientId(facesContext),
+ value);
+
+ slider.processDecodes(facesContext);
+ slider.processValidators(facesContext);
+ slider.processUpdates(facesContext);
+
+ renderedView = renderView();
+ assertTrue(value.equals(((UIInputNumberSlider) slider).getValue()));
}
-
- public void testDecode() throws Exception{
- //Tests if component accepts request parameters and stores them in submittedValue().
- //If component is immediate, validation (possibly with conversion) should occur on that
phase.
- final SliderBean bean = new SliderBean();
- ((UIInputNumberSlider)slider).setValueBinding("value",
- new ValueBinding() {
- public Class getType(FacesContext context) throws EvaluationException,
PropertyNotFoundException {
- return String.class;
- }
- public Object getValue(FacesContext context) throws EvaluationException,
PropertyNotFoundException {
- return bean.getValue();
- }
- public boolean isReadOnly(FacesContext context) throws EvaluationException,
PropertyNotFoundException {
- return false;
- }
- public void setValue(FacesContext context, Object value) throws EvaluationException,
PropertyNotFoundException {
- bean.setValue((String)value);
- }
- });
- HtmlPage renderedView = renderView();
- HtmlAnchor htmlLink = (HtmlAnchor)
renderedView.getHtmlElementById(command.getClientId(facesContext));
- htmlLink.click();
-
externalContext.addRequestParameterMap(slider.getClientId(facesContext),"66");
- slider.processDecodes(facesContext);
- assertTrue(bean.getValue().equals("66"));
-
- ((UIInputNumberSlider)slider).setImmediate(true);
- renderedView = renderView();
- htmlLink = (HtmlAnchor)
renderedView.getHtmlElementById(command.getClientId(facesContext));
- htmlLink.click();
- externalContext.addRequestParameterMap(slider.getClientId(facesContext),"wrong
value");
- slider.processDecodes(facesContext);
- assertTrue(facesContext.getMessages().hasNext());
+
+ public void testDecode() throws Exception {
+ //Tests if component accepts request parameters and stores them in
submittedValue().
+ //If component is immediate, validation (possibly with conversion) should occur
on that phase.
+ final SliderBean bean = new SliderBean();
+ ((UIInputNumberSlider) slider).setValueBinding("value",
+ new ValueBinding() {
+ public Class getType(FacesContext context) throws
+ EvaluationException,
+ PropertyNotFoundException
{
+ return String.class;
+ }
+
+ public Object getValue(FacesContext context) throws
+ EvaluationException,
+
PropertyNotFoundException {
+ return bean.getValue();
+ }
+
+ public boolean isReadOnly(FacesContext context) throws
+ EvaluationException,
+
PropertyNotFoundException {
+ return false;
+ }
+
+ public void setValue(FacesContext context, Object value)
+ throws EvaluationException,
+ PropertyNotFoundException {
+ bean.setValue((String) value);
+ }
+ });
+ HtmlPage renderedView = renderView();
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(
+ command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(slider.getClientId(facesContext),
+ "66");
+ slider.processDecodes(facesContext);
+ assertTrue(bean.getValue().equals("66"));
+
+ ((UIInputNumberSlider) slider).setImmediate(true);
+ renderedView = renderView();
+ htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(
+ command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(slider.getClientId(facesContext),
+ "wrong value");
+ slider.processDecodes(facesContext);
+ assertTrue(facesContext.getMessages().hasNext());
}
-
- public void testValidate() throws Exception{
- HtmlPage renderedView = renderView();
- HtmlAnchor htmlLink = (HtmlAnchor)
renderedView.getHtmlElementById(command.getClientId(facesContext));
- htmlLink.click();
- externalContext.addRequestParameterMap(slider.getClientId(facesContext),"wrong
value");
- slider.processDecodes(facesContext);
- slider.processValidators(facesContext);
-
- assertTrue(facesContext.getMessages().hasNext());
-
+ public void testValidate() throws Exception {
+ HtmlPage renderedView = renderView();
+
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(
+ command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(slider.getClientId(facesContext),
+ "wrong value");
+ slider.processDecodes(facesContext);
+ slider.processValidators(facesContext);
+
+ assertTrue(facesContext.getMessages().hasNext());
+
}
-
- private class SliderBean {
-
- private String value;
-
- SliderBean (){
- this.value = "66";
- }
- public String getValue() {
- return value;
- }
+ private class SliderBean {
- public void setValue(String value) {
- this.value = value;
- }
-
+ private String value;
+
+ SliderBean() {
+ this.value = "66";
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
}
-
+
}
\ No newline at end of file