Author: nbelaevski
Date: 2009-07-12 18:53:07 -0400 (Sun, 12 Jul 2009)
New Revision: 14902
Added:
framework/trunk/impl/src/test/java/org/ajax4jsf/codec/
framework/trunk/impl/src/test/java/org/ajax4jsf/codec/CodecTest.java
framework/trunk/impl/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java
framework/trunk/impl/src/test/java/org/richfaces/component/nsutils/
framework/trunk/impl/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java
framework/trunk/impl/src/test/java/org/richfaces/component/util/FormUtilTest.java
framework/trunk/impl/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
framework/trunk/impl/src/test/java/org/richfaces/json/JsonTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/
framework/trunk/impl/src/test/java/org/richfaces/model/FilterFieldTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/MockDataModel.java
framework/trunk/impl/src/test/java/org/richfaces/model/MockRange.java
framework/trunk/impl/src/test/java/org/richfaces/model/ModifiableModelTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/SortField2Test.java
framework/trunk/impl/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/entity/
framework/trunk/impl/src/test/java/org/richfaces/model/entity/Directory.java
framework/trunk/impl/src/test/java/org/richfaces/model/entity/File.java
framework/trunk/impl/src/test/java/org/richfaces/model/entity/Named.java
framework/trunk/impl/src/test/java/org/richfaces/model/entity/Project.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/JavaBeanWrapperTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/MethodBindingExpressionTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/NamedObject.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/NullExpressionTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/SimplePropertyExpressionTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/ValueBindingExpressionTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java
framework/trunk/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
framework/trunk/impl/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java
framework/trunk/impl/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java
framework/trunk/impl/src/test/java/org/richfaces/skin/
framework/trunk/impl/src/test/java/org/richfaces/skin/Bean.java
framework/trunk/impl/src/test/java/org/richfaces/skin/SkinTestCase.java
framework/trunk/impl/src/test/java/org/richfaces/skin/SkinThreadsTestCase.java
framework/trunk/impl/src/test/resources/bindedtest.skin.properties
framework/trunk/impl/src/test/resources/org/
framework/trunk/impl/src/test/resources/org/richfaces/
framework/trunk/impl/src/test/resources/org/richfaces/renderkit/
framework/trunk/impl/src/test/resources/org/richfaces/renderkit/form_script
framework/trunk/impl/src/test/resources/org/richfaces/renderkit/form_style
framework/trunk/impl/src/test/resources/org/richfaces/renderkit/input_script
framework/trunk/impl/src/test/resources/org/richfaces/renderkit/input_style
Modified:
framework/trunk/impl/
framework/trunk/impl/pom.xml
framework/trunk/impl/src/main/resources/META-INF/faces-config.xml
Log:
Framework unit tests updated
Property changes on: framework/trunk/impl
___________________________________________________________________
Name: svn:ignore
- .project
.checkstyle
target
.metadata
.settings
.classpath
+ .project
.checkstyle
target
.metadata
.settings
.classpath
.clover
Modified: framework/trunk/impl/pom.xml
===================================================================
--- framework/trunk/impl/pom.xml 2009-07-12 22:49:21 UTC (rev 14901)
+++ framework/trunk/impl/pom.xml 2009-07-12 22:53:07 UTC (rev 14902)
@@ -128,6 +128,10 @@
<artifactId>richfaces-api</artifactId>
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>richfaces-test-base</artifactId>
+ </dependency>
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
@@ -155,6 +159,16 @@
<artifactId>ehcache</artifactId>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: framework/trunk/impl/src/main/resources/META-INF/faces-config.xml
===================================================================
--- framework/trunk/impl/src/main/resources/META-INF/faces-config.xml 2009-07-12 22:49:21
UTC (rev 14901)
+++ framework/trunk/impl/src/main/resources/META-INF/faces-config.xml 2009-07-12 22:53:07
UTC (rev 14902)
@@ -41,16 +41,16 @@
<managed-bean-class>org.ajax4jsf.context.AjaxContextImpl</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
- <component>
+ <!-- component>
- <!-- component-type>javax.faces.ViewRoot</component-type>
+ <component-type>javax.faces.ViewRoot</component-type>
<component-class>org.ajax4jsf.component.AjaxViewRoot</component-class>
<component-extension>
<component-family>javax.faces.ViewRoot</component-family>
- </component-extension -->
+ </component-extension>
- </component>
+ </component -->
<!-- render-kit>
Copied: framework/trunk/impl/src/test/java/org/ajax4jsf/codec/CodecTest.java (from rev
14869, framework/trunk/legacy-tests/src/test/java/org/ajax4jsf/codec/CodecTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/ajax4jsf/codec/CodecTest.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/ajax4jsf/codec/CodecTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,81 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.codec;
+
+import org.ajax4jsf.util.base64.Codec;
+import org.richfaces.test.AbstractThreadedTest;
+
+public class CodecTest extends AbstractThreadedTest {
+ Codec c;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ String message = "";
+ try {
+ c = new Codec("anbshsquycwuudyft");
+ } catch (Exception e) {
+ message = "Cannot create Codec instance " + e.getMessage();
+ }
+ assertNotNull(message, c);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCodec() {
+ CodecTestRunnable[] runnables = new CodecTestRunnable[100];
+ for (int i = 0; i < runnables.length; i++) {
+ runnables[i] = new CodecTestRunnable(c, generateRandomString(), i);
+ }
+ runTestCaseRunnables(runnables);
+ }
+
+ private String generateRandomString() {
+ StringBuffer ss = new StringBuffer();
+ for (int i = 0; i < 50000; i++) {
+ char c = (char)(96 + Math.random() * 26);
+ ss.append(c);
+ }
+ return ss.toString();
+ }
+
+ class CodecTestRunnable extends TestCaseRunnable {
+ Codec c;
+ String s;
+ int id;
+
+ public CodecTestRunnable(Codec c, String s, int id) {
+ this.c = c;
+ this.s = s;
+ this.id = id;
+ }
+
+ public void runTestCase() throws Throwable {
+ String s1 = c.encode(s);
+ String s2 = c.decode(s1);
+ assertEquals("Failure in thread " + id, s2, s);
+ }
+
+ }
+
+}
Copied:
framework/trunk/impl/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java)
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,125 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import org.richfaces.test.AbstractFacesTest;
+
+
+public class UIRangedNumberInputTest extends AbstractFacesTest {
+
+ private UIRangedNumberInput input;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+
+ input = new UIRangedNumberInput() {
+ private String minValue;
+ private String maxValue;
+ private boolean disabled;
+
+ public String getMinValue() {
+ return minValue;
+ }
+ public void setMinValue(String minValue) {
+ this.minValue = minValue;
+ }
+ public String getMaxValue() {
+ return maxValue;
+ }
+ public void setMaxValue(String maxValue) {
+ this.maxValue = maxValue;
+ }
+ public boolean isDisabled() {
+ return disabled;
+ }
+ public void setDisabled(boolean disabled) {
+ this.disabled = disabled;
+ }
+ };
+
+ input.setMaxValue("100");
+ input.setMinValue("0");
+ input.setValid(true);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ this.input = null;
+ }
+
+ private void checkValid() {
+ assertTrue(input.isValid());
+ assertFalse(facesContext.getMessages().hasNext());
+ }
+
+ private void checkInvalid() {
+ assertFalse(input.isValid());
+ assertTrue(facesContext.getMessages().hasNext());
+ }
+
+ public void testValidateValueFacesContextObject() {
+ checkValid();
+ input.validateValue(facesContext, new Double(23.45));
+ checkValid();
+ }
+
+ public void testValidateNullValue() throws Exception {
+ checkValid();
+ input.validateValue(facesContext, null);
+ checkValid();
+ }
+
+ public void testValidateMinValue() throws Exception {
+ checkValid();
+ input.validateValue(facesContext, new Double(-23.45));
+ checkInvalid();
+ }
+
+ public void testValidateMaxValue() throws Exception {
+ checkValid();
+ input.validateValue(facesContext, new Double(223.45));
+ checkInvalid();
+ }
+
+
+ public void testValidateMinNullMinValue() throws Exception {
+ input.setMinValue(null);
+ checkValid();
+ input.validateValue(facesContext, new Double(-23.45));
+ checkInvalid();
+ }
+
+ public void testValidateMaxNullMaxValue() throws Exception {
+ input.setMaxValue(null);
+ checkValid();
+ input.validateValue(facesContext, new Double(223.45));
+ checkInvalid();
+ }
+
+ public void testValidateIllegalValue() throws Exception {
+ checkValid();
+ input.validateValue(facesContext, "string");
+ checkInvalid();
+ }
+}
Copied:
framework/trunk/impl/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java (from
rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/component/nsutils/NSUtilsTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,60 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component.nsutils;
+
+import java.io.StringWriter;
+
+import javax.faces.component.UIInput;
+import javax.faces.context.ResponseWriter;
+
+import org.richfaces.test.AbstractFacesTest;
+
+public class NSUtilsTest extends AbstractFacesTest {
+
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testWriteNameSpace() throws Exception {
+ final StringWriter stringWriter = new StringWriter();
+ ResponseWriter writer = facesContext.getRenderKit().createResponseWriter(stringWriter,
"text/html", "UTF-8");
+ facesContext.setResponseWriter(writer);
+
+ UIInput input = new UIInput();
+
+ writer.startDocument();
+ writer.startElement("span", input);
+
+ NSUtils.writeNameSpace(facesContext, input);
+
+ writer.endElement("span");
+ writer.endDocument();
+
+ String result = stringWriter.getBuffer().toString();
+ assertTrue(result.contains("span
xmlns:rich=\"http://richfaces.ajax4jsf.org/rich\""));
+ }
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/component/util/FormUtilTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/component/util/FormUtilTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/component/util/FormUtilTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/component/util/FormUtilTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,85 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component.util;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UIViewRoot;
+
+import org.richfaces.component.EnclosingFormRequiredException;
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 11.04.2007
+ *
+ */
+public class FormUtilTest extends AbstractFacesTest {
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testThrowEnclFormReqExceptionIfNeed() throws Exception {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ UIComponent form = application.createComponent(UIForm.COMPONENT_TYPE);
+ viewRoot.getChildren().add(form);
+
+ UIComponent testComponent = application.createComponent(UIOutput.COMPONENT_TYPE);
+ form.getChildren().add(testComponent);
+
+ FormUtil.throwEnclFormReqExceptionIfNeed(facesContext, testComponent);
+ }
+
+ public void testThrowEnclFormReqExceptionIfNeedNoForm() throws Exception {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+
+ UIComponent testComponent = application.createComponent(UIOutput.COMPONENT_TYPE);
+ viewRoot.getChildren().add(testComponent);
+
+ try {
+ FormUtil.throwEnclFormReqExceptionIfNeed(facesContext, testComponent);
+
+ fail();
+ } catch (EnclosingFormRequiredException e) {
+
+ }
+ }
+
+ public void testThrowEnclFormReqExceptionIfNeedClient() throws Exception {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+
+ UIComponent testComponent = application.createComponent(UIOutput.COMPONENT_TYPE);
+ testComponent.getAttributes().put("switchType", "CLIENT");
+ viewRoot.getChildren().add(testComponent);
+
+ FormUtil.throwEnclFormReqExceptionIfNeed(facesContext, testComponent);
+ }
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/component/util/HtmlUtilTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/component/util/HtmlUtilTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/component/util/HtmlUtilTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,112 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component.util;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 11.04.2007
+ *
+ */
+public class HtmlUtilTest extends TestCase {
+
+ public HtmlUtilTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testQualifySize() throws Exception {
+ assertEquals("", HtmlUtil.qualifySize(""));
+
+ assertEquals("100px", HtmlUtil.qualifySize("100px"));
+ assertEquals("100px", HtmlUtil.qualifySize("100"));
+ assertEquals("100pt", HtmlUtil.qualifySize("100pt"));
+
+ assertEquals("100in", HtmlUtil.qualifySize("100in"));
+ assertEquals("100cm", HtmlUtil.qualifySize("100cm"));
+ assertEquals("100em", HtmlUtil.qualifySize("100em"));
+ assertEquals("100%", HtmlUtil.qualifySize("100%"));
+ }
+
+ public void testAddToSize() throws Exception {
+ assertEquals("120px", HtmlUtil.addToSize("100",
"20px"));
+ assertEquals("120px", HtmlUtil.addToSize("100px",
"20"));
+ assertEquals("120px", HtmlUtil.addToSize("100", "20"));
+ assertEquals("120px", HtmlUtil.addToSize("100px",
"20px"));
+ }
+
+ public void testExpandIdSelector() {
+ String selector = ".class_form+#-Test .class2 #_aaaa";
+
+ UIComponent component = new UIComponentBase() {
+ public String getFamily() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public UIComponent findComponent(String expr) {
+ if ("-Test".equals(expr)) {
+ return new UIComponentBase() {
+ public String getClientId(FacesContext context) {
+ return "component1";
+ }
+ public String getFamily() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ } else if ("_aaaa".equals(expr)) {
+ return new UIComponentBase() {
+ public String getClientId(FacesContext context) {
+ return "component2";
+ }
+ public String getFamily() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ }
+
+ return null;
+ }
+ };
+
+ String string =
+ HtmlUtil.expandIdSelector(selector, component, null);
+
+ assertEquals(".class_form+#component1 .class2 #component2", string);
+
+ String s = ".class_form+.component1 .class2 #1component2";
+ assertEquals(s, HtmlUtil.expandIdSelector(s, component, null));
+ }
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/json/JsonTest.java (from rev
14869, framework/trunk/legacy-tests/src/test/java/org/richfaces/json/JsonTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/json/JsonTest.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/json/JsonTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,166 @@
+/**
+ *
+ */
+package org.richfaces.json;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 12.04.2007
+ *
+ */
+public class JsonTest extends TestCase {
+
+ /**
+ * @param name
+ */
+ public JsonTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testMap() throws Exception {
+ JSONMap map = new JSONMap("{text: 12, moreData: { key: value, key1: 23.04
}}");
+ assertEquals(12, ((Integer) map.get("text")).intValue());
+ assertEquals(2, map.size());
+
+ Map innerMap = (Map) map.get("moreData");
+ assertEquals("value", innerMap.get("key"));
+ assertEquals(23.04, ((Double) innerMap.get("key1")).doubleValue(), 0);
+ assertEquals(2, innerMap.size());
+ }
+
+ public void testCollection() throws Exception {
+ JSONCollection collection = new JSONCollection("[text, { key: value, key1: 23.04
}, [1, a, 3]]");
+ assertEquals(3, collection.size());
+
+ Iterator iterator = collection.iterator();
+ assertTrue(iterator.hasNext());
+
+ assertEquals("text", iterator.next());
+ assertTrue(iterator.hasNext());
+
+ Map innerMap = (Map) iterator.next();
+ assertTrue(iterator.hasNext());
+
+ assertEquals("value", innerMap.get("key"));
+ assertEquals(23.04, ((Double) innerMap.get("key1")).doubleValue(), 0);
+ assertEquals(2, innerMap.size());
+
+ Collection innerCollection = (Collection) iterator.next();
+ assertEquals(3, innerCollection.size());
+ Iterator innerIterator = innerCollection.iterator();
+
+ assertTrue(innerIterator.hasNext());
+ assertEquals(1, ((Integer) innerIterator.next()).intValue());
+ assertTrue(innerIterator.hasNext());
+ assertEquals("a", innerIterator.next());
+ assertTrue(innerIterator.hasNext());
+ assertEquals(3, ((Integer) innerIterator.next()).intValue());
+ assertFalse(innerIterator.hasNext());
+
+ assertFalse(iterator.hasNext());
+ }
+
+ public void testNewCollection() throws Exception {
+ JSONCollection collection = new JSONCollection();
+ assertTrue(collection.isEmpty());
+ }
+
+ public void testNewMap() throws Exception {
+ JSONMap map = new JSONMap();
+ assertTrue(map.isEmpty());
+ }
+
+ public void testMapAddiition() throws Exception {
+ JSONMap map = new JSONMap();
+ Set set = map.entrySet();
+ set.add(new JsonTestMockMapEntry("boolean", new Boolean(true)));
+ set.add(new JsonTestMockMapEntry("double", new Double(23.45)));
+ set.add(new JsonTestMockMapEntry("integer", new Integer(56)));
+ set.add(new JsonTestMockMapEntry("long", new Long(89)));
+ set.add(new JsonTestMockMapEntry("string", "testString"));
+
+ HashSet hashSet = new HashSet();
+
+ hashSet.add("15");
+ hashSet.add(new Double(45.01));
+
+ HashSet etalonSet = (HashSet) hashSet.clone();
+
+
+ HashMap hashMap = new HashMap();
+
+ hashMap.put("16", new Boolean(false));
+ hashMap.put("key", new Double(145.01));
+
+ HashMap etalonMap = (HashMap) hashMap.clone();
+
+ set.add(new JsonTestMockMapEntry("collection", hashSet));
+ set.add(new JsonTestMockMapEntry("map", hashMap));
+
+ assertEquals(Boolean.TRUE, map.get("boolean"));
+ assertEquals(new Double(23.45), map.get("double"));
+ assertEquals(new Integer(56), map.get("integer"));
+ assertEquals(new Long(89), map.get("long"));
+ assertEquals("testString", map.get("string"));
+
+ Collection collection = (Collection) map.get("collection");
+ assertTrue(etalonSet.containsAll(collection));
+ etalonSet.removeAll(collection);
+ assertTrue(etalonSet.isEmpty());
+
+ assertEquals(etalonMap, map.get("map"));
+ }
+
+}
+
+class JsonTestMockMapEntry implements Map.Entry {
+
+ private Object key;
+ private Object value;
+
+
+
+ public JsonTestMockMapEntry(Object key, Object value) {
+ super();
+ this.key = key;
+ this.value = value;
+ }
+
+ public Object getKey() {
+ return key;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public Object setValue(Object newValue) {
+ Object oldValue = value;
+ value = newValue;
+ return oldValue;
+ }
+
+}
\ No newline at end of file
Copied: framework/trunk/impl/src/test/java/org/richfaces/model/FilterFieldTest.java (from
rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/model/FilterFieldTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/FilterFieldTest.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/model/FilterFieldTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,87 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import javax.el.ValueExpression;
+
+import junit.framework.TestCase;
+
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class FilterFieldTest extends TestCase {
+
+ private Field field;
+ private ValueExpression expression;
+
+ /**
+ * @param name
+ */
+ public FilterFieldTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ expression = EasyMock.createNiceMock(ValueExpression.class);
+ field = new FilterField(expression);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ field = null;
+ expression = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.FilterField#FilterField(javax.el.ValueExpression)}.
+ */
+ public final void testFilterField() {
+ Field filterField = new FilterField(expression);
+ assertEquals(filterField, field);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.Field#hashCode()}.
+ */
+ public final void testHashCode() {
+ Field filterField = new FilterField(expression);
+ assertEquals(filterField.hashCode(), field.hashCode());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.Field#equals(java.lang.Object)}.
+ */
+ public final void testEqualsObject() {
+ Field filterField = new FilterField(null);
+ assertFalse(filterField.equals(field));
+ filterField.setExpression(expression);
+ assertTrue(filterField.equals(field));
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.Field#getExpression()}.
+ */
+ public final void testGetExpression() {
+ assertSame(field.getExpression(), expression);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.Field#setExpression(javax.el.ValueExpression)}.
+ */
+ public final void testSetExpression() {
+ field.setExpression(null);
+ assertNull(field.getExpression());
+ }
+
+}
Copied:
framework/trunk/impl/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/ListSequenceDataModelTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,133 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.SequenceRange;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ListSequenceDataModelTest extends TestCase {
+
+ private List<Integer> list;
+ private ListSequenceDataModel model;
+ private ListSequenceDataModel nullModel;
+
+ /**
+ * @param name
+ */
+ public ListSequenceDataModelTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ list = new ArrayList<Integer>();
+ for (int i = 0; i < 10; i++) {
+ list.add(new Integer(i));
+ }
+ model = new ListSequenceDataModel(list);
+ nullModel = new ListSequenceDataModel(null);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ nullModel = null;
+ model = null;
+ list = null;
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ListSequenceDataModel#isRowAvailable()}.
+ */
+ public final void testIsRowAvailable() {
+ assertFalse(nullModel.isRowAvailable());
+ assertTrue(model.isRowAvailable());
+ model.setRowIndex(-1);
+ assertFalse(model.isRowAvailable());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ListSequenceDataModel#getRowCount()}.
+ */
+ public final void testGetRowCount() {
+ assertEquals(model.getRowCount(), list.size());
+ assertEquals(nullModel.getRowCount(), -1);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ListSequenceDataModel#setRowIndex()}
+ * and {@link org.richfaces.model.ListSequenceDataModel#getRowIndex()}.
+ */
+ public final void testRowIndex() {
+ int i = 3;
+ model.setRowIndex(i);
+ assertEquals(model.getRowIndex(), i);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ListSequenceDataModel#setRowKey(java.lang.Object)}
+ * and {@link org.richfaces.model.ListSequenceDataModel#getRowKey(java.lang.Object)}.
+ */
+ public final void testRowKey() {
+ Integer i = 3;
+ model.setRowKey(i);
+ assertEquals(model.getRowKey(), i);
+ model.setRowKey(null);
+ assertNull(model.getRowKey());
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ListSequenceDataModel#walk(javax.faces.context.FacesContext,
org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range, java.lang.Object)}
+ * and {@link org.richfaces.model.ListSequenceDataModel#getRowData()}.
+ */
+ public final void testWalk() {
+ DataVisitor visitor = new DataVisitor(){
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+ Object key = model.getRowKey();
+ model.setRowKey(rowKey);
+ assertEquals(model.getRowData(), list.get(((Integer)rowKey).intValue()));
+ model.setRowKey(key);
+ }
+ };
+ try {
+ SequenceRange range = new SequenceRange(0, -1);
+ model.walk(null, visitor, range, null);
+ range = new SequenceRange(0, 5);
+ model.walk(null, visitor, range, null);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ListSequenceDataModel#ListSequenceDataModel(java.util.List)},
+ * {@link org.richfaces.model.ListSequenceDataModel#setWrappedData(java.lang.Object)}
+ * and {@link org.richfaces.model.ListSequenceDataModel#getWrappedData()} .
+ */
+ public final void testListSequenceDataModel() {
+ assertNull(nullModel.getWrappedData());
+ ListSequenceDataModel dataModel = new ListSequenceDataModel(list);
+ assertSame(dataModel.getWrappedData(), model.getWrappedData());
+
+ }
+
+}
Added: framework/trunk/impl/src/test/java/org/richfaces/model/MockDataModel.java
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/MockDataModel.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/model/MockDataModel.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,170 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model;
+
+import java.io.IOException;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+import org.ajax4jsf.model.SequenceRange;
+
+/**
+ * @author shura
+ *
+ */
+public class MockDataModel extends ExtendedDataModel {
+
+ public static final int ROWS = 10;
+
+ private int rowIndex = 0;
+
+ private int minRow = 0;
+
+ private int maxRow = ROWS;
+
+ private Object wrappedData;
+ /**
+ * @return the maxRow
+ */
+ public int getMaxRow() {
+ return maxRow;
+ }
+
+ /**
+ * @param maxRow the maxRow to set
+ */
+ public void setMaxRow(int maxRow) {
+ this.maxRow = maxRow;
+ }
+
+ /**
+ * @return the minRow
+ */
+ public int getMinRow() {
+ return minRow;
+ }
+
+ /**
+ * @param minRow the minRow to set
+ */
+ public void setMinRow(int minRow) {
+ this.minRow = minRow;
+ }
+
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) throws IOException {
+ int first=0;
+ int count=ROWS;
+ if (range instanceof MockRange) {
+ MockRange mockRange = (MockRange) range;
+ count = mockRange.getCount();
+ } else if (range instanceof SequenceRange) {
+ SequenceRange seqRange = (SequenceRange) range;
+ first = seqRange.getFirstRow();
+ int rows = seqRange.getRows();
+ if(rows>0){
+ count = rows+first;
+ }
+ }
+ for(int row = first; row < count && row < ROWS;row++){
+ visitor.process(context, new Integer(row), argument);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.ajax.repeat.ExtendedDataModel#getRowKey()
+ */
+ public Object getRowKey() {
+ // TODO Auto-generated method stub
+ return rowIndex<0?null:new Integer(rowIndex);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.ajax.repeat.ExtendedDataModel#setRowKey(java.lang.Object)
+ */
+ public void setRowKey(Object key) {
+ if(null == key){
+ rowIndex = -1;
+ } else {
+ rowIndex = ((Integer) key).intValue();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ public int getRowCount() {
+ // TODO Auto-generated method stub
+ return getMaxRow();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowData()
+ */
+ public Object getRowData() {
+ // TODO Auto-generated method stub
+ return isRowAvailable()?String.valueOf(rowIndex):null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+ public int getRowIndex() {
+ // TODO Auto-generated method stub
+ return rowIndex;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ // TODO Auto-generated method stub
+ return wrappedData;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ // TODO Auto-generated method stub
+ return rowIndex>=getMinRow() && rowIndex<getMaxRow();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ public void setRowIndex(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ wrappedData = data;
+ }
+
+}
Added: framework/trunk/impl/src/test/java/org/richfaces/model/MockRange.java
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/MockRange.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/model/MockRange.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,41 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model;
+
+import org.ajax4jsf.model.Range;
+
+/**
+ * @author shura
+ *
+ */
+public class MockRange implements Range {
+
+ private int count;
+
+ public MockRange(int count) {
+ this.count = count;
+ }
+
+ public int getCount(){
+ return count;
+ }
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/model/ModifiableModelTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/model/ModifiableModelTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/ModifiableModelTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/ModifiableModelTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,107 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModelListener;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.SequenceRange;
+import org.easymock.classextension.EasyMock;
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ModifiableModelTest extends AbstractFacesTest {
+
+ private ModifiableModel model;
+ private ExtendedDataModel originalModel;
+ private String var;
+ private List<FilterField> filterFields;
+ private List<SortField2> sortFields;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ var = "var";
+ originalModel = new MockDataModel();
+ filterFields = new LinkedList<FilterField>();
+ sortFields = new LinkedList<SortField2>();
+ model = new ModifiableModel(originalModel, var);
+ model.modify(filterFields, sortFields);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ model = null;
+ var = null;
+ filterFields = null;
+ sortFields = null;
+ originalModel = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#walk(javax.faces.context.FacesContext,
org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range, java.lang.Object)}.
+ */
+ public final void testWalk() {
+ SequenceRange range = new SequenceRange(0, -1);
+ DataVisitor visitor = new DataVisitor(){
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+ Object key = model.getRowKey();
+ model.setRowKey(rowKey);
+ Object key2 = originalModel.getRowKey();
+ originalModel.setRowKey(rowKey);
+ assertEquals(model.getRowData(), originalModel.getRowData());
+ model.setRowKey(key);
+ originalModel.setRowKey(key2);
+ }
+ };
+ try {
+ model.walk(null, visitor, range, null);
+ ValueExpression expression =
+ facesContext.getApplication().getExpressionFactory().createValueExpression(Boolean.TRUE,
Boolean.class);
+ filterFields.add(new FilterField(expression));
+ sortFields.add(new SortField2(expression, Ordering.ASCENDING));
+ model.walk(null, visitor, range, null);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#addDataModelListener(javax.faces.model.DataModelListener)}.
+ */
+ public final void testAddDataModelListenerDataModelListener() {
+ DataModelListener mockedListener = EasyMock.createNiceMock(DataModelListener.class);
+ model.addDataModelListener(mockedListener);
+ assertEquals(model.getDataModelListeners()[0], mockedListener);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#removeDataModelListener(javax.faces.model.DataModelListener)}.
+ */
+ public final void testRemoveDataModelListenerDataModelListener() {
+ DataModelListener mockedListener = EasyMock.createNiceMock(DataModelListener.class);
+ model.addDataModelListener(mockedListener);
+ assertSame(model.getDataModelListeners()[0], mockedListener);
+ model.removeDataModelListener(mockedListener);
+ assertEquals(model.getDataModelListeners().length, 0);
+ }
+
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/model/SortField2Test.java (from
rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/model/SortField2Test.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/SortField2Test.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/model/SortField2Test.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,99 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import javax.el.ValueExpression;
+
+import junit.framework.TestCase;
+
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class SortField2Test extends TestCase {
+
+ private SortField2 field;
+ private ValueExpression expression;
+ private Ordering ordering;
+ /**
+ * @param name
+ */
+ public SortField2Test(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ expression = EasyMock.createNiceMock(ValueExpression.class);
+ ordering = Ordering.ASCENDING;
+ field = new SortField2(expression, ordering);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ field = null;
+ ordering = null;
+ expression = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.SortField2#hashCode()}.
+ */
+ public final void testHashCode() {
+ Field sortField = new SortField2(expression, ordering);
+ assertEquals(sortField.hashCode(), field.hashCode());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.SortField2#equals(java.lang.Object)}.
+ */
+ public final void testEqualsObject() {
+ SortField2 sortField = new SortField2(null);
+ assertFalse(sortField.equals(field));
+ sortField.setExpression(expression);
+ sortField.setOrdering(ordering);
+ assertTrue(sortField.equals(field));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.SortField2#SortField2(javax.el.ValueExpression)}.
+ */
+ public final void testSortField2ValueExpression() {
+ SortField2 sortField2 = new SortField2(expression);
+ field.setOrdering(null);
+ assertEquals(sortField2, field);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.SortField2#SortField2(javax.el.ValueExpression,
org.richfaces.model.Ordering)}.
+ */
+ public final void testSortField2ValueExpressionOrdering() {
+ SortField2 sortField2 = new SortField2(expression, ordering);
+ assertEquals(sortField2, field);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.SortField2#getOrdering()}.
+ */
+ public final void testGetOrdering() {
+ assertEquals(field.getOrdering(), ordering);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.SortField2#setOrdering(org.richfaces.model.Ordering)}.
+ */
+ public final void testSetOrdering() {
+ field.setOrdering(null);
+ assertNull(field.getOrdering());
+ }
+
+}
Copied:
framework/trunk/impl/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/StackingTreeDataModelTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,450 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.richfaces.model.entity.Directory;
+import org.richfaces.model.entity.File;
+import org.richfaces.model.entity.Named;
+import org.richfaces.model.entity.Project;
+import org.richfaces.test.AbstractFacesTest;
+
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class StackingTreeDataModelTest extends AbstractFacesTest {
+
+ private StackingTreeModel stackingTreeModel;
+ private StackingTreeModel projectsModel;
+ private StackingTreeModel directoriesModel;
+ private StackingTreeModel filesModel;
+
+ private Object projectRequestObject;
+ private Object directoryRequestObject;
+ private Object fileRequestObject;
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ this.stackingTreeModel = new StackingTreeModel();
+ projectsModel = new StackingTreeModel("project", "project", new
StackingTreeModelDataProvider() {
+
+ private Map<String, Project> data = null;
+
+ public Object getData() {
+ if (data == null) {
+ data = new LinkedHashMap<String, Project>();
+ Project projectA = new Project("projectA", 10);
+
+ Directory adir1 = new Directory("ADir1", 50);
+
+ adir1.addFile(new File("AFile1", 60));
+ adir1.addFile(new File("AFile2", 61));
+
+ Directory adir2 = new Directory("ADir2", 101);
+
+ projectA.addDirectory(adir1);
+ projectA.addDirectory(adir2);
+
+ data.put(projectA.getName(), projectA);
+
+ Project projectB = new Project("projectB", 501);
+
+ Directory bdir1 = new Directory("BDir1", 600);
+ Directory bdir2 = new Directory("BDir2", 700);
+ Directory bdir3 = new Directory("BDir3", 801);
+
+ projectB.addDirectory(bdir1);
+ projectB.addDirectory(bdir2);
+ projectB.addDirectory(bdir3);
+
+ data.put(projectB.getName(), projectB);
+ }
+ return data;
+ }
+ });
+ final ValueBinding dirVB =
application.createValueBinding("#{project.directories}");
+ directoriesModel = new StackingTreeModel("directory", "directory",
new StackingTreeModelDataProvider() {
+ public Object getData() {
+ return dirVB.getValue(facesContext);
+ }
+ });
+ final ValueBinding fileVB =
application.createValueBinding("#{directory.files}");
+ filesModel = new StackingTreeModel("file", "file", new
StackingTreeModelDataProvider() {
+ public Object getData() {
+ return fileVB.getValue(facesContext);
+ }
+ });
+ directoriesModel.addStackingModel(filesModel);
+ projectsModel.addStackingModel(directoriesModel);
+ this.stackingTreeModel.addStackingModel(projectsModel);
+
+ projectRequestObject = new Object();
+ directoryRequestObject = new Object();
+ fileRequestObject = new Object();
+
+ Map<String, Object> requestMap =
facesContext.getExternalContext().getRequestMap();
+ requestMap.put("project", projectRequestObject);
+ requestMap.put("directory", directoryRequestObject);
+ requestMap.put("file", fileRequestObject);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ this.stackingTreeModel = null;
+ this.projectsModel = null;
+ this.directoriesModel = null;
+ this.filesModel = null;
+
+ this.projectRequestObject = null;
+ this.directoryRequestObject = null;
+ this.fileRequestObject = null;
+ }
+
+ public void testWalk() throws Exception {
+ StackingTreeDataModelTestVisitor1 visitor1 = new StackingTreeDataModelTestVisitor1();
+ this.stackingTreeModel.walk(facesContext, visitor1, null, null);
+ assertEquals(9, visitor1.getCounter());
+ this.stackingTreeModel.setRowKey(null);
+ assertFalse(this.stackingTreeModel.isRowAvailable());
+
+ Map<String, Object> requestMap =
facesContext.getExternalContext().getRequestMap();
+ assertSame(this.projectRequestObject, requestMap.get("project"));
+ assertSame(this.directoryRequestObject, requestMap.get("directory"));
+ assertSame(this.fileRequestObject, requestMap.get("file"));
+ }
+
+ public void testBadKey() throws Exception {
+ StackingTreeDataModelTestVisitor1 visitor1 = new StackingTreeDataModelTestVisitor1();
+ this.stackingTreeModel.walk(facesContext, visitor1, null, null);
+ this.stackingTreeModel.setRowKey(new ListRowKey(new
StackingTreeModelKey("project", "projectA")));
+ assertTrue(this.stackingTreeModel.isRowAvailable());
+ assertNotNull(this.stackingTreeModel.getRowData());
+
+ assertNull(this.stackingTreeModel.getTreeNode());
+ assertFalse(this.stackingTreeModel.isLeaf());
+
+ this.stackingTreeModel.setRowKey(new ListRowKey(new
StackingTreeModelKey("project", "projectAAAAA")));
+ assertFalse(this.stackingTreeModel.isRowAvailable());
+ try {
+ Object rowData = this.stackingTreeModel.getRowData();
+ assertNull(rowData);
+ //FIXME: Maksim - bad keys happen for a reason
+ //fail();
+ } catch (Exception e) {
+
+ }
+
+ try {
+ boolean leaf = this.stackingTreeModel.isLeaf();
+ assertTrue(leaf);
+ //FIXME: Maksim - bad keys happen for a reason
+ //fail();
+ } catch (Exception e) {
+
+ }
+
+ try {
+ TreeNode node = this.stackingTreeModel.getTreeNode();
+ assertNull(node);
+ //FIXME: Maksim - bad keys happen for a reason
+ //fail();
+ } catch (Exception e) {
+
+ }
+ }
+
+ public void testActiveData() throws Exception {
+ final ValueBinding fileVB =
application.createValueBinding("#{directory.files}");
+ StackingTreeModel localFilesModel = new StackingTreeModel("file",
"file", new StackingTreeModelDataProvider() {
+ public Object getData() {
+ return fileVB.getValue(facesContext);
+ }
+
+ }) {
+ protected boolean isActiveData() {
+ Map requestMap = facesContext.getExternalContext().getRequestMap();
+ Object object = requestMap.get("file");
+ assertNotNull(object);
+ File file = (File) object;
+ if (file.getTag() == 61) {
+ return false;
+ }
+
+ return super.isActiveData();
+ }
+ };
+ directoriesModel.removeStackingModel(filesModel);
+ directoriesModel.addStackingModel(localFilesModel);
+
+ stackingTreeModel.walk(facesContext, new StackingTreeDataModelTestVisitor3(), null,
null);
+ }
+
+ public void testKey() throws Exception {
+ StackingTreeModelKey key = new StackingTreeModelKey("aaa", new Integer(10));
+ StackingTreeModelKey key2 = new StackingTreeModelKey("aaa", new
Integer(11));
+ StackingTreeModelKey key3 = new StackingTreeModelKey("aaa", new
Integer(10));
+ StackingTreeModelKey key4 = new StackingTreeModelKey("bbb", new
Integer(10));
+
+ assertFalse(key.equals(new StackingTreeModelKey("aaa", new Integer(0)) {}
));
+
+ assertTrue(key.equals(key3));
+ assertTrue(key3.equals(key));
+ assertTrue(key2.equals(key2));
+ assertTrue(key4.equals(key4));
+
+ assertTrue(key.hashCode() == key3.hashCode());
+ assertTrue(key3.hashCode() == key.hashCode());
+ assertTrue(key2.hashCode() == key2.hashCode());
+ assertTrue(key4.hashCode() == key4.hashCode());
+
+ assertFalse(key.equals(key2));
+ assertFalse(key3.equals(key2));
+ assertFalse(key2.equals(key));
+ assertFalse(key2.equals(key3));
+
+ assertFalse(key.hashCode() == key2.hashCode());
+ assertFalse(key3.hashCode() == key2.hashCode());
+ assertFalse(key2.hashCode() == key.hashCode());
+ assertFalse(key2.hashCode() == key3.hashCode());
+
+ assertFalse(key4.equals(key));
+ assertFalse(key4.equals(key2));
+ assertFalse(key4.equals(key3));
+
+ assertFalse(key4.hashCode() == key.hashCode());
+ assertFalse(key4.hashCode() == key2.hashCode());
+ assertFalse(key4.hashCode() == key3.hashCode());
+
+ assertFalse(key.equals(key4));
+ assertFalse(key2.equals(key4));
+ assertFalse(key3.equals(key4));
+
+ assertFalse(new StackingTreeModelKey("aaa", new Integer(10)).equals(null));
+ assertFalse(new StackingTreeModelKey("aaa", null).equals(null));
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).equals(null));
+ assertFalse(new StackingTreeModelKey(null, null).equals(null));
+
+ assertFalse(key.hashCode() == key4.hashCode());
+ assertFalse(key2.hashCode() == key4.hashCode());
+ assertFalse(key3.hashCode() == key4.hashCode());
+
+ assertFalse(key.hashCode() == 0);
+ assertFalse(key2.hashCode() == 0);
+ assertFalse(key3.hashCode() == 0);
+ assertFalse(key4.hashCode() == 0);
+
+ assertTrue(new StackingTreeModelKey(null, new Integer(11)).equals(new
StackingTreeModelKey(null, new Integer(11))));
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).equals(new
StackingTreeModelKey(null, new Integer(11))));
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).equals(new
StackingTreeModelKey("aaa", new Integer(10))));
+
+ assertTrue(new StackingTreeModelKey(null, new Integer(11)).hashCode() == new
StackingTreeModelKey(null, new Integer(11)).hashCode());
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).hashCode() == new
StackingTreeModelKey(null, new Integer(11)).hashCode());
+ assertFalse(new StackingTreeModelKey(null, new Integer(10)).hashCode() == new
StackingTreeModelKey("aaa", new Integer(10)).hashCode());
+
+ assertTrue(new StackingTreeModelKey("aaa", null).equals(new
StackingTreeModelKey("aaa", null)));
+ assertFalse(new StackingTreeModelKey("aaa", null).equals(new
StackingTreeModelKey("bbb", null)));
+ assertFalse(new StackingTreeModelKey("aaa", null).equals(new
StackingTreeModelKey("aaa", new Integer(10))));
+
+ assertTrue(new StackingTreeModelKey("aaa", null).hashCode() == new
StackingTreeModelKey("aaa", null).hashCode());
+ assertFalse(new StackingTreeModelKey("aaa", null).hashCode() == new
StackingTreeModelKey("bbb", null).hashCode());
+ assertFalse(new StackingTreeModelKey("aaa", null).hashCode() == new
StackingTreeModelKey("aaa", new Integer(10)).hashCode());
+ }
+
+ class StackingTreeDataModelTestVisitor1 implements DataVisitor, LastElementAware {
+
+ private boolean last;
+ private int tag = 0;
+ private int counter = 0;
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ StackingTreeDataModelTestVisitor2 visitor2 = new StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor2, null, new ListRowKey(new
StackingTreeModelKey("project", "projectA")),
+ argument, false);
+
+ assertEquals(5, visitor2.getCounter());
+
+ StackingTreeDataModelTestVisitor2 visitor20 = new
StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor20, new TreeRange() {
+
+ public boolean processChildren(TreeRowKey rowKey) {
+ return false;
+ }
+
+ public boolean processNode(TreeRowKey rowKey) {
+ return false;
+ }
+
+ }, new ListRowKey(new StackingTreeModelKey("project",
"projectA")),
+ argument, false);
+
+ assertEquals(0, visitor20.getCounter());
+
+ StackingTreeDataModelTestVisitor2 visitor21 = new
StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor21, new TreeRange() {
+
+ public boolean processChildren(TreeRowKey rowKey) {
+ return false;
+ }
+
+ public boolean processNode(TreeRowKey rowKey) {
+ return true;
+ }
+
+ }, new ListRowKey(new StackingTreeModelKey("project",
"projectA")),
+ argument, false);
+
+ assertEquals(1, visitor21.getCounter());
+
+ StackingTreeDataModelTestVisitor2 visitor22 = new
StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor22, null, new ListRowKey(new
StackingTreeModelKey("project", "projectB")),
+ argument, false);
+
+ assertEquals(4, visitor22.getCounter());
+
+ StackingTreeDataModelTestVisitor2 visitor23 = new
StackingTreeDataModelTestVisitor2();
+
+ stackingTreeModel.walk(context, visitor23, new TreeRange() {
+
+ private boolean rootProcessed = false;
+
+ public boolean processChildren(TreeRowKey rowKey) {
+ boolean result = rootProcessed;
+ rootProcessed = true;
+ return !result;
+ }
+
+ public boolean processNode(TreeRowKey rowKey) {
+ return true;
+ }
+
+ }, new ListRowKey(new StackingTreeModelKey("project",
"projectB")),
+ argument, false);
+
+ assertEquals(4, visitor23.getCounter());
+
+ stackingTreeModel.setRowKey(rowKey);
+
+ assertSame(rowKey, stackingTreeModel.getRowKey());
+
+ assertNull(stackingTreeModel.getTreeNode());
+ Object rowData = stackingTreeModel.getRowData();
+ assertNotNull(rowData);
+ assertTrue(rowData instanceof Named);
+
+ Named named = (Named) rowData;
+
+ int currentTag = named.getTag();
+ assertTrue(currentTag > tag);
+ this.tag = currentTag;
+
+ if (this.tag % 10 == 1) {
+ assertTrue(last);
+ } else {
+ assertFalse(last);
+ }
+
+ if (named instanceof Directory) {
+ if ("ADir1".equals(named.getName())) {
+ assertFalse(stackingTreeModel.isLeaf());
+ } else {
+ assertTrue(stackingTreeModel.isLeaf());
+ }
+ } else if (named instanceof Project) {
+ assertFalse(stackingTreeModel.isLeaf());
+ } else if (named instanceof File) {
+ assertTrue(stackingTreeModel.isLeaf());
+ } else {
+ fail();
+ }
+
+ counter++;
+ }
+
+ public void resetLastElement() {
+ this.last = false;
+ }
+
+ public void setLastElement() {
+ this.last = true;
+ }
+
+ public int getCounter() {
+ return counter;
+ }
+ }
+
+ class StackingTreeDataModelTestVisitor2 implements DataVisitor {
+ private int counter = 0;
+ private int tag = 0;
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ stackingTreeModel.setRowKey(rowKey);
+ Object rowData = stackingTreeModel.getRowData();
+ assertNotNull(rowData);
+ Named named = (Named) rowData;
+
+ int currentTag = named.getTag();
+ assertTrue(currentTag > tag);
+ tag = currentTag;
+ counter++;
+ }
+
+ public int getCounter() {
+ return counter;
+ }
+ }
+
+ class StackingTreeDataModelTestVisitor3 implements DataVisitor, LastElementAware {
+
+ private boolean last;
+
+ public void process(FacesContext context, Object rowKey, Object argument)
+ throws IOException {
+
+ stackingTreeModel.setRowKey(rowKey);
+ Named named = (Named) stackingTreeModel.getRowData();
+ int tag = named.getTag();
+
+ if (tag == 60) {
+ assertTrue(last);
+ }
+ assertFalse(tag == 61);
+ }
+
+ public void resetLastElement() {
+ this.last = false;
+ }
+
+ public void setLastElement() {
+ this.last = true;
+ }
+ }
+}
+
Copied: framework/trunk/impl/src/test/java/org/richfaces/model/entity/Directory.java (from
rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/model/entity/Directory.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/entity/Directory.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/entity/Directory.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,30 @@
+/**
+ *
+ */
+package org.richfaces.model.entity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class Directory extends Named {
+
+ public Directory(String name, int tag) {
+ super(name, tag);
+ }
+
+ private List files = new ArrayList();
+
+ public List getFiles() {
+ return files;
+ }
+
+ public void addFile(File file) {
+ this.files.add(file);
+ }
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/model/entity/File.java (from rev
14869, framework/trunk/legacy-tests/src/test/java/org/richfaces/model/entity/File.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/entity/File.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/model/entity/File.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.richfaces.model.entity;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class File extends Named {
+
+ public File(String name, int tag) {
+ super(name, tag);
+ }
+
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/model/entity/Named.java (from rev
14869, framework/trunk/legacy-tests/src/test/java/org/richfaces/model/entity/Named.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/entity/Named.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/model/entity/Named.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,27 @@
+/**
+ *
+ */
+package org.richfaces.model.entity;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class Named {
+ private String name;
+ private int tag;
+ public String getName() {
+ return name;
+ }
+ public int getTag() {
+ return tag;
+ }
+ public Named(String name, int tag) {
+ super();
+ this.name = name;
+ this.tag = tag;
+ }
+
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/model/entity/Project.java (from
rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/model/entity/Project.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/model/entity/Project.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/model/entity/Project.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,29 @@
+/**
+ *
+ */
+package org.richfaces.model.entity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 30.07.2007
+ *
+ */
+public class Project extends Named {
+ public Project(String name, int tag) {
+ super(name, tag);
+ }
+
+ private List directories = new ArrayList();
+
+ public List getDirectories() {
+ return directories;
+ }
+
+ public void addDirectory(Directory directory) {
+ directories.add(directory);
+ }
+}
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/JavaBeanWrapperTest.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/JavaBeanWrapperTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/JavaBeanWrapperTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,78 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.richfaces.model.impl.expressive.JavaBeanWrapper;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaBeanWrapperTest extends TestCase {
+
+
+ private JavaBeanWrapper wrapper;
+ final Boolean test = Boolean.TRUE;
+ final Map props = Collections.singletonMap("true", test);
+ /**
+ * @param name
+ */
+ public JavaBeanWrapperTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ wrapper = new JavaBeanWrapper(test, props);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ wrapper = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.JavaBeanWrapper#getProperty(java.lang.String)}.
+ */
+ public void testGetProperty() {
+ assertEquals(test, wrapper.getProperty("true"));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.JavaBeanWrapper#getWrappedObject()}.
+ */
+ public void testGetWrappedObject() {
+ assertEquals(test, wrapper.getWrappedObject());
+ }
+
+}
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/MethodBindingExpressionTest.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/MethodBindingExpressionTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/MethodBindingExpressionTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,49 @@
+/**
+ *
+ */
+package org.richfaces.model.impl.expressive;
+
+import javax.el.ELContext;
+import javax.el.MethodExpression;
+import javax.faces.context.FacesContext;
+
+import junit.framework.TestCase;
+
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class MethodBindingExpressionTest extends TestCase {
+
+ /**
+ * @param name
+ */
+ public MethodBindingExpressionTest(String name) {
+ super(name);
+ }
+
+ private MethodExpression createMockMethodExpression(String returnValue) {
+ MethodExpression expression = EasyMock.createNiceMock(MethodExpression.class);
+ EasyMock.expect(expression.invoke((ELContext) EasyMock.anyObject(),
+ (Object[]) EasyMock.anyObject())).andReturn(returnValue);
+
+ EasyMock.replay(expression);
+ return expression;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.MethodBindingExpression#MethodBindingExpression(javax.faces.context.FacesContext,
javax.el.MethodExpression)}
+ * and {@link
org.richfaces.model.impl.expressive.MethodBindingExpression#evaluate(java.lang.Object)}.
+ */
+ public final void testMethodBindingExpression() {
+ String expression = "expression";
+ MethodBindingExpression methodBindingExpression = new MethodBindingExpression(
+ EasyMock.createNiceMock(FacesContext.class),
+ createMockMethodExpression(expression));
+
+ assertEquals(methodBindingExpression.evaluate(null), expression);
+ }
+
+}
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/NamedObject.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/NamedObject.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/NamedObject.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,45 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+public class NamedObject {
+ private String name;
+
+ /**
+ *
+ */
+ public NamedObject() {
+ }
+
+ public NamedObject(String name) {
+ this.name = name;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
\ No newline at end of file
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/NullExpressionTest.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/NullExpressionTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/NullExpressionTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,66 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import org.richfaces.model.impl.expressive.Expression;
+import org.richfaces.model.impl.expressive.NullExpression;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class NullExpressionTest extends TestCase {
+
+
+ private Expression expression;
+
+ /**
+ * @param name
+ */
+ public NullExpressionTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ expression = new NullExpression("_id2");
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ expression = null;
+ }
+
+ public void testEvaluate() {
+ Object o = new Object();
+ assertNull(expression.evaluate(o));
+ }
+
+}
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/ObjectWrapperFactoryTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,195 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Random;
+
+import org.richfaces.model.SortField;
+import org.richfaces.model.SortOrder;
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ObjectWrapperFactoryTest extends AbstractFacesTest {
+
+
+ /**
+ *
+ */
+ SortField [] sortFields;
+ SortOrder sortOrder;
+ private ObjectWrapperFactory factory;
+ private String var = "abc";
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ sortFields = new SortField[3];
+ sortFields[0] = new SortField("_id1", Boolean.TRUE);
+ sortFields[1] = new SortField("name", Boolean.FALSE);
+ sortFields[2] = new SortField("#{" +var + ".name}", Boolean.TRUE);
+ sortOrder = new SortOrder(sortFields);
+
+ factory = new ObjectWrapperFactory(facesContext, var, sortOrder);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ sortFields = null;
+ sortOrder = null;
+ factory = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#convertList(java.util.List,
org.richfaces.model.impl.expressive.ObjectWrapperFactory.ObjectConvertor)}.
+ */
+ public final void testConvertList() {
+
+
+ List objects = new ArrayList();
+ objects.add(Boolean.TRUE);
+ int size = objects.size();
+ factory.convertList(objects, new ObjectWrapperFactory.ObjectConvertor() {
+ public Object convert(Object o ) {
+
+ return new Boolean(!((Boolean) o).booleanValue());
+ }
+ });
+
+ assertEquals(size, objects.size());
+ assertEquals(Boolean.FALSE, objects.get(0));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#unwrapList(java.util.List)}.
+ */
+ public final void testUnwrapList() {
+ List objects = new ArrayList(10);
+ int [] ints = new int[10];
+ Random random = new Random();
+ for(int i = 0; i < 10; i++) {
+ ints[i] = random.nextInt();
+ objects.add(new NamedObject(String.valueOf(ints[i])));
+ }
+
+ List l1 = factory.wrapList(objects);
+ List l2 = factory.unwrapList(l1);
+
+ assertSame(objects, l1);
+ assertSame(objects, l2);
+ assertEquals(10, l2.size());
+
+ for(int i = 0; i < 10; i++) {
+ NamedObject t = (NamedObject) l2.get(i);
+ assertEquals(String.valueOf(ints[i]), t.getName());
+ }
+
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#unwrapObject(java.lang.Object)}.
+ */
+ public final void testUnwrapObject() {
+
+ NamedObject t = new NamedObject("20");
+
+ JavaBeanWrapper wrapper = new JavaBeanWrapper(t, new HashMap());
+
+ Object wrapped = factory.unwrapObject(wrapper);
+
+ assertSame(t, wrapped);
+
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#wrapList(java.util.List)}.
+ */
+ public final void testWrapList() {
+ List objects = new ArrayList(10);
+ int [] ints = new int[10];
+ Random random = new Random();
+ for(int i = 0; i < 10; i++) {
+ ints[i] = random.nextInt();
+ objects.add(new NamedObject(String.valueOf(ints[i])));
+ }
+
+ List l1 = factory.wrapList(objects);
+
+ assertSame(objects, l1);
+ assertEquals(10, l1.size());
+
+ for(int i = 0; i < 10; i++) {
+ JavaBeanWrapper wrapper = (JavaBeanWrapper) l1.get(i);
+ NamedObject t = (NamedObject) wrapper.getWrappedObject();
+
+ String string = String.valueOf(ints[i]);
+
+ assertEquals(string, t.getName());
+
+ Object prop1 = wrapper.getProperty("name");
+ //Object prop2 = wrapper.getProperty("#{abc.name}");
+
+ assertNotNull(prop1);
+ //assertNotNull(prop2);
+ assertEquals(string, prop1);
+ //assertEquals(string, prop2);
+ }
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ObjectWrapperFactory#wrapObject(java.lang.Object)}.
+ */
+ public final void testWrapObject() {
+ NamedObject t = new NamedObject("20");
+
+
+
+ JavaBeanWrapper wrapper = factory.wrapObject(t);
+
+ Object wrapped = wrapper.getWrappedObject();
+
+ assertSame(t, wrapped);
+
+ Object prop1 = wrapper.getProperty("name");
+ //Object prop2 = wrapper.getProperty("#{abc.name}");
+
+ assertNotNull(prop1);
+ //assertNotNull(prop2);
+ assertEquals("20", prop1);
+ //assertEquals("20", prop2);
+
+
+ }
+
+}
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/SimplePropertyExpressionTest.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/SimplePropertyExpressionTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/SimplePropertyExpressionTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,69 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimplePropertyExpressionTest extends AbstractFacesTest {
+
+ final static String property = "name";
+ private SimplePropertyExpression expression;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ expression = new SimplePropertyExpression("name",
facesContext.getELContext(), application.getELResolver());
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ expression = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.SimplePropertyExpression#evaluate(java.lang.Object)}.
+ */
+ public final void testEvaluate() {
+ NamedObject testObj = new NamedObject("aaaa");
+ Object prop = expression.evaluate(testObj);
+ assertNotNull(prop);
+ assertEquals("aaaa", prop);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.Expression#getExpressionString()}.
+ */
+ public final void testGetExpressionString() {
+ assertEquals(property, expression.getExpressionString());
+ }
+
+}
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/ValueBindingExpressionTest.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/ValueBindingExpressionTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/ValueBindingExpressionTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,70 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ValueBindingExpressionTest extends AbstractFacesTest {
+
+ private ValueBindingExpression expression;
+ static final String var = "obj";
+ static final String el = "#{" + var + ".name}";
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ expression = new ValueBindingExpression(facesContext, el, var);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ expression = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.ValueBindingExpression#evaluate(java.lang.Object)}.
+ */
+ public final void testEvaluate() {
+ NamedObject testObj = new NamedObject("aaaa");
+ Object prop = expression.evaluate(testObj);
+ //assertNotNull(prop);
+ //assertEquals("aaaa", prop);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.Expression#getExpressionString()}.
+ */
+ public final void testGetExpressionString() {
+ assertEquals(el, expression.getExpressionString());
+ }
+
+}
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanComparatorTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,102 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.model.impl.expressive;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.richfaces.model.SortField;
+import org.richfaces.model.impl.expressive.JavaBeanWrapper;
+import org.richfaces.model.impl.expressive.WrappedBeanComparator;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class WrappedBeanComparatorTest extends TestCase {
+
+ private SortField[] sortFields;
+ private WrappedBeanComparator comparator;
+
+ private static final int [][] testData = {{0,0}, {0,1}, {1, 0}, {1, 1} };
+
+ private JavaBeanWrapper [] testWrapers;
+
+ public WrappedBeanComparatorTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ sortFields = new SortField[2];
+ sortFields[0] = new SortField("a", Boolean.FALSE);
+ sortFields[1] = new SortField("b", Boolean.TRUE);
+
+
+ comparator = new WrappedBeanComparator(sortFields);
+
+ testWrapers = new JavaBeanWrapper[testData.length];
+ for(int i = 0; i < testData.length; i++) {
+ testWrapers[i] = w(testData[i]);
+ }
+
+ }
+
+ private JavaBeanWrapper w(int [] ints) {
+ Map m = new HashMap();
+ m.put("a", new Integer(ints[0]));
+ m.put("b", new Integer(ints[1]));
+
+ return new JavaBeanWrapper(m, m);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ sortFields = null;
+ comparator = null;
+ testWrapers = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.WrappedBeanComparator#compare(java.lang.Object,
java.lang.Object)}.
+ */
+ public final void testCompare() {
+
+ assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+ assertTrue(comparator.compare(w(new int[] {1, 1}), w(new int [] {0, 0})) < 0);
+ assertTrue(comparator.compare(w(new int[] {0, 0}), w(new int [] {0, 1})) < 0);
+ assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 0})) == 0);
+ //assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+ //assertTrue(comparator.compare(w(new int[] {1, 0}), w(new int [] {1, 1})) < 0);
+
+ }
+
+}
Added:
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,88 @@
+/**
+ *
+ */
+package org.richfaces.model.impl.expressive;
+
+import java.util.IdentityHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+
+import junit.framework.TestCase;
+
+import org.easymock.classextension.EasyMock;
+import org.richfaces.model.FilterField;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class WrappedBeanFilterTest extends TestCase {
+
+ private List<FilterField> filterFields;
+ private WrappedBeanFilter filter;
+
+ private ValueExpression keyTrue = createMockExpression("keyTrue");
+ private ValueExpression keyFalse = createMockExpression("keyFalse");
+
+ private ValueExpression createMockExpression(String value) {
+ ValueExpression expression = EasyMock.createNiceMock(ValueExpression.class);
+ EasyMock.expect(expression.getValue((ELContext)
EasyMock.anyObject())).andReturn(value);
+ EasyMock.replay(expression);
+ return expression;
+ }
+
+ /**
+ * @param name
+ */
+ public WrappedBeanFilterTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ filterFields = new LinkedList<FilterField>();
+ filterFields.add(new FilterField(keyTrue));
+ filter = new WrappedBeanFilter(filterFields);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ filter = null;
+ filterFields = null;
+ keyTrue = null;
+ keyFalse = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.WrappedBeanFilter#WrappedBeanFilter(java.util.List)}.
+ */
+ public final void testWrappedBeanFilter() {
+ WrappedBeanFilter beanFilter = new WrappedBeanFilter(filterFields);
+ assertNotNull(beanFilter);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.impl.expressive.WrappedBeanFilter#accept(org.richfaces.model.impl.expressive.JavaBeanWrapper)}.
+ */
+ public final void testAccept() {
+ NamedObject obj = new NamedObject("TestObj");
+ Map<Object, Object> props = new IdentityHashMap<Object, Object>();
+ props.put(keyTrue, Boolean.TRUE);
+ props.put(keyFalse, Boolean.FALSE);
+ JavaBeanWrapper wrapper = new JavaBeanWrapper(obj, props);
+ assertTrue(filter.accept(wrapper));
+ filterFields.add(new FilterField(keyFalse));
+ assertFalse(filter.accept(wrapper));
+ }
+
+}
Copied:
framework/trunk/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/renderkit/CompositeRendererTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,483 @@
+package org.richfaces.renderkit;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.Map;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.resource.InternetResource;
+import org.richfaces.test.AbstractFacesTest;
+
+public class CompositeRendererTest extends AbstractFacesTest {
+
+ private CompositeRenderer compositeRenderer;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+
+ this.compositeRenderer = new CompositeRenderer() {
+
+ protected Class getComponentClass() {
+ return UIComponent.class;
+ }
+ };
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ this.compositeRenderer = null;
+ }
+
+ public final void testDoDecodeFacesContextUIComponent() {
+ MockDecodeContributor[] contributors = new MockDecodeContributor[5];
+ for (int i = 0; i < contributors.length; i++) {
+ contributors[i] = new MockDecodeContributor();
+ compositeRenderer.addContributor(contributors[i]);
+ }
+
+ UIInput component = new UIInput();
+ compositeRenderer.doDecode(facesContext, component);
+
+ for (int i = 0; i < contributors.length; i++) {
+ assertSame(compositeRenderer, contributors[i].getRenderer());
+ assertSame(facesContext, contributors[i].getContext());
+ assertSame(component, contributors[i].getComponent());
+ }
+ }
+
+ public final void testMergeScriptOptionsScriptOptionsFacesContextUIComponent() {
+ UIInput input = new UIInput();
+
+ ScriptOptions inputOptions = new ScriptOptions(input);
+ inputOptions.addOption("input", "1");
+
+ ScriptOptions formOptions = new ScriptOptions(input);
+ formOptions.addOption("form", "2");
+
+ ScriptOptions options = new ScriptOptions(input);
+ options.addOption("generic", "3");
+
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+ MockDecodeContributor contributor;
+ MockDecodeContributor nullContributor;
+
+ inputContributor = new MockDecodeContributor(UIComponent.class, inputOptions);
+ formContributor = new MockDecodeContributor(UIComponent.class, formOptions);
+ contributor = new MockDecodeContributor(UIComponent.class, options);
+ nullContributor = new MockDecodeContributor(UIComponent.class, (ScriptOptions) null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(nullContributor);
+
+ ScriptOptions scriptOptions = new ScriptOptions(input);
+ compositeRenderer.mergeScriptOptions(scriptOptions, facesContext, input);
+ Map map = scriptOptions.getMap();
+
+ assertEquals(3, map.size());
+ assertEquals("1", map.get("input"));
+ assertEquals("2", map.get("form"));
+ assertEquals("3", map.get("generic"));
+ }
+
+ public final void testMergeScriptOptionsScriptOptionsFacesContextUIComponentClass() {
+ UIInput input = new UIInput();
+
+ ScriptOptions inputOptions = new ScriptOptions(input);
+ inputOptions.addOption("input", "1");
+
+ ScriptOptions formOptions = new ScriptOptions(input);
+ formOptions.addOption("form", "2");
+
+ ScriptOptions options = new ScriptOptions(input);
+ options.addOption("generic", "3");
+
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+ MockDecodeContributor contributor;
+ MockDecodeContributor nullContributor;
+
+ inputContributor = new MockDecodeContributor(UIInput.class, inputOptions);
+ formContributor = new MockDecodeContributor(NamingContainer.class, formOptions);
+ contributor = new MockDecodeContributor(UIComponent.class, options);
+ nullContributor = new MockDecodeContributor(UIForm.class, (ScriptOptions) null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(nullContributor);
+
+ ScriptOptions scriptOptions = new ScriptOptions(input);
+ compositeRenderer.mergeScriptOptions(scriptOptions, facesContext, input,
UIForm.class);
+ Map map = scriptOptions.getMap();
+
+ assertEquals(2, map.size());
+ assertEquals("2", map.get("form"));
+ assertEquals("3", map.get("generic"));
+ }
+
+ public final void testGetScripts() {
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+ MockDecodeContributor contributor;
+
+ inputContributor = new MockDecodeContributor(UIComponent.class, new String[] {
"input_script" }, null);
+ formContributor = new MockDecodeContributor(UIComponent.class, new String[] {
"form_script" }, null);
+ contributor = new MockDecodeContributor(UIComponent.class, null, null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+
+ InternetResource[] scripts = compositeRenderer.getScripts();
+
+ assertEquals(2, scripts.length);
+
+ assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/form_script"));
+ assertTrue(scripts[1].getKey().contains("org/richfaces/renderkit/input_script"));
+ }
+
+ public final void testGetStyles() {
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+ MockDecodeContributor contributor;
+
+ inputContributor = new MockDecodeContributor(UIComponent.class, null, new String[] {
"input_style" });
+ formContributor = new MockDecodeContributor(UIComponent.class, null, new String[] {
"form_style" });
+ contributor = new MockDecodeContributor(UIComponent.class, null, null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(formContributor);
+
+ InternetResource[] scripts = compositeRenderer.getStyles();
+
+ assertEquals(2, scripts.length);
+
+ assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/input_style"));
+ assertTrue(scripts[1].getKey().contains("org/richfaces/renderkit/form_style"));
+ }
+
+ public final void testGetScriptsClass() {
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+ MockDecodeContributor contributor;
+
+ inputContributor = new MockDecodeContributor(UIInput.class, new String[] {
"input_script" }, null);
+ formContributor = new MockDecodeContributor(NamingContainer.class, new String[] {
"form_script" }, null);
+ contributor = new MockDecodeContributor(UIComponent.class, null, null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+
+ InternetResource[] scripts = compositeRenderer.getScripts(UIInput.class);
+
+ assertEquals(1, scripts.length);
+
+ assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/input_script"));
+
+ scripts = compositeRenderer.getScripts(NamingContainer.class);
+
+ assertEquals(1, scripts.length);
+
+ assertTrue(scripts[0].getKey().contains("org/richfaces/renderkit/form_script"));
+
+ scripts = compositeRenderer.getStyles(String.class);
+ assertNull(scripts);
+ }
+
+ public final void testGetStylesClass() {
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+ MockDecodeContributor contributor;
+
+ inputContributor = new MockDecodeContributor(UIInput.class, null, new String[] {
"input_style" });
+ formContributor = new MockDecodeContributor(NamingContainer.class, null, new String[] {
"form_style" });
+ contributor = new MockDecodeContributor(UIComponent.class, null, null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+
+ InternetResource[] styles = compositeRenderer.getStyles(UIInput.class);
+
+ assertEquals(1, styles.length);
+
+ assertTrue(styles[0].getKey().contains("org/richfaces/renderkit/input_style"));
+
+ styles = compositeRenderer.getStyles(NamingContainer.class);
+
+ assertEquals(1, styles.length);
+ assertTrue(styles[0].getKey().contains("org/richfaces/renderkit/form_style"));
+
+ styles = compositeRenderer.getStyles(String.class);
+ assertNull(styles);
+ }
+
+ public final void testGetScriptContributionsStringFacesContextUIComponent() {
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+ MockDecodeContributor contributor;
+ MockDecodeContributor nullContributor;
+
+ inputContributor = new MockDecodeContributor(UIComponent.class, ".1;");
+ formContributor = new MockDecodeContributor(UIComponent.class, ".2;");
+ contributor = new MockDecodeContributor(UIComponent.class, ".3;");
+ nullContributor = new MockDecodeContributor(UIForm.class, (String) null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(nullContributor);
+
+ UIInput input = new UIInput();
+ input.getAttributes().put("test", ".testValue");
+
+ String contributions = compositeRenderer.getScriptContributions("theVar",
facesContext, input);
+
+ assertEquals("theVar.testValue.3;theVar.testValue.2;theVar.testValue.1;",
contributions);
+ }
+
+ public final void testGetScriptContributionsStringFacesContextUIComponentClass() {
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+ MockDecodeContributor contributor;
+ MockDecodeContributor nullContributor;
+
+ inputContributor = new MockDecodeContributor(UIInput.class, ".input;");
+ formContributor = new MockDecodeContributor(NamingContainer.class,
".namingContainer;");
+ contributor = new MockDecodeContributor(UIComponent.class, ".generic;");
+ nullContributor = new MockDecodeContributor(UIForm.class, (String) null);
+
+ compositeRenderer.addContributor(contributor);
+ compositeRenderer.addContributor(formContributor);
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(nullContributor);
+
+ UIInput input = new UIInput();
+ input.getAttributes().put("test", ".testValue");
+
+ String contributions = compositeRenderer.getScriptContributions("theVar",
facesContext, input,
+ UIForm.class);
+
+ assertEquals("theVar.testValue.generic;theVar.testValue.namingContainer;",
contributions);
+ }
+
+ public final void testAddContributor() {
+ MockDecodeContributor[] contributors = new MockDecodeContributor[5];
+ for (int i = 0; i < contributors.length; i++) {
+ contributors[i] = new MockDecodeContributor();
+ compositeRenderer.addContributor(contributors[i]);
+ }
+
+ assertTrue(Arrays.deepEquals(contributors, compositeRenderer.getContributors()));
+ }
+
+ public final void testContributorDecodeCallback() {
+ MockDecodeContributor inputContributor;
+ MockDecodeContributor formContributor;
+
+ formContributor = new MockDecodeContributor(NamingContainer.class);
+ inputContributor = new MockDecodeContributor(UIInput.class);
+
+ compositeRenderer.addContributor(inputContributor);
+ compositeRenderer.addContributor(formContributor);
+
+ UIComponent component = new UIInput();
+ compositeRenderer.doDecode(facesContext, component);
+
+ assertSame(compositeRenderer, inputContributor.getRenderer());
+ assertSame(facesContext, inputContributor.getContext());
+ assertSame(component, inputContributor.getComponent());
+
+ assertNull(formContributor.getRenderer());
+ assertNull(formContributor.getContext());
+ assertNull(formContributor.getComponent());
+
+ inputContributor.reset();
+ formContributor.reset();
+
+ assertNull(inputContributor.getRenderer());
+ assertNull(inputContributor.getContext());
+ assertNull(inputContributor.getComponent());
+
+ assertNull(formContributor.getRenderer());
+ assertNull(formContributor.getContext());
+ assertNull(formContributor.getComponent());
+
+ component = new UIForm();
+ compositeRenderer.doDecode(facesContext, component);
+
+ assertSame(compositeRenderer, formContributor.getRenderer());
+ assertSame(facesContext, formContributor.getContext());
+ assertSame(component, formContributor.getComponent());
+
+ assertNull(inputContributor.getRenderer());
+ assertNull(inputContributor.getContext());
+ assertNull(inputContributor.getComponent());
+ }
+
+ public final void testAddParameterEncoder() {
+ MockAttributeParameterEncoder[] encoders = new MockAttributeParameterEncoder[5];
+ for (int i = 0; i < encoders.length; i++) {
+ encoders[i] = new MockAttributeParameterEncoder("aaa");
+ compositeRenderer.addParameterEncoder(encoders[i]);
+ }
+
+ assertTrue(Arrays.deepEquals(encoders, compositeRenderer.getParameterEncoders()));
+ }
+
+ public final void testEncodeAttributeParameters() throws IOException {
+
+ MockAttributeParameterEncoder encoder1 = new
MockAttributeParameterEncoder("Attribute");
+ MockAttributeParameterEncoder encoder2 = new
MockAttributeParameterEncoder("MoreAttribute");
+
+ compositeRenderer.addParameterEncoder(encoder1);
+ compositeRenderer.addParameterEncoder(encoder2);
+
+ UIInput input = new UIInput();
+ input.getAttributes().put("Attribute", "testValue1");
+ input.getAttributes().put("MoreAttribute", "testValue2");
+
+ //ResponseWriter responseWriter = facesContext.getResponseWriter();
+ StringWriter stringWriter = new StringWriter();
+ ResponseWriter responseWriter =
facesContext.getRenderKit().createResponseWriter(stringWriter, "text/html",
"UTF8");
+ facesContext.setResponseWriter(responseWriter);
+
+ responseWriter.startDocument();
+ responseWriter.startElement("span", input);
+ compositeRenderer.encodeAttributeParameters(facesContext, input);
+ responseWriter.endElement("span");
+ responseWriter.endDocument();
+
+ responseWriter.flush();
+
+ String result = stringWriter.getBuffer().toString();
+ assertTrue(result.contains("testAttribute=\"testValue1\""));
+ assertTrue(result.contains("testMoreAttribute=\"testValue2\""));
+ }
+}
+
+class MockDecodeContributor implements RendererContributor {
+
+ private String[] scriptDependencies;
+ private String[] styleDependencies;
+
+ private String scriptContribution;
+
+ private Class componentClass;
+ private FacesContext context;
+ private UIComponent component;
+ private CompositeRenderer renderer;
+ private ScriptOptions options;
+
+ public MockDecodeContributor(Class componentClass, ScriptOptions options) {
+ super();
+
+ this.componentClass = componentClass;
+ this.options = options;
+ }
+
+ public MockDecodeContributor() {
+ this(UIComponent.class);
+ }
+
+ public MockDecodeContributor(Class componentClass) {
+ super();
+ this.componentClass = componentClass;
+ }
+
+ public MockDecodeContributor(Class componentClass, String scriptContribution) {
+ super();
+
+ this.componentClass = componentClass;
+ this.scriptContribution = scriptContribution;
+ }
+
+ public MockDecodeContributor(Class componentClass, String[] scriptDependencies,
+ String[] styleDependencies) {
+ super();
+
+ this.componentClass = componentClass;
+ this.scriptDependencies = scriptDependencies;
+ this.styleDependencies = styleDependencies;
+ }
+
+ public void decode(FacesContext context, UIComponent component,
+ CompositeRenderer compositeRenderer) {
+
+ this.component = component;
+ this.context = context;
+ this.renderer = compositeRenderer;
+ }
+
+ public Class getAcceptableClass() {
+ return componentClass;
+ }
+
+ public String getScriptContribution(FacesContext context,
+ UIComponent component) {
+ return scriptContribution != null ? component.getAttributes().get("test") +
scriptContribution :
+ null;
+ }
+
+ public String[] getScriptDependencies() {
+ return scriptDependencies;
+ }
+
+ public String[] getStyleDependencies() {
+ return styleDependencies;
+ }
+
+ public ScriptOptions buildOptions(FacesContext context,
+ UIComponent component) {
+ return options;
+ }
+
+ public UIComponent getComponent() {
+ return component;
+ }
+
+ public FacesContext getContext() {
+ return context;
+ }
+
+ public CompositeRenderer getRenderer() {
+ return renderer;
+ }
+
+ public void reset() {
+ this.component = null;
+ this.context = null;
+ this.renderer = null;
+ }
+}
+
+class MockAttributeParameterEncoder implements AttributeParametersEncoder {
+
+ private String attributeName;
+
+ public MockAttributeParameterEncoder(String attributeName) {
+ super();
+ this.attributeName = attributeName;
+ }
+
+ public void doEncode(FacesContext context, UIComponent component)
+ throws IOException {
+
+ context.getResponseWriter().writeAttribute("test" + attributeName,
component.getAttributes().get(attributeName)
+ , null);
+ }
+}
Copied:
framework/trunk/impl/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java)
===================================================================
---
framework/trunk/impl/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/renderkit/TemplateEncoderRendererBaseTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,73 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.renderkit;
+
+import java.io.StringWriter;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIOutput;
+import javax.faces.context.ResponseWriter;
+
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * Created 26.10.2007
+ * @author Nick Belaevski - mailto:nbelaevski@exadel.com
+ * @since 3.2
+ */
+
+public class TemplateEncoderRendererBaseTest extends AbstractFacesTest {
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testEncodeNonRendered() throws Exception {
+ ResponseWriter responseWriter = facesContext.getRenderKit().createResponseWriter(new
StringWriter(), "text/html", "UTF-8");
+ facesContext.setResponseWriter(responseWriter);
+
+ TemplateEncoderRendererBase rendererBase = new TemplateEncoderRendererBase() {
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return UIOutput.class;
+ }
+ };
+
+ UIOutput output = new UIOutput();
+
+ UIOutput c = new UIOutput();
+ c.setRendered(false);
+ c.setValue("");
+ output.getChildren().add(c);
+
+ //that should not fail
+ rendererBase.writeScriptBody(facesContext, c, true);
+ }
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/renderkit/TemplateUtilTest.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,45 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.renderkit;
+
+import java.io.StringReader;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.richfaces.javacc.RichMacroDefinition;
+
+/**
+ * @author Nick Belaevski - mailto:nbelaevski@exadel.com
+ * created 17.06.2007
+ *
+ */
+public class TemplateUtilTest extends TestCase {
+
+
+ public void testAntlr() throws Exception {
+ List result = new RichMacroDefinition(new StringReader("{aa{b\\}}a}\\\\
a\\}b\\{c")).expression();
+ Expression holder = (Expression) result.get(0);
+ assertEquals("aa{b}}a", holder.getExpression());
+ assertEquals("\\ a}b{c", result.get(1));
+ }
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/skin/Bean.java (from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/skin/Bean.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/skin/Bean.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/skin/Bean.java 2009-07-12 22:53:07
UTC (rev 14902)
@@ -0,0 +1,27 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.skin;
+
+public class Bean {
+ public String getName(){return "bindedtest";}
+ public String getBean(){return "binded.string";}
+}
\ No newline at end of file
Copied: framework/trunk/impl/src/test/java/org/richfaces/skin/SkinTestCase.java (from rev
14869, framework/trunk/legacy-tests/src/test/java/org/richfaces/skin/SkinTestCase.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/skin/SkinTestCase.java
(rev 0)
+++ framework/trunk/impl/src/test/java/org/richfaces/skin/SkinTestCase.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,270 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.skin;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.FacesException;
+
+import org.richfaces.test.AbstractFacesTest;
+
+/**
+ * Test for Skin/skin factory methods.
+ * @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
+ * @version $Revision: 1.1.2.1 $ $Date: 2007/01/10 14:28:13 $
+ *
+ */
+public class SkinTestCase extends AbstractFacesTest {
+
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(ElementType.METHOD)
+ private @interface SkinParameters {
+ String skinName() default "";
+ String baseSkinName() default "";
+ };
+
+ public void setUp() throws Exception {
+ super.setUp();
+ setupFacesRequest();
+ }
+
+ public void tearDown() throws Exception {
+ SkinFactory.reset();
+ super.tearDown();
+ }
+
+ @Override
+ protected void setupJsfInitParameters() {
+ super.setupJsfInitParameters();
+
+ setupSkinParameters();
+ }
+
+ private void setupSkinParameters() {
+ try {
+ Method method = getClass().getMethod(getName());
+ SkinParameters skinParameters = method.getAnnotation(SkinParameters.class);
+ if (skinParameters != null) {
+ String skinName = skinParameters.skinName();
+ if (skinName != null && skinName.length() != 0) {
+ facesServer.addInitParameter(SkinFactory.SKIN_PARAMETER, skinName);
+ }
+
+ String baseSkinName = skinParameters.baseSkinName();
+ if (baseSkinName != null && baseSkinName.length() != 0) {
+ facesServer.addInitParameter(SkinFactory.BASE_SKIN_PARAMETER, baseSkinName);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getInstance()'
+ */
+ public void testGetInstance() {
+ SkinFactory factory = SkinFactory.getInstance();
+ SkinFactory factory1 = SkinFactory.getInstance();
+ assertSame(factory,factory1);
+ }
+
+ private void addParameters(Object[][] strings) {
+ Map<Object,Object> baseMap = new HashMap<Object, Object>();
+ for (Object[] objects : strings) {
+ baseMap.put(objects[0], objects[1]);
+ }
+
+ facesContext.getExternalContext().getRequestMap().put("test", baseMap);
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ @SkinParameters(skinName = "test")
+ public void testGetSkin() {
+ addParameters(new Object[][]{new Object[] {"bean",
"test.value"}});
+
+ SkinFactory factory = SkinFactory.getInstance();
+ // test call
+ Skin skin = factory.getSkin(facesContext);
+ assertNotNull("Null skin!",skin);
+ // test properties
+ assertEquals("string",skin.getParameter(facesContext,
"string.property"));
+ assertEquals("base.string",skin.getParameter(facesContext,
"base.property"));
+ assertEquals("test.value",skin.getParameter(facesContext,
"bind.property"));
+ // assertEquals("HTML_BASIC",skin.getRenderKitId(mockContext));
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ @SkinParameters(skinName = "test")
+ public void testSkinReferences() {
+ SkinFactory factory = SkinFactory.getInstance();
+
+ // test call
+ Skin skin = factory.getSkin(facesContext);
+ assertNotNull("Null skin!",skin);
+ assertEquals("default",skin.getParameter(facesContext, "c"));
+ assertEquals("yyy",skin.getParameter(facesContext, "y"));
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ @SkinParameters(skinName = "style", baseSkinName = "style_base")
+ public void testSkinReferences1() {
+ SkinFactory factory = SkinFactory.getInstance();
+ // test call
+ Skin skin = factory.getSkin(facesContext);
+ assertNotNull("Null skin!",skin);
+ assertEquals("#F5F0E7",skin.getParameter(facesContext,
"intermediateTextColor"));
+ assertEquals("10px",skin.getParameter(facesContext,
"intermediateTextSize"));
+ assertEquals("#F5F0E7",skin.getParameter(facesContext,
"generalTextColor"));
+
+ assertEquals("white.textcolor",skin.getParameter(facesContext,
"additionalTextColor"));
+ }
+
+ @SkinParameters(skinName = "dynatest", baseSkinName =
"dynatest_base")
+ public void testBaseSkin() {
+ SkinFactory factory = SkinFactory.getInstance();
+ addParameters(new Object[][]{new Object[] {"bean", "dynabase1"}});
+
+ Skin skin = factory.getSkin(facesContext);
+ assertEquals("default", skin.getParameter(facesContext,
"default"));
+ assertEquals("itself", skin.getParameter(facesContext,
"selfValue"));
+ assertEquals("#AAA", skin.getParameter(facesContext,
"customFormColor"));
+
+ Map<String, String> map = (Map<String, String>)
facesContext.getExternalContext().getRequestMap().get("test");
+ map.put("bean", "dynabase2");
+
+ assertEquals("xxx", skin.getParameter(facesContext, "default"));
+ assertEquals("itself", skin.getParameter(facesContext,
"selfValue"));
+ assertEquals("#AAA", skin.getParameter(facesContext,
"customFormColor"));
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ @SkinParameters(skinName = "cyclic")
+ public void testCyclicSkinReferences() {
+ SkinFactory factory = SkinFactory.getInstance();
+
+ try {
+ Skin skin = factory.getSkin(facesContext);
+ skin.getParameter(facesContext, "x");
+ fail();
+ } catch(FacesException e){
+ //it's ok
+ }
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ @SkinParameters(skinName = "noref")
+ public void testBadSkinReferences() {
+ SkinFactory factory = SkinFactory.getInstance();
+
+ // test call
+ try {
+ Skin skin = factory.getSkin(facesContext);
+ skin.getParameter(facesContext, "x");
+ fail();
+ } catch(FacesException e){
+ //it's ok
+ }
+ }
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkin(FacesContext)'
+ */
+ @SkinParameters(skinName = "#{test.skin}")
+ public void testGetBindedSkin() {
+ SkinFactory factory = SkinFactory.getInstance();
+
+ addParameters(new Object[][] {
+ new Object[] {"skin", "bindedtest"},
+ new Object[] {"bean", "binded.test.value"}
+ });
+
+ // test call
+ Skin skin = factory.getSkin(facesContext);
+ assertNotNull("Null skin!",skin);
+ // test properties
+ assertEquals("bindedstring",skin.getParameter(facesContext,
"string.property"));
+ // assertEquals("base.string",skin.getParameter(mockContext,"base.property"));
+ assertEquals("binded.test.value",skin.getParameter(facesContext,
"bind.property"));
+ assertEquals("TEST",skin.getRenderKitId(facesContext));
+ }
+
+ @SkinParameters(skinName = "#{test.skin}")
+ public void testSkinHash() {
+ SkinFactory factory = SkinFactory.getInstance();
+
+ addParameters(new Object[][] {
+ new Object[] {"skin", "bindedtest"},
+ new Object[] {"bean", "binded.test.value"}
+ });
+
+ Skin skin = factory.getSkin(facesContext);
+ Map<String, Object> requestMap =
facesContext.getExternalContext().getRequestMap();
+
+ // test properties
+ int hash = skin.hashCode(facesContext);
+ assertTrue(requestMap.containsKey(BasicSkinImpl.REQUEST_HASH_CODES_MAP_PARAMETER));
+ assertEquals(hash,skin.hashCode(facesContext));
+ requestMap.remove(BasicSkinImpl.REQUEST_HASH_CODES_MAP_PARAMETER);
+ assertEquals(hash,skin.hashCode(facesContext));
+ // setup Value binding mock for different value - hash must differ.
+ requestMap.remove(BasicSkinImpl.REQUEST_HASH_CODES_MAP_PARAMETER);
+
+ Map map = (Map) requestMap.get("test");
+ map.put("bean", "other.test.value");
+
+ assertFalse( hash==skin.hashCode(facesContext) );
+
+ }
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getDefaultProperties()'
+ */
+ public void testGetDefaultProperties() {
+ SkinFactory factory = (SkinFactory) SkinFactory.getInstance();
+ // assertEquals("HTML_BASIC",defaultProps.getProperty("render.kit"));
+ // Second default config
+ assertEquals("default",factory.getDefaultSkin(facesContext).getParameter(facesContext,
"a"));
+ }
+
+ /*
+ * Test method for 'org.richfaces.skin.SkinFactory.getSkinName(FacesContext)'
+ */
+ public void testGetSkinName() {
+
+ }
+
+}
Copied: framework/trunk/impl/src/test/java/org/richfaces/skin/SkinThreadsTestCase.java
(from rev 14869,
framework/trunk/legacy-tests/src/test/java/org/richfaces/skin/SkinThreadsTestCase.java)
===================================================================
--- framework/trunk/impl/src/test/java/org/richfaces/skin/SkinThreadsTestCase.java
(rev 0)
+++
framework/trunk/impl/src/test/java/org/richfaces/skin/SkinThreadsTestCase.java 2009-07-12
22:53:07 UTC (rev 14902)
@@ -0,0 +1,112 @@
+///**
+// * License Agreement.
+// *
+// * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+// *
+// * Copyright (C) 2007 Exadel, Inc.
+// *
+// * This library is free software; you can redistribute it and/or
+// * modify it under the terms of the GNU Lesser General Public
+// * License version 2.1 as published by the Free Software Foundation.
+// *
+// * This library 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 library; if not, write to the Free Software
+// * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+// */
+//
+//package org.richfaces.skin;
+//
+//import javax.faces.context.FacesContext;
+//
+//import org.ajax4jsf.tests.AbstractThreadedAjax4JsfTestCase;
+//import org.richfaces.skin.Skin;
+//import org.richfaces.skin.SkinFactory;
+//
+///**
+// * @author asmirnov(a)exadel.com (latest modification by $Author: ishabalov $)
+// * @version $Revision: 1.1.2.2 $ $Date: 2007/02/20 20:58:11 $
+// *
+// */
+//public class SkinThreadsTestCase extends AbstractThreadedAjax4JsfTestCase {
+//
+// /**
+// * @param s
+// */
+// public SkinThreadsTestCase(String s) {
+// super(s);
+// // TODO Auto-generated constructor stub
+// }
+//
+// /*
+// * (non-Javadoc)
+// *
+// * @see com.exadel.vcp.tests.VcpJsfTestCase#setUp()
+// */
+//public void setUp() throws Exception {
+// // TODO Auto-generated method stub
+// super.setUp();
+// servletContext.setAttribute("skin", new Bean());
+// }
+// /*
+// * (non-Javadoc)
+// *
+// * @see com.exadel.vcp.tests.VcpJsfTestCase#tearDown()
+// */
+// public void tearDown() throws Exception {
+// // TODO Auto-generated method stub
+// super.tearDown();
+// }
+//
+//
+// public class SkinTestRunnable extends TestCaseRunnable {
+//
+//
+// /**
+// *
+// */
+// public SkinTestRunnable() {
+// // TODO Auto-generated constructor stub
+// }
+//
+// /* (non-Javadoc)
+// * @see
com.exadel.vcp.tests.ThreadedVcpJsfTestCase.TestCaseRunnable#runTestCase(javax.faces.context.FacesContext)
+// */
+// public void runTestCase(FacesContext context) throws Throwable {
+// context.getExternalContext().getRequestMap().put("test", new Bean());
+// Skin skin = SkinFactory.getInstance().getSkin(context);
+// assertNotNull(skin);
+// assertEquals("TEST", skin.getRenderKitId(context));
+// assertEquals("binded.string", skin.getParameter(context,
"bind.property"));
+// assertEquals("bindedstring", skin.getParameter(context,
"string.property"));
+// assertEquals("10", skin.getParameter(context, "int.property"));
+// assertNull(skin.getParameter(context, "notexist"));
+// }
+//
+// }
+//
+// /**
+// * Test skin factory for thread-safe.
+// */
+// public void testThreadsafe() {
+// TestCaseRunnable[] runnables = new TestCaseRunnable[20];
+// for (int i = 0; i < runnables.length; i++) {
+// runnables[i] = new SkinTestRunnable();
+//
+// }
+// this.runTestCaseRunnables(runnables);
+// }
+// /*
+// * (non-Javadoc)
+// *
+// * @see com.exadel.vcp.tests.VcpJsfTestCase#getSkinName()
+// */
+// protected String getSkinName() {
+// // TODO Auto-generated method stub
+// return "#{skin.name}";
+// }
+//}
Added: framework/trunk/impl/src/test/resources/bindedtest.skin.properties
===================================================================
--- framework/trunk/impl/src/test/resources/bindedtest.skin.properties
(rev 0)
+++ framework/trunk/impl/src/test/resources/bindedtest.skin.properties 2009-07-12 22:53:07
UTC (rev 14902)
@@ -0,0 +1,4 @@
+render.kit=TEST
+string.property=bindedstring
+int.property=10
+bind.property=\#{test.bean}
Added: framework/trunk/impl/src/test/resources/org/richfaces/renderkit/form_script
===================================================================
Added: framework/trunk/impl/src/test/resources/org/richfaces/renderkit/form_style
===================================================================
Added: framework/trunk/impl/src/test/resources/org/richfaces/renderkit/input_script
===================================================================
Added: framework/trunk/impl/src/test/resources/org/richfaces/renderkit/input_style
===================================================================