Author: sergeyhalipov
Date: 2007-12-10 10:56:23 -0500 (Mon, 10 Dec 2007)
New Revision: 4661
Modified:
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/component/OrderingListComponentTest.java
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/renderkit/OrderingListRenderingTest.java
Log:
Tests for ordering list was changed.
Modified:
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/component/OrderingListComponentTest.java
===================================================================
---
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/component/OrderingListComponentTest.java 2007-12-10
15:17:50 UTC (rev 4660)
+++
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/component/OrderingListComponentTest.java 2007-12-10
15:56:23 UTC (rev 4661)
@@ -61,7 +61,7 @@
private UIForm form = null;
private UIOrderingList orderingList = null;
- private OrderingListBean bean = null;
+ private List valueList = null;
private UICommand command = null;
private UIOrderingList orderingList2 = null;
@@ -78,7 +78,9 @@
command.setId("command");
form.getChildren().add(command);
- bean = new OrderingListBean();
+ valueList = new ArrayList();
+ valueList.add("1");
+ valueList.add("2");
orderingList =
(UIOrderingList)application.createComponent("org.richfaces.OrderingList");
orderingList.setControlsType("link");
@@ -87,12 +89,12 @@
public Class getType(FacesContext arg0) throws EvaluationException,
PropertyNotFoundException {
- return String.class;
+ return List.class;
}
public Object getValue(FacesContext arg0)
throws EvaluationException, PropertyNotFoundException {
- return bean.getValue();
+ return valueList;
}
public boolean isReadOnly(FacesContext arg0)
@@ -103,18 +105,27 @@
public void setValue(FacesContext arg0, Object arg1)
throws EvaluationException, PropertyNotFoundException {
assertTrue(arg1 instanceof List);
- bean.setValue((List)arg1);
+ valueList = (List)arg1;
}
});
+ orderingList.addValidator(new Validator() {
+
+ public void validate(FacesContext arg0, UIComponent arg1,
+ Object arg2) throws ValidatorException {
+ // Fake validator.
+ }
+
+ });
+
form.getChildren().add(orderingList);
orderingList2 =
(UIOrderingList)application.createComponent("org.richfaces.OrderingList");
}
public void tearDown() throws Exception {
- bean = null;
+ valueList = null;
orderingList = null;
orderingList2 = null;
command = null;
@@ -135,18 +146,15 @@
HtmlAnchor anchor =
(HtmlAnchor)page.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
anchor.click();
- externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"1sa,0");
+ externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"sa1:2");
+ externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"0:1");
orderingList.processDecodes(facesContext);
Object submittedValue = orderingList.getSubmittedValue();
assertNotNull(submittedValue);
- assertTrue(submittedValue instanceof Object[]);
- assertEquals(2, ((Object[])submittedValue).length);
+ assertTrue(submittedValue instanceof UIOrderingList.SubmittedValue);
+ UIOrderingList.SubmittedValue sValue = (UIOrderingList.SubmittedValue)
submittedValue;
+ assertFalse(sValue.isNull());
- Object valueHolder = ((Object[])submittedValue)[0];
- assertNotNull(valueHolder);
- assertTrue(valueHolder instanceof UIOrderingList.SubmittedValue);
- assertEquals("1sa,0", valueHolder.toString());
-
orderingList.setImmediate(true);
orderingList.addValidator(new Validator() {
@@ -162,7 +170,8 @@
page = renderView();
anchor =
(HtmlAnchor)page.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
anchor.click();
- externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"1sa,0");
+ externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"sa1:2");
+ externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"0:1");
orderingList.processDecodes(facesContext);
assertTrue(facesContext.getMessages().hasNext());
}
@@ -178,16 +187,16 @@
HtmlAnchor anchor =
(HtmlAnchor)page.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
anchor.click();
- externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"1sa,0");
+ externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"sa1:2");
+ externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"0:1");
orderingList.processDecodes(facesContext);
orderingList.processValidators(facesContext);
orderingList.processUpdates(facesContext);
- List newValue = bean.getValue();
- assertNotNull(newValue);
- assertEquals(2, newValue.size());
- assertEquals(newValue.get(0), "2");
- assertEquals(newValue.get(1), "1");
+ assertNotNull(valueList);
+ assertEquals(2, valueList.size());
+ assertEquals("2", valueList.get(0));
+ assertEquals("1", valueList.get(1));
}
/**
@@ -212,24 +221,21 @@
HtmlAnchor anchor =
(HtmlAnchor)page.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
anchor.click();
- externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"1sa,0");
+ externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"sa1:2");
+ externalContext.addRequestParameterMap(orderingList.getClientId(facesContext),
"0:1");
orderingList.processDecodes(facesContext);
orderingList.processValidators(facesContext);
assertTrue(facesContext.getMessages().hasNext());
Object submittedValue = orderingList.getSubmittedValue();
assertNotNull(submittedValue);
- assertTrue(submittedValue instanceof Object[]);
- assertEquals(2, ((Object[])submittedValue).length);
-
- Object valueHolder = ((Object[])submittedValue)[0];
- assertNotNull(valueHolder);
- assertTrue(valueHolder instanceof UIOrderingList.SubmittedValue);
- assertEquals("1sa,0", valueHolder.toString());
+ assertTrue(submittedValue instanceof UIOrderingList.SubmittedValue);
+ assertFalse(((UIOrderingList.SubmittedValue)submittedValue).isNull());
}
public void testSaveRestore() throws Exception {
- String [] value = new String [] {"1"};
+ List value = new ArrayList();
+ value.add("1");
orderingList.setValueBinding("value", null);
orderingList.setValue(value);
assertEquals(value, orderingList.getValue());
@@ -243,21 +249,4 @@
assertEquals(value, value2);
}
- protected class OrderingListBean {
- private List value = null;
-
- public OrderingListBean() {
- value = new ArrayList();
- value.add("1");
- value.add("2");
- }
-
- public List getValue() {
- return value;
- }
-
- public void setValue(List value) {
- this.value = value;
- }
- }
}
Modified:
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/renderkit/OrderingListRenderingTest.java
===================================================================
---
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/renderkit/OrderingListRenderingTest.java 2007-12-10
15:17:50 UTC (rev 4660)
+++
branches/3.1.x/ui/orderingList/src/test/java/org/richfaces/renderkit/OrderingListRenderingTest.java 2007-12-10
15:56:23 UTC (rev 4661)
@@ -61,6 +61,7 @@
javaScripts.add("scripts/LayoutManager.js");
javaScripts.add("scripts/Control.js");
javaScripts.add("scripts/OrderingList.js");
+ javaScripts.add("scripts/ListBase.js");
imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconUp");
imageClasses.add("org.richfaces.renderkit.html.images.OrderingListIconDown");
@@ -85,6 +86,8 @@
super( testName );
}
+ private final static int ROWS_COUNT = 3;
+
private UIForm form = null;
private UIOrderingList orderingList = null;
private List items = null;
@@ -235,11 +238,12 @@
public void testRenderControls() throws Exception {
HtmlPage view = renderView();
assertNotNull(view);
+ System.out.println(view.asXml());
List images =
view.getDocumentElement().getHtmlElementsByTagName("img");
assertNotNull(images);
- assertEquals(8, images.size());
+ int generatedCount = 0;
for (Iterator it = images.iterator(); it.hasNext(); ) {
HtmlElement img = (HtmlElement) it.next();
assertNotNull(img);
@@ -249,21 +253,40 @@
assertNotNull(page);
assertTrue(page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK);
- HtmlElement div = (HtmlElement) img.getParentNode();
- assertNotNull(div);
- assertEquals("div", div.getNodeName());
+ if (uri.contains("spacer.gif")) {
+ continue;
+ }
+ generatedCount++;
- div = (HtmlElement) div.getParentNode();
- assertNotNull(div);
- assertEquals("div", div.getNodeName());
+ HtmlElement element = (HtmlElement) img.getParentNode();
+ assertNotNull(element);
+ assertEquals("div", element.getNodeName());
+ String clazz = element.getAttributeValue("class");
+ assertNotNull(clazz);
+ assertTrue("rich-ordering-list-button-content".equals(clazz));
- div = (HtmlElement) div.getParentNode();
- assertNotNull(div);
- assertEquals("div", div.getNodeName());
- String clazz = div.getAttributeValue("class");
+ element = (HtmlElement) element.getParentNode();
+ assertNotNull(element);
+ assertEquals("a", element.getNodeName());
+ String href = element.getAttributeValue("href");
+ assertNotNull(href);
+ assertTrue("#".equals(href));
+
+ element = (HtmlElement) element.getParentNode();
+ assertNotNull(element);
+ assertEquals("div", element.getNodeName());
+ clazz = element.getAttributeValue("class");
assertNotNull(clazz);
+ assertTrue(clazz.startsWith("rich-ordering-list-button"));
+
+ element = (HtmlElement) element.getParentNode();
+ assertNotNull(element);
+ assertEquals("div", element.getNodeName());
+ clazz = element.getAttributeValue("class");
+ assertNotNull(clazz);
assertTrue(clazz.contains("rich-ordering-control"));
}
+ assertEquals(8, generatedCount);
}
/**
@@ -335,10 +358,14 @@
assertEquals("button", hidden1.getAttributeValue("type"));
hidden1.getAttributeValue("style").contains("left:
-32767px");
- HtmlElement hidden2 =
view.getHtmlElementById(orderingList.getClientId(facesContext) +
"valueKeeper");
- assertNotNull(hidden2);
- assertEquals("input", hidden2.getNodeName());
- assertEquals("hidden", hidden2.getAttributeValue("type"));
+ List hiddens =
view.getDocumentElement().getHtmlElementsByAttribute("input", "name",
orderingList.getClientId(facesContext));
+ assertNotNull(hiddens);
+ assertEquals(ROWS_COUNT, hiddens.size());
+ for (Iterator it = hiddens.iterator(); it.hasNext(); ) {
+ HtmlElement hidden2 = (HtmlElement) it.next();
+ assertEquals("input", hidden2.getNodeName());
+ assertEquals("hidden", hidden2.getAttributeValue("type"));
+ }
}
protected class SimpleItem {