Author: alexsmirnov
Date: 2010-09-15 19:43:35 -0400 (Wed, 15 Sep 2010)
New Revision: 19219
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ClientScript.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
branches/RF-8742/ui/validator/ui/src/test/config/
branches/RF-8742/ui/validator/ui/src/test/config/mocks.xml
branches/RF-8742/ui/validator/ui/src/test/java/org/
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/ClientValidatorBehaviorTest.java
Removed:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java
Modified:
branches/RF-8742/ui/validator/api/pom.xml
branches/RF-8742/ui/validator/impl/pom.xml
branches/RF-8742/ui/validator/ui/pom.xml
Log:
CODING IN PROGRESS - issue RF-9219: CSV: development tests for server side(junit)
https://jira.jboss.org/browse/RF-9219
Modified: branches/RF-8742/ui/validator/api/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/api/pom.xml 2010-09-15 16:10:55 UTC (rev 19218)
+++ branches/RF-8742/ui/validator/api/pom.xml 2010-09-15 23:43:35 UTC (rev 19219)
@@ -58,6 +58,12 @@
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-mock</artifactId>
+ <version>1.0.5-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<scm>
Added:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ClientScript.java
===================================================================
---
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ClientScript.java
(rev 0)
+++
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ClientScript.java 2010-09-15
23:43:35 UTC (rev 19219)
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.validator;
+
+/**
+ * <p class="changed_added_4_0">This class contains information about
JavaScript associated with JSF object ( converter or validator )</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface ClientScript {
+
+ String getLibrary();
+
+ String getResourceName();
+
+ String getFunctionName();
+
+}
Property changes on:
branches/RF-8742/ui/validator/api/src/main/java/org/richfaces/validator/ClientScript.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/RF-8742/ui/validator/impl/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/impl/pom.xml 2010-09-15 16:10:55 UTC (rev 19218)
+++ branches/RF-8742/ui/validator/impl/pom.xml 2010-09-15 23:43:35 UTC (rev 19219)
@@ -71,6 +71,12 @@
<version>4.0.0.GA</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-mock</artifactId>
+ <version>1.0.5-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<scm>
Modified: branches/RF-8742/ui/validator/ui/pom.xml
===================================================================
--- branches/RF-8742/ui/validator/ui/pom.xml 2010-09-15 16:10:55 UTC (rev 19218)
+++ branches/RF-8742/ui/validator/ui/pom.xml 2010-09-15 23:43:35 UTC (rev 19219)
@@ -43,6 +43,21 @@
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>maven-mockgenerator-plugin</artifactId>
+ <version>1.0.5-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <id>generateTestMocks</id>
+ <goals>
+ <goal>generate-test-mock</goal>
+ </goals>
+ <configuration>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
@@ -56,18 +71,25 @@
<groupId>org.richfaces.ui.common</groupId>
<artifactId>richfaces-ui-common-ui</artifactId>
</dependency>
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- <version>1.0.0.GA</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>4.0.0.GA</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>4.0.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-mock</artifactId>
+ <version>1.0.5-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<scm>
Deleted:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java 2010-09-15
16:10:55 UTC (rev 19218)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java 2010-09-15
23:43:35 UTC (rev 19219)
@@ -1,34 +0,0 @@
-/*
- * $Id$
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.component;
-
-import javax.faces.component.behavior.ClientBehaviorBase;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class ClientValidatorBehavior extends ClientBehaviorBase {
-
-}
Copied:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
(from rev 19206,
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/ClientValidatorBehavior.java)
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java 2010-09-15
23:43:35 UTC (rev 19219)
@@ -0,0 +1,55 @@
+/*
+ * $Id$
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component.behavior;
+
+import java.util.Collection;
+
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIMessage;
+import javax.faces.component.behavior.ClientBehaviorBase;
+import javax.faces.component.behavior.ClientBehaviorContext;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ClientValidatorBehavior extends ClientBehaviorBase {
+
+ @Override
+ public String getScript(ClientBehaviorContext behaviorContext) {
+ if (!(behaviorContext.getComponent() instanceof EditableValueHolder)) {
+ throw new FacesException("Invalid target for client-side validator
behavior");
+ }
+ return super.getScript(behaviorContext);
+ }
+ /**
+ * <p class="changed_added_4_0">This method looks up all {@link
UIMessage} components associated with input for which this behavior belongs to</p>
+ * @param context
+ * @return non-null collection of {@link UIMessage} components associated with terget
input.
+ */
+// public Collection<UIMessage> findMessages(ClientBehaviorContext context) {
+//
+// }
+}
Property changes on:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/RF-8742/ui/validator/ui/src/test/config/mocks.xml
===================================================================
--- branches/RF-8742/ui/validator/ui/src/test/config/mocks.xml
(rev 0)
+++ branches/RF-8742/ui/validator/ui/src/test/config/mocks.xml 2010-09-15 23:43:35 UTC
(rev 19219)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mock-config>
+ <class-prefix>Mock</class-prefix>
+ <package>org.richfaces.component.mock</package>
+
<mock-controller>org.richfaces.component.mock.FacesTestMockController</mock-controller>
+ <mock>
+ <name>org.richfaces.component.mock.MockUIForm</name>
+ <class-name>javax.faces.component.UIForm</class-name>
+ </mock>
+ <mock>
+ <name>org.richfaces.component.mock.MockUIMessage</name>
+ <class-name>javax.faces.component.UIMessage</class-name>
+ </mock>
+
+</mock-config>
\ No newline at end of file
Property changes on: branches/RF-8742/ui/validator/ui/src/test/config/mocks.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java 2010-09-15
16:10:55 UTC (rev 19218)
+++
branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java 2010-09-15
23:43:35 UTC (rev 19219)
@@ -1,112 +0,0 @@
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
-
-import javax.faces.FacesException;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIInput;
-import javax.faces.component.UIOutput;
-import javax.faces.component.behavior.ClientBehaviorContext;
-
-import org.jboss.test.faces.mock.Environment;
-import org.jboss.test.faces.mock.Mock;
-import org.jboss.test.faces.mock.MockController;
-import org.jboss.test.faces.mock.MockFacesEnvironment;
-import org.jboss.test.faces.mock.MockTestRunner;
-import org.jboss.test.faces.mock.Stub;
-import org.jboss.test.faces.mock.Environment.Feature;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.richfaces.component.ClientValidatorBehavior;
-
-
-/**
- * <p class="changed_added_4_0">This class tests client validator
behavior.
- * as it described at
https://community.jboss.org/wiki/ClientSideValidation # Server-side
rendering algorithm</p>
- * @author asmirnov(a)exadel.com
- *
- */
-(a)RunWith(MockTestRunner.class)
-public class ClientValidatorBehaviorTest {
-
- @Mock()
- @Environment({Feature.APPLICATION})
- protected MockFacesEnvironment environment;
-
- @Stub
- private UIOutput output;
-
- @Mock
- protected UIInput input;
-
- @Mock
- private ClientBehaviorContext behaviorContext;
-
- protected MockController controller;
-
- /**
- * <p class="changed_added_4_0">Server-side rendering algorithm
.1</p>
- */
- @Test(expected=FacesException.class)
- public void testGetScriptForIllegalComponent() {
- getScript(output);
- }
-
- /**
- * <p class="changed_added_4_0">Server-side rendering algorithm
.2</p>
- * @throws Exception
- */
- @Test
- public void testGetScriptWithoutMessageComponent() throws Exception {
-
- }
-
- /**
- * <p class="changed_added_4_0">Server-side rendering algorithm .3 -
determine client-side converter</p>
- * @throws Exception
- */
- @Test
- public void testGetClientConverter() throws Exception {
-
- }
- /**
- * <p class="changed_added_4_0">Server-side rendering algorithm
.3</p>
- * @throws Exception
- */
- @Test
- public void testGetScriptWithoutClientConverter() throws Exception {
-
- }
-
- /**
- * <p class="changed_added_4_0">Server-side rendering algorithm
.3</p>
- * @throws Exception
- */
- @Test
- public void testGetScriptWithClientConverter() throws Exception {
-
- }
-
- private String getScript(UIComponent component) {
- ClientValidatorBehavior behavior = createBehavior();
- controller.replay();
- String script = behavior.getScript(setupBehaviorContext(component));
- controller.verify();
- return script;
- }
-
- private ClientBehaviorContext setupBehaviorContext(UIComponent component) {
- expect(behaviorContext.getComponent()).andStubReturn(component);
-
expect(behaviorContext.getFacesContext()).andStubReturn(environment.getFacesContext());
- return behaviorContext;
- }
-
- private ClientValidatorBehavior createBehavior() {
- return new ClientValidatorBehavior();
- }
-
- @Test
- public void testDecode() {
- fail("Not yet implemented");
- }
-
-}
Copied:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/ClientValidatorBehaviorTest.java
(from rev 19208,
branches/RF-8742/ui/validator/ui/src/test/java/ClientValidatorBehaviorTest.java)
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/ClientValidatorBehaviorTest.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/behavior/ClientValidatorBehaviorTest.java 2010-09-15
23:43:35 UTC (rev 19219)
@@ -0,0 +1,180 @@
+package org.richfaces.component.behavior;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.behavior.ClientBehaviorContext;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.jboss.test.faces.mock.Environment;
+import org.jboss.test.faces.mock.Mock;
+import org.jboss.test.faces.mock.MockController;
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.jboss.test.faces.mock.MockTestRunner;
+import org.jboss.test.faces.mock.Stub;
+import org.jboss.test.faces.mock.Environment.Feature;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.component.behavior.ClientValidatorBehavior;
+import org.richfaces.component.mock.MockUIForm;
+import org.richfaces.component.mock.MockUIMessage;
+
+
+/**
+ * <p class="changed_added_4_0">This class tests client validator
behavior.
+ * as it described at
https://community.jboss.org/wiki/ClientSideValidation # Server-side
rendering algorithm</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)RunWith(MockTestRunner.class)
+public class ClientValidatorBehaviorTest {
+
+ private static final String CLIENT_VALIDATION_FUNCTION = "rf.csv.v";
+
+ private final class DummyConverter implements Converter {
+ public String getAsString(FacesContext context, UIComponent component, Object
value) {
+ return value.toString();
+ }
+
+ public Object getAsObject(FacesContext context, UIComponent component, String
value) {
+ return value;
+ }
+ }
+
+ private static final String FORM_ID = "formId";
+
+ private static final String INPUT_ID = "inputId";
+
+ private static final String MESSAGE_ID = "messageId";
+
+ @Mock()
+ @Environment({Feature.APPLICATION})
+ protected MockFacesEnvironment environment;
+
+ @Stub
+ private UIOutput output;
+
+ @Mock
+ protected UIInput input;
+
+ @Mock
+ protected UIViewRoot root;
+
+ @Mock
+ protected MockUIForm form;
+
+ @Mock
+ protected MockUIMessage message;
+
+ @Mock
+ private ClientBehaviorContext behaviorContext;
+
+ protected MockController controller;
+
+ private ClientValidatorBehavior behavior;
+
+ @Before
+ public void setUp() {
+ behavior = createBehavior();
+ }
+
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm
.1</p>
+ */
+ @Test(expected=FacesException.class)
+ public void testGetScriptForIllegalComponent() {
+ getScript(output);
+ }
+
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm
.2</p>
+ * @throws Exception
+ */
+ @Test
+ public void testGetScriptWithoutMessageComponent() throws Exception {
+ buildForm(false);
+ assertEquals(0, getScript(input).length());
+ }
+
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm .3 -
determine client-side converter</p>
+ * @throws Exception
+ */
+ @Test
+ public void testGetClientConverter() throws Exception {
+
+ }
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm
.3</p>
+ * @throws Exception
+ */
+ @Test
+ public void testGetScriptWithoutClientConverter() throws Exception {
+ buildForm(true);
+ expect(input.getConverter()).andStubReturn(new DummyConverter());
+ String script = getScript(input);// ajax-only validator.
+ assertFalse(script.contains(CLIENT_VALIDATION_FUNCTION));
+ }
+
+ /**
+ * <p class="changed_added_4_0">Server-side rendering algorithm
.3</p>
+ * @throws Exception
+ */
+ @Test
+ public void testGetScriptWithClientConverter() throws Exception {
+
+ }
+
+ private String getScript(UIComponent component) {
+ ClientBehaviorContext clientBehaviorContext = setupBehaviorContext(component);
+ controller.replay();
+ String script = behavior.getScript(clientBehaviorContext);
+ controller.verify();
+ return script;
+ }
+
+ private ClientBehaviorContext setupBehaviorContext(UIComponent component) {
+ expect(behaviorContext.getComponent()).andStubReturn(component);
+
expect(behaviorContext.getFacesContext()).andStubReturn(environment.getFacesContext());
+ return behaviorContext;
+ }
+
+ private void buildForm(boolean withMessage) {
+ expect(environment.getFacesContext().getViewRoot()).andStubReturn(root);
+ expect(form.getId()).andStubReturn(FORM_ID);
+ List<UIComponent> formChildren = new ArrayList<UIComponent>();
+ expect(form.getChildren()).andStubReturn(formChildren);
+ expect(input.getId()).andStubReturn(INPUT_ID);
+ expect(input.getParent()).andStubReturn(form);
+ formChildren.add(input);
+ expect(output.getParent()).andStubReturn(form);
+ formChildren.add(output);
+ if(withMessage){
+ expect(message.getId()).andStubReturn(MESSAGE_ID);
+ expect(message.getFor()).andStubReturn(INPUT_ID);
+ expect(message.getParent()).andStubReturn(form);
+ formChildren.add(message);
+ }
+// root.getChildren().add(form);
+ }
+
+ private ClientValidatorBehavior createBehavior() {
+ return new ClientValidatorBehavior();
+ }
+
+ @Test
+ public void testDecode() {
+ fail("Not yet implemented");
+ }
+
+}