Author: abelevich
Date: 2007-07-31 11:32:25 -0400 (Tue, 31 Jul 2007)
New Revision: 1956
Added:
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/RichMessageRendererTest.java
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/RichMessagesRendererTest.java
Log:
test for message and messages renderers
Added:
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/RichMessageRendererTest.java
===================================================================
---
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/RichMessageRendererTest.java
(rev 0)
+++
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/RichMessageRendererTest.java 2007-07-31
15:32:25 UTC (rev 1956)
@@ -0,0 +1,105 @@
+/**
+ *
+ */
+package org.richfaces.renderer;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.component.html.HtmlOutputText;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlRichMessage;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class RichMessageRendererTest extends AbstractAjax4JsfTestCase {
+
+ HtmlRichMessage message = null;
+ HtmlOutputText text = null;
+ HtmlInputText input = null;
+
+ public RichMessageRendererTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+
+ super.setUp();
+
+ input =
(HtmlInputText)application.createComponent("javax.faces.HtmlInputText");
+ input.setId("select");
+
+ text =
(HtmlOutputText)application.createComponent("javax.faces.HtmlOutputText");
+ text.setValue("Error");
+
+ message =
(HtmlRichMessage)application.createComponent("org.richfaces.component.RichMessage");
+ message.setId("message");
+ message.setFor("select");
+ message.setErrorClass("errorClass");
+ message.setErrorLabelClass("errorLabelClass");
+ message.setErrorMarkerClass("errorMarkerClass");
+ message.getFacets().put("errorFacet", text);
+
+ FacesMessage facesMessage = new FacesMessage();
+
+ facesMessage.setDetail("TEST detail");
+ facesMessage.setSummary("TEST summary");
+ facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
+ facesContext.addMessage("select",facesMessage);
+
+ facesContext.getViewRoot().getChildren().add(input);
+ facesContext.getViewRoot().getChildren().add(message);
+
+ }
+
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List links =
page.getDocumentElement().getHtmlElementsByTagName("link");
+ assertNotNull(links);
+ HtmlElement link = (HtmlElement)links.get(0);
+
assertTrue(link.getAttributeValue("href").contains("/org/richfaces/renderkit/html/css/msg.css"));
+ }
+
+ public void testRendererMessage() throws Exception{
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ HtmlElement span = page.getHtmlElementById(message.getClientId(facesContext));
+
+ assertNotNull(span);
+ assertEquals("span", span.getNodeName().toLowerCase());
+
+ String classAttr = span.getAttributeValue("class");
+ assertTrue(classAttr.contains("rich-message"));
+ assertTrue(classAttr.contains("errorClass"));
+
+ Iterator childIter= span.getChildElementsIterator();
+
+ for (; childIter.hasNext();) {
+ HtmlElement name = (HtmlElement) childIter.next();
+ assertNotNull(name);
+ assertEquals(name.getNodeName().toLowerCase(), "span");
+
+ classAttr = name.getAttributeValue("class");
+ assertTrue(classAttr.contains("rich-message-label")||
classAttr.contains("rich-message-marker") );
+
assertTrue(classAttr.contains("errorLabelClass")||classAttr.contains("errorMarkerClass")
);
+ }
+
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ message = null;
+ }
+
+}
Added:
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/RichMessagesRendererTest.java
===================================================================
---
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/RichMessagesRendererTest.java
(rev 0)
+++
trunk/sandbox/ui/message/src/test/java/org/richfaces/renderer/RichMessagesRendererTest.java 2007-07-31
15:32:25 UTC (rev 1956)
@@ -0,0 +1,273 @@
+/**
+ *
+ */
+package org.richfaces.renderer;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.component.html.HtmlOutputText;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.html.HtmlRichMessages;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class RichMessagesRendererTest extends AbstractAjax4JsfTestCase {
+
+ HtmlRichMessages messages1 = null;
+ HtmlRichMessages messages2 = null;
+
+ HtmlInputText input1 = null;
+ HtmlInputText input2 = null;
+ HtmlInputText input3 = null;
+ HtmlInputText input4 = null;
+
+ HtmlOutputText output1 = null;
+ HtmlOutputText output2 = null;
+ HtmlOutputText output3 = null;
+ HtmlOutputText output4 = null;
+
+
+ public RichMessagesRendererTest(String name) {
+ super(name);
+ }
+
+ public void testRenderStyle() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ List links =
page.getDocumentElement().getHtmlElementsByTagName("link");
+ assertNotNull(links);
+ HtmlElement link = (HtmlElement)links.get(0);
+
assertTrue(link.getAttributeValue("href").contains("/org/richfaces/renderkit/html/css/msgs.css"));
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ messages1 = null;
+ messages2 = null;
+ }
+
+ public void setUp() throws Exception {
+
+ super.setUp();
+
+ input1 =
(HtmlInputText)application.createComponent("javax.faces.HtmlInputText");
+ input1.setId("input1");
+
+ output1 =
(HtmlOutputText)application.createComponent("javax.faces.HtmlOutputText");
+ output1.setId("output1");
+ output1.setValue("output1");
+
+ input2 =
(HtmlInputText)application.createComponent("javax.faces.HtmlInputText");
+ input2.setId("input2");
+
+ output2 =
(HtmlOutputText)application.createComponent("javax.faces.HtmlOutputText");
+ output2.setId("output2");
+ output2.setValue("output2");
+
+ input3 =
(HtmlInputText)application.createComponent("javax.faces.HtmlInputText");
+ input3.setId("input3");
+
+ output3 =
(HtmlOutputText)application.createComponent("javax.faces.HtmlOutputText");
+ output3.setId("output3");
+ output3.setValue("output3");
+
+ input4 =
(HtmlInputText)application.createComponent("javax.faces.HtmlInputText");
+ input4.setId("input4");
+
+ output4 =
(HtmlOutputText)application.createComponent("javax.faces.HtmlOutputText");
+ output4.setId("output4");
+ output4.setValue("output4");
+
+ messages1 =
(HtmlRichMessages)application.createComponent("org.richfaces.component.RichMessages");
+ messages1.setId("message1");
+ messages1.setLayout("table");
+ messages1.setErrorClass("errorClass");
+ messages1.setWarnClass("warnClass");
+ messages1.setFatalClass("fatalClass");
+ messages1.setInfoClass("infoClass");
+
+ messages1.setErrorLabelClass("errorLabelClass");
+ messages1.setWarnLabelClass("errorLabelClass");
+ messages1.setFatalLabelClass("errorLabelClass");
+ messages1.setInfoLabelClass("errorLabelClass");
+
+ messages1.setErrorMarkerClass("errorMarkerClass");
+ messages1.setFatalMarkerClass("fatalMarkerClass");
+ messages1.setInfoMarkerClass("infoMarkerClass");
+ messages1.setWarnMarkerClass("warnMarkerClass");
+
+ messages1.getFacets().put("errorMarker", output1);
+ messages1.getFacets().put("warnMarker", output2);
+ messages1.getFacets().put("fatalMarker", output3);
+ messages1.getFacets().put("infoMarker", output4);
+
+ messages1.setTitle("TITLE");
+
+ messages2 =
(HtmlRichMessages)application.createComponent("org.richfaces.component.RichMessages");
+ messages2.setId("message2");
+ messages2.setLayout("list");
+
+ messages2.setErrorClass("errorClass");
+ messages2.setWarnClass("warnClass");
+ messages2.setFatalClass("fatalClass");
+ messages2.setInfoClass("infoClass");
+
+ messages2.setErrorLabelClass("errorLabelClass");
+ messages2.setWarnLabelClass("errorLabelClass");
+ messages2.setFatalLabelClass("errorLabelClass");
+ messages2.setInfoLabelClass("errorLabelClass");
+
+ messages2.setErrorMarkerClass("errorMarkerClass");
+ messages2.setFatalMarkerClass("fatalMarkerClass");
+ messages2.setInfoMarkerClass("infoMarkerClass");
+ messages2.setWarnMarkerClass("warnMarkerClass");
+
+ messages2.getFacets().put("errorMarker", output1);
+ messages2.getFacets().put("warnMarker", output2);
+ messages2.getFacets().put("fatalMarker", output3);
+ messages2.getFacets().put("infoMarker", output4);
+
+ FacesMessage facesMessage = new FacesMessage();
+
+ facesMessage.setDetail("TEST detail");
+ facesMessage.setSummary("TEST summary");
+ facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR);
+ facesContext.addMessage("input1",facesMessage);
+
+ facesMessage.setDetail("TEST detail");
+ facesMessage.setSummary("TEST summary");
+ facesMessage.setSeverity(FacesMessage.SEVERITY_FATAL);
+ facesContext.addMessage("input2",facesMessage);
+
+ facesMessage.setDetail("TEST detail");
+ facesMessage.setSummary("TEST summary");
+ facesMessage.setSeverity(FacesMessage.SEVERITY_INFO);
+ facesContext.addMessage("input3",facesMessage);
+
+ facesMessage.setDetail("TEST detail");
+ facesMessage.setSummary("TEST summary");
+ facesMessage.setSeverity(FacesMessage.SEVERITY_WARN);
+ facesContext.addMessage("input4",facesMessage);
+
+ facesContext.getViewRoot().getChildren().add(input1);
+ facesContext.getViewRoot().getChildren().add(input2);
+ facesContext.getViewRoot().getChildren().add(input3);
+ facesContext.getViewRoot().getChildren().add(input4);
+ facesContext.getViewRoot().getChildren().add(messages1);
+ facesContext.getViewRoot().getChildren().add(messages2);
+
+ }
+
+ public void testRendererMessage() throws Exception{
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ HtmlElement table = page.getHtmlElementById(messages1.getClientId(facesContext));
+ HtmlElement dl = page.getHtmlElementById(messages2.getClientId(facesContext));
+
+ assertNotNull(table);
+ assertNotNull(dl);
+
+ assertEquals(table.getNodeName().toLowerCase(), "table");
+ assertEquals(dl.getNodeName().toLowerCase(), "dl");
+
+ String classAttr = table.getAttributeValue("class");
+ assertTrue(classAttr.contains("rich-message"));
+
+ classAttr = dl.getAttributeValue("class");
+ assertTrue(classAttr.contains("rich-message"));
+
+ // test rendering component mockup for list layout
+ Iterator dtIter= dl.getChildElementsIterator();
+ for (; dtIter.hasNext();) {
+
+ HtmlElement dt = (HtmlElement) dtIter.next();
+ assertNotNull(dt);
+ assertEquals(dt.getNodeName().toLowerCase(), "dt");
+ classAttr = dt.getAttributeValue("class");
+ assertTrue(classAttr.contains("errorClass")||classAttr.contains("fatalClass")
+ ||classAttr.contains("warnClass")
||classAttr.contains("infoClass"));
+
+ Iterator spanIter= dt.getChildElementsIterator();
+ for (; spanIter.hasNext();) {
+
+ HtmlElement span = (HtmlElement) dtIter.next();
+ assertNotNull(span);
+ assertEquals(dt.getNodeName().toLowerCase(), "span");
+
+ classAttr = dt.getAttributeValue("class");
+
+ assertTrue(classAttr.contains("rich-messages-label") ||
classAttr.contains("rich-massages-marker"));
+
+ assertTrue(classAttr.contains("errorLabelClass") ||
classAttr.contains("infoLabelClass")
+ || classAttr.contains("fatalLabelClass") ||
classAttr.contains("warnLabelClass")
+ || classAttr.contains("errorMarkerClass") ||
classAttr.contains("fatalMarkerClass")
+ || classAttr.contains("infoMarkerClass") ||
classAttr.contains("warnMarkerClass"));
+
+ String title = dt.getAttributeValue("title");
+
+ assertEquals("TITLTE", title);
+ }
+ }
+
+ // test rendering component mockup for table layout
+ HtmlElement tbody = (HtmlElement)table.getFirstChild();
+
+ assertNotNull(tbody);
+ assertEquals(tbody.getNodeName().toLowerCase(), "tbody");
+
+ Iterator trIter = tbody.getChildIterator();
+
+ for (;trIter.hasNext();) {
+
+ HtmlElement tr = (HtmlElement) trIter.next();
+
+ assertNotNull(tr);
+ assertEquals(tr.getNodeName().toLowerCase(), "tr");
+
+ classAttr = tr.getAttributeValue("class");
+
+ assertTrue(classAttr.contains("errorClass")||classAttr.contains("fatalClass")
+ ||classAttr.contains("warnClass")
||classAttr.contains("infoClass"));
+
+ Iterator tdIter = tr.getChildIterator();
+ for (;tdIter.hasNext();) {
+
+ HtmlElement td = (HtmlElement)tdIter.next();
+ assertNotNull(td);
+ assertEquals(td.getNodeName().toLowerCase(), "td");
+
+ if(td.getAttributeValue("class")!= null){
+ classAttr = td.getAttributeValue("class");
+
+ assertTrue(classAttr.contains("rich-messages-marker"));
+ assertTrue(classAttr.contains("errorMarkerClass") ||
classAttr.contains("fatalMarkerClass")
+ || classAttr.contains("infoMarkerClass") ||
classAttr.contains("warnMarkerClass"));
+ }
+
+ HtmlElement elem = (HtmlElement)td.getFirstChild();
+ assertNotNull(elem);
+
+ if(elem.getNodeName().equals("span")){
+ classAttr = tr.getAttributeValue("class");
+
+ assertTrue(classAttr.contains("rich-messages-label"));
+ assertTrue(classAttr.contains("errorLabelClass") ||
classAttr.contains("infoLabelClass")
+ || classAttr.contains("fatalLabelClass") ||
classAttr.contains("warnLabelClass"));
+
+ String title = elem.getAttributeValue("title");
+ assertEquals("TITLTE", title);
+ }
+ }
+ }
+ }
+}
Show replies by date