Author: konstantin.mishin
Date: 2008-01-22 13:17:16 -0500 (Tue, 22 Jan 2008)
New Revision: 5542
Added:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockDataModelListener.java
trunk/framework/test/src/test/java/org/richfaces/model/FilterFieldTest.java
trunk/framework/test/src/test/java/org/richfaces/model/ModifiableModelTest.java
trunk/framework/test/src/test/java/org/richfaces/model/SortField2Test.java
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockDataModel.java
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java
Log:
RF-1743
Modified: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockDataModel.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockDataModel.java 2008-01-22
17:39:58 UTC (rev 5541)
+++ trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockDataModel.java 2008-01-22
18:17:16 UTC (rev 5542)
@@ -44,6 +44,7 @@
private int maxRow = ROWS;
+ private Object wrappedData;
/**
* @return the maxRow
*/
@@ -141,7 +142,7 @@
*/
public Object getWrappedData() {
// TODO Auto-generated method stub
- return null;
+ return wrappedData;
}
/* (non-Javadoc)
@@ -163,8 +164,7 @@
* @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
*/
public void setWrappedData(Object data) {
- // TODO Auto-generated method stub
-
+ wrappedData = data;
}
}
Added: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockDataModelListener.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockDataModelListener.java
(rev 0)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockDataModelListener.java 2008-01-22
18:17:16 UTC (rev 5542)
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package org.ajax4jsf.tests;
+
+import javax.faces.model.DataModelEvent;
+import javax.faces.model.DataModelListener;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class MockDataModelListener implements DataModelListener {
+
+ /* (non-Javadoc)
+ * @see
javax.faces.model.DataModelListener#rowSelected(javax.faces.model.DataModelEvent)
+ */
+ public void rowSelected(DataModelEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java
===================================================================
---
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java 2008-01-22
17:39:58 UTC (rev 5541)
+++
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockValueExpression.java 2008-01-22
18:17:16 UTC (rev 5542)
@@ -72,33 +72,40 @@
}
/* (non-Javadoc)
- * @see javax.el.Expression#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- // TODO Auto-generated method stub
- return false;
- }
-
- /* (non-Javadoc)
* @see javax.el.Expression#getExpressionString()
*/
@Override
public String getExpressionString() {
// TODO Auto-generated method stub
- return null;
+ return o.toString();
}
- /* (non-Javadoc)
- * @see javax.el.Expression#hashCode()
- */
@Override
- public int hashCode() {
- // TODO Auto-generated method stub
- return 0;
- }
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((o == null) ? 0 : o.hashCode());
+ return result;
+ }
- /* (non-Javadoc)
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MockValueExpression other = (MockValueExpression) obj;
+ if (o == null) {
+ if (other.o != null)
+ return false;
+ } else if (!o.equals(other.o))
+ return false;
+ return true;
+ }
+
+ /* (non-Javadoc)
* @see javax.el.Expression#isLiteralText()
*/
@Override
@@ -106,5 +113,4 @@
// TODO Auto-generated method stub
return true;
}
-
}
Added: trunk/framework/test/src/test/java/org/richfaces/model/FilterFieldTest.java
===================================================================
--- trunk/framework/test/src/test/java/org/richfaces/model/FilterFieldTest.java
(rev 0)
+++ trunk/framework/test/src/test/java/org/richfaces/model/FilterFieldTest.java 2008-01-22
18:17:16 UTC (rev 5542)
@@ -0,0 +1,87 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import javax.el.ValueExpression;
+
+import org.ajax4jsf.tests.MockValueExpression;
+
+import junit.framework.TestCase;
+
+/**
+ * @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 = new MockValueExpression(null);
+ 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());
+ }
+
+}
Added: trunk/framework/test/src/test/java/org/richfaces/model/ModifiableModelTest.java
===================================================================
--- trunk/framework/test/src/test/java/org/richfaces/model/ModifiableModelTest.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/ModifiableModelTest.java 2008-01-22
18:17:16 UTC (rev 5542)
@@ -0,0 +1,192 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.tests.MockDataModel;
+import org.ajax4jsf.tests.MockDataModelListener;
+import org.ajax4jsf.tests.MockRange;
+import org.apache.commons.digester.SetRootRule;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class ModifiableModelTest extends TestCase {
+
+ private ModifiableModel model;
+ private ExtendedDataModel originalModel;
+ private String var;
+ private List<FilterField> filterFields;
+ private List<SortField2> sortFields;
+
+ /**
+ * @param name
+ */
+ public ModifiableModelTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ originalModel = new MockDataModel();
+ var = "var";
+ filterFields = new LinkedList<FilterField>();
+ sortFields = new LinkedList<SortField2>();
+ model = new ModifiableModel(originalModel, var, filterFields, sortFields);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ model = null;
+ var = null;
+ filterFields = null;
+ sortFields = null;
+ originalModel = null;
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ModifiableModel#isRowAvailable()}.
+ */
+ public final void testIsRowAvailable() {
+ assertEquals(model.isRowAvailable(), originalModel.isRowAvailable());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ModifiableModel#getRowCount()}.
+ */
+ public final void testGetRowCount() {
+ assertEquals(model.getRowCount(), originalModel.getRowCount());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ModifiableModel#getRowIndex()}.
+ */
+ public final void testGetRowIndex() {
+ assertEquals(model.getRowIndex(), originalModel.getRowIndex());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ModifiableModel#setRowIndex(int)}.
+ */
+ public final void testSetRowIndex() {
+ model.setRowIndex(5);
+ assertEquals(model.getRowIndex(), originalModel.getRowIndex());
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#setRowKey(java.lang.Object)}.
+ */
+ public final void testSetRowKey() {
+ model.setRowKey(new Integer(5));
+ assertEquals(model.getRowKey(), originalModel.getRowKey());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ModifiableModel#getRowKey()}.
+ */
+ public final void testGetRowKey() {
+ assertEquals(model.getRowKey(), originalModel.getRowKey());
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#getSerializableModel(org.ajax4jsf.model.Range)}.
+ */
+ public final void testGetSerializableModel() {
+ assertEquals(model.getSerializableModel(null),
originalModel.getSerializableModel(null));
+ }
+
+ /**
+ * 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() {
+ MockRange range = new MockRange(5);
+ try {
+ model.walk(null, new DataVisitor(){
+ public void process(FacesContext context, Object rowKey,
+ Object argument) throws IOException {
+ Object key = model.getRowKey();
+ model.setRowKey(rowKey);
+ assertEquals(model.getRowData(), originalModel.getRowData());
+ model.setRowKey(key);
+ }
+ }, range, null);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#ModifiableModel(org.ajax4jsf.model.ExtendedDataModel,
java.lang.String, java.util.List, java.util.List)}.
+ */
+ public final void testModifiableModel() {
+ ModifiableModel modifiableModel = new ModifiableModel(originalModel, var, filterFields,
sortFields);;
+ assertNotNull(modifiableModel);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#addDataModelListener(javax.faces.model.DataModelListener)}.
+ */
+ public final void testAddDataModelListenerDataModelListener() {
+ MockDataModelListener listener = new MockDataModelListener();
+ model.addDataModelListener(listener);
+ assertEquals(model.getDataModelListeners()[0], listener);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ModifiableModel#getDataModelListeners()}.
+ */
+ public final void testGetDataModelListeners() {
+ assertEquals(model.getDataModelListeners().length, 0);
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ModifiableModel#getRowData()}.
+ */
+ public final void testGetRowData() {
+ assertEquals(model.getRowData(), originalModel.getRowData());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.model.ModifiableModel#getWrappedData()}.
+ */
+ public final void testGetWrappedData() {
+ assertEquals(model.getWrappedData(), originalModel.getWrappedData());
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#removeDataModelListener(javax.faces.model.DataModelListener)}.
+ */
+ public final void testRemoveDataModelListenerDataModelListener() {
+ MockDataModelListener listener = new MockDataModelListener();
+ model.addDataModelListener(listener);
+ assertEquals(model.getDataModelListeners()[0], listener);
+ model.removeDataModelListener(listener);
+ assertEquals(model.getDataModelListeners().length, 0);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.model.ModifiableModel#setWrappedData(java.lang.Object)}.
+ */
+ public final void testSetWrappedDataObject() {
+ model.setWrappedData(var);
+ assertEquals(originalModel.getWrappedData(), var);
+ }
+
+}
Added: trunk/framework/test/src/test/java/org/richfaces/model/SortField2Test.java
===================================================================
--- trunk/framework/test/src/test/java/org/richfaces/model/SortField2Test.java
(rev 0)
+++ trunk/framework/test/src/test/java/org/richfaces/model/SortField2Test.java 2008-01-22
18:17:16 UTC (rev 5542)
@@ -0,0 +1,99 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import javax.el.ValueExpression;
+
+import org.ajax4jsf.tests.MockValueExpression;
+
+import junit.framework.TestCase;
+
+/**
+ * @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 = new MockValueExpression(null);
+ 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());
+ }
+
+}
Added:
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java
===================================================================
---
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java
(rev 0)
+++
trunk/framework/test/src/test/java/org/richfaces/model/impl/expressive/WrappedBeanFilterTest.java 2008-01-22
18:17:16 UTC (rev 5542)
@@ -0,0 +1,72 @@
+/**
+ *
+ */
+package org.richfaces.model.impl.expressive;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.ajax4jsf.tests.MockValueExpression;
+import org.richfaces.model.FilterField;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class WrappedBeanFilterTest extends TestCase {
+
+ private List<FilterField> filterFields;
+ private WrappedBeanFilter filter;
+ /**
+ * @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(new MockValueExpression("keyTrue")));
+ filter = new WrappedBeanFilter(filterFields);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ filter = null;
+ filterFields = 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() {
+ TestObj obj = new TestObj("TestObj");
+ Map<String, Object> props = new HashMap<String, 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(new MockValueExpression("keyFalse")));
+ assertFalse(filter.accept(wrapper));
+ }
+
+}