Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
refactored validation tests to fun tests + fix whole framework build
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Fryc committed Mar 19, 2013
1 parent f6752ca commit bf0f460
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 265 deletions.
Expand Up @@ -29,7 +29,6 @@
import javax.inject.Inject;
import javax.inject.Named;

import org.richfaces.component.UITree;
import org.richfaces.photoalbum.domain.Album;
import org.richfaces.photoalbum.domain.Image;
import org.richfaces.photoalbum.domain.MetaTag;
Expand All @@ -44,6 +43,7 @@
import org.richfaces.photoalbum.event.SimpleEvent;
import org.richfaces.photoalbum.service.Constants;
import org.richfaces.photoalbum.util.Preferred;
import org.richfaces.ui.iteration.AbstractTree;

/**
* This class represent 'C' in MVC pattern. It is logic that determine what actions invoked and what next page need to be
Expand Down Expand Up @@ -484,7 +484,7 @@ public void cancelRegistration() {
/**
* This utility method determine if the specified node should be marked as selected. Used in internal rich:tree mechanism
*/
public Boolean adviseNodeSelected(UITree tree) {
public Boolean adviseNodeSelected(AbstractTree tree) {
Object currentNode = tree.getRowData();
if (currentNode.equals(model.getSelectedAlbum()) || currentNode.equals(model.getSelectedShelf())) {
return true;
Expand Down
@@ -1,6 +1,6 @@
package org.richfaces.photoalbum.util;

import org.richfaces.component.UIOutputPanel;
import org.richfaces.ui.output.UIOutputPanel;

public class UIOutputPanelWorkaround extends UIOutputPanel {
public boolean isKeepTransient() {
Expand Down
Expand Up @@ -10,8 +10,8 @@
import javax.faces.bean.ViewScoped;
import javax.faces.event.AjaxBehaviorEvent;

import org.richfaces.component.UIExtendedDataTable;
import org.richfaces.demo.tables.model.cars.InventoryItem;
import org.richfaces.ui.iteration.AbstractExtendedDataTable;

@ManagedBean
@ViewScoped
Expand All @@ -23,7 +23,7 @@ public class ExtTableSelectionBean implements Serializable {
private List<InventoryItem> selectionItems = new ArrayList<InventoryItem>();

public void selectionListener(AjaxBehaviorEvent event) {
UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
AbstractExtendedDataTable dataTable = (AbstractExtendedDataTable) event.getComponent();
Object originalKey = dataTable.getRowKey();
selectionItems.clear();
for (Object selectionKey : selection) {
Expand Down
Expand Up @@ -33,11 +33,11 @@
import javax.faces.bean.ViewScoped;
import javax.swing.tree.TreeNode;

import org.richfaces.component.UITree;
import org.richfaces.demo.tree.model.CD;
import org.richfaces.demo.tree.model.Company;
import org.richfaces.demo.tree.model.Country;
import org.richfaces.event.TreeSelectionChangeEvent;
import org.richfaces.ui.iteration.AbstractTree;

/**
* @author Ilya Shaikovsky
Expand Down Expand Up @@ -69,7 +69,7 @@ public void selectionChanged(TreeSelectionChangeEvent selectionChangeEvent) {
// considering only single selection
List<Object> selection = new ArrayList<Object>(selectionChangeEvent.getNewSelection());
Object currentSelectionKey = selection.get(0);
UITree tree = (UITree) selectionChangeEvent.getSource();
AbstractTree tree = (AbstractTree) selectionChangeEvent.getSource();

Object storedKey = tree.getRowKey();
tree.setRowKey(currentSelectionKey);
Expand Down
Expand Up @@ -38,7 +38,7 @@
* @author asmirnov@exadel.com
*/
@JsfComponent(type = "org.richfaces.Message", tag = @Tag(name = "message"),
renderer = @JsfRenderer(template = "message.template.xml"),
renderer = @JsfRenderer(template = "message.template.xml", type = "org.richfaces.MessageRenderer"),
attributes = {"core-props.xml", "events-mouse-props.xml", "events-key-props.xml", "i18n-props.xml", "AjaxOutput-props.xml", "output-format-props.xml" })
public abstract class AbstractMessage extends UIMessage implements AjaxOutput {
@Attribute(defaultValue = "true")
Expand Down
Expand Up @@ -38,10 +38,9 @@
* @author asmirnov@exadel.com
*/
@JsfComponent(type = "org.richfaces.Messages", tag = @Tag(name = "messages"),
renderer = @JsfRenderer(template = "messages.template.xml"),
attributes = {
"core-props.xml", "events-mouse-props.xml", "events-key-props.xml", "i18n-props.xml", "AjaxOutput-props.xml",
"output-format-props.xml" })
renderer = @JsfRenderer(template = "messages.template.xml", type = "org.richfaces.MessagesRenderer"), attributes = {
"core-props.xml", "events-mouse-props.xml", "events-key-props.xml", "i18n-props.xml", "AjaxOutput-props.xml",
"output-format-props.xml" })
public abstract class AbstractMessages extends UIMessages implements AjaxOutput, ClientSideMessage {
@Attribute(defaultValue = "true")
public abstract boolean isAjaxRendered();
Expand Down
Expand Up @@ -41,7 +41,7 @@
*/
@JsfComponent(type = "org.richfaces.NotifyMessage", tag = @Tag(name = "notifyMessage"),
attributes = { "core-props.xml", "events-mouse-props.xml", "events-key-props.xml", "i18n-props.xml", "AjaxOutput-props.xml" },
renderer = @JsfRenderer(template = "notifyMessage.template.xml"))
renderer = @JsfRenderer(template = "notifyMessage.template.xml", type = "org.richfaces.NotifyMessageRenderer"))
public abstract class AbstractNotifyMessage extends UIMessage implements AjaxOutput, ClientSideMessage, NotifyAttributes {

@Attribute(defaultValue = "true")
Expand Down
Expand Up @@ -37,7 +37,7 @@
* @author <a href="http://community.jboss.org/people/lfryc">Lukas Fryc</a>
*/
@JsfComponent(type = "org.richfaces.NotifyMessages", tag = @Tag(name = "notifyMessages"),
renderer = @JsfRenderer(template = "notifyMessages.template.xml"),
renderer = @JsfRenderer(template = "notifyMessages.template.xml", type = "org.richfaces.NotifyMessagesRenderer"),
attributes = { "core-props.xml", "events-mouse-props.xml", "events-key-props.xml", "i18n-props.xml", "AjaxOutput-props.xml" })
public abstract class AbstractNotifyMessages extends UIMessages implements AjaxOutput, ClientSideMessage, NotifyAttributes {

Expand Down
@@ -1,34 +1,35 @@
package org.richfaces.ui.validation;

import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertNotNull;

/**
* Test for dynamic add/remove {@link org.richfaces.ui.core.UIScripts} as view resource.
*
* @author asmirnov
*
*/
import static org.jboss.arquillian.graphene.Graphene.guardXhr;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.richfaces.deployment.FrameworkDeployment;
import org.richfaces.integration.IntegrationTest;
import org.richfaces.shrinkwrap.descriptor.FaceletAsset;
import org.richfaces.ui.common.Bean;

@RunWith(Arquillian.class)
@RunAsClient
@Category(IntegrationTest.class)
public class AjaxValidationTest extends ValidationTestBase {

protected String getFacesConfig() {
return "faces-config.xml";
}
@Deployment
public static WebArchive deployment() {
FrameworkDeployment deployment = new FrameworkDeployment(AjaxValidationTest.class);

protected String getPageName() {
return "test";
}
deployment.archive().addClasses(Bean.class, CustomValidator.class);

@Test
public void testRequest() throws Exception {
HtmlPage page = requestPage();
HtmlInput input = getInput(page);
assertNotNull(input);
addIndexPage(deployment);

return deployment.getFinalArchive();
}

@Test
Expand All @@ -46,4 +47,24 @@ public void testSubmitProperValue() throws Exception {
submitValueAndCheckMessage("ab", equalTo(""));
}

@Override
protected void submitValue() {
guardXhr(body).click();
}

private static void addIndexPage(org.richfaces.deployment.Deployment deployment) {
FaceletAsset p = new FaceletAsset();

p.body("<h:form id='form'>");
p.body("<h:inputText id='text' value='#{test.value}'>");
p.body(" <f:validator validatorId='custom' />");
p.body(" <r:validator event='blur' />");
p.body("</h:inputText>");
p.body("<h:outputText id='out' value='#{test.value}'></h:outputText>");
p.body("</h:form>");
p.body("<r:message id='uiMessage' for='text' />");

deployment.archive().addAsWebResource(p, "index.xhtml");
}

}
@@ -1,34 +1,31 @@
package org.richfaces.ui.validation;

import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertNotNull;

/**
* Test for dynamic add/remove {@link org.richfaces.ui.core.UIScripts} as view resource.
*
* @author asmirnov
*
*/

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.deployment.FrameworkDeployment;
import org.richfaces.shrinkwrap.descriptor.FaceletAsset;
import org.richfaces.ui.common.Bean;

@RunWith(Arquillian.class)
@RunAsClient
public class ClientValidationTest extends ValidationTestBase {

protected String getFacesConfig() {
return "faces-config.xml";
}
@Deployment
public static WebArchive deployment() {
FrameworkDeployment deployment = new FrameworkDeployment(ClientValidationTest.class);

protected String getPageName() {
return "client-test";
}
deployment.archive().addClasses(Bean.class);

@Test
public void testRequest() throws Exception {
HtmlPage page = requestPage();
HtmlInput input = getInput(page);
assertNotNull(input);
addIndexPage(deployment);

return deployment.getFinalArchive();
}

@Test
Expand All @@ -45,4 +42,20 @@ public void testSubmitTooLongValue() throws Exception {
public void testSubmitProperValue() throws Exception {
submitValueAndCheckMessage("ab", equalTo(""));
}

private static void addIndexPage(org.richfaces.deployment.Deployment deployment) {
FaceletAsset p = new FaceletAsset();

p.body("<h:form id='form'>");
p.body(" <h:inputText id='text' value='#{test.value}'>");
p.body(" <f:validateLength minimum='1' maximum='3' />");
p.body(" <r:validator event='blur' />");
p.body(" </h:inputText>");
p.body(" <h:outputText id='out' value='#{test.value}'></h:outputText>");
p.body("</h:form>");

p.body("<r:message id='uiMessage' for='text' />");

deployment.archive().addAsWebResource(p, "index.xhtml");
}
}
@@ -0,0 +1,36 @@
package org.richfaces.ui.validation;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
import org.junit.runner.RunWith;
import org.richfaces.deployment.FrameworkDeployment;

import com.google.common.base.Function;

@RunWith(Arquillian.class)
@RunAsClient
public class FacesBeanValidatorTest extends GraphValidationTestBase {

@Deployment
public static WebArchive deployment() {
FrameworkDeployment deployment = new FrameworkDeployment(FacesBeanValidatorTest.class);

deployment.archive().addClasses(GraphBean.class, Group.class);

deployment.webXml(new Function<WebAppDescriptor, WebAppDescriptor>() {
public WebAppDescriptor apply(WebAppDescriptor webXml) {
webXml.createContextParam()
.paramName("javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR")
.paramValue("true");
return webXml;
}
});

GraphValidationTest.addIndexPage(deployment);

return deployment.getFinalArchive();
}
}
@@ -1,61 +1,24 @@
package org.richfaces.ui.validation;

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.Test;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.runner.RunWith;
import org.richfaces.deployment.FrameworkDeployment;

import java.io.IOException;
@RunWith(Arquillian.class)
@RunAsClient
public class GraphValidationTest extends GraphValidationTestBase {

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.matchers.JUnitMatchers.containsString;
@Deployment
public static WebArchive deployment() {
FrameworkDeployment deployment = new FrameworkDeployment(GraphValidationTest.class);

/**
* Test for dynamic add/remove {@link org.richfaces.ui.core.UIScripts} as view resource.
*
* @author asmirnov
*
*/
public class GraphValidationTest extends ValidationTestBase {
deployment.archive().addClasses(GraphBean.class, Group.class);

protected String getFacesConfig() {
return "graph-faces-config.xml";
}

protected String getPageName() {
return "graph-test";
}

@Test
public void testRequest() throws Exception {
HtmlPage page = requestPage();
HtmlInput input = getInput(page);
assertNotNull(input);
}

@Override
protected HtmlPage submit(HtmlPage page) throws IOException {
HtmlElement submit = page.getElementById("form:submit");
return submit.click();
}

@Test
public void testSubmitTooShortValue() throws Exception {
HtmlPage page = submitValueAndCheckMessage("", containsString(GraphBean.SHORT_MSG));
checkMessage(page, "textMessage", containsString(GraphBean.SHORT_MSG));
checkMessage(page, "graphMessage", equalTo(""));
}

@Test
public void testBeanLevelConstrain() throws Exception {
HtmlPage page = submitValueAndCheckMessage("bar", equalTo(GraphBean.FOO_MSG));
checkMessage(page, "graphMessage", containsString(GraphBean.FOO_MSG));
checkMessage(page, "textMessage", equalTo(""));
}
addIndexPage(deployment);

@Test
public void testCorrectValue() throws Exception {
submitValueAndCheckMessage("foobar", equalTo(""));
return deployment.getFinalArchive();
}
}

0 comments on commit bf0f460

Please sign in to comment.