[richfaces-svn-commits] JBoss Rich Faces SVN: r392 - in trunk/richfaces/common/src: main/java/org/richfaces/json and 4 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Apr 12 16:06:46 EDT 2007


Author: nbelaevski
Date: 2007-04-12 16:06:46 -0400 (Thu, 12 Apr 2007)
New Revision: 392

Added:
   trunk/richfaces/common/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java
   trunk/richfaces/common/src/test/java/org/richfaces/json/
   trunk/richfaces/common/src/test/java/org/richfaces/json/JsonTest.java
Modified:
   trunk/richfaces/common/src/main/java/org/richfaces/component/UIRangedNumberInput.java
   trunk/richfaces/common/src/main/java/org/richfaces/json/JSONCollection.java
   trunk/richfaces/common/src/main/java/org/richfaces/json/JSONMap.java
   trunk/richfaces/common/src/test/java/org/richfaces/renderkit/InputRendererBaseTest.java
Log:
Tests for common

Modified: trunk/richfaces/common/src/main/java/org/richfaces/component/UIRangedNumberInput.java
===================================================================
--- trunk/richfaces/common/src/main/java/org/richfaces/component/UIRangedNumberInput.java	2007-04-12 19:03:45 UTC (rev 391)
+++ trunk/richfaces/common/src/main/java/org/richfaces/component/UIRangedNumberInput.java	2007-04-12 20:06:46 UTC (rev 392)
@@ -33,15 +33,7 @@
  * 
  */
 public abstract class UIRangedNumberInput extends UIInput {
-    private static final double DEFAULT_MIN = 0;
-    private static final double DEFAULT_MAX = 100;
 
-    private Number normValue;
-
-    public UIRangedNumberInput() {
-        super();
-    }
-
     public abstract String getMaxValue();
     public abstract void setMaxValue(String value);
 

Modified: trunk/richfaces/common/src/main/java/org/richfaces/json/JSONCollection.java
===================================================================
--- trunk/richfaces/common/src/main/java/org/richfaces/json/JSONCollection.java	2007-04-12 19:03:45 UTC (rev 391)
+++ trunk/richfaces/common/src/main/java/org/richfaces/json/JSONCollection.java	2007-04-12 20:06:46 UTC (rev 392)
@@ -77,17 +77,9 @@
 			
 		};
 	}
-
+	
 	public int size() {
 		return array.length();
 	}
 
-	public static void main(String[] args) throws JSONException {
-		JSONCollection collection = new JSONCollection("['string', [1, 2, 3]]");
-		Object[] objects = collection.toArray();
-		for (int i = 0; i < objects.length; i++) {
-			System.out.print(i + "=> ");
-			System.out.println(objects[i]);
-		}
-	}
 }

Modified: trunk/richfaces/common/src/main/java/org/richfaces/json/JSONMap.java
===================================================================
--- trunk/richfaces/common/src/main/java/org/richfaces/json/JSONMap.java	2007-04-12 19:03:45 UTC (rev 391)
+++ trunk/richfaces/common/src/main/java/org/richfaces/json/JSONMap.java	2007-04-12 20:06:46 UTC (rev 392)
@@ -129,15 +129,15 @@
 		return jsonObject.toString(indentFactor);
 	}
 	
-	public static void main(String[] args) throws Exception {
-		String json = "{ test1: 'test string', test2: [15, 45, 28], test3: { innerMap1: { prop1: '1', prop2: true }, innerProp1: [12, 2] } }";
-		JSONMap map = new JSONMap(json);
-		System.out.println(map.get("test1"));
-		System.out.println("next >>>>>>>>");
-		System.out.println(map.get("test2"));
-		System.out.println("next >>>>>>>>");
-		System.out.println(map.get("test3"));
-	}
+//	public static void main(String[] args) throws Exception {
+//		String json = "{ test1: 'test string', test2: [15, 45, 28], test3: { innerMap1: { prop1: '1', prop2: true }, innerProp1: [12, 2] } }";
+//		JSONMap map = new JSONMap(json);
+//		System.out.println(map.get("test1"));
+//		System.out.println("next >>>>>>>>");
+//		System.out.println(map.get("test2"));
+//		System.out.println("next >>>>>>>>");
+//		System.out.println(map.get("test3"));
+//	}
 }
 
 

Added: trunk/richfaces/common/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java
===================================================================
--- trunk/richfaces/common/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java	                        (rev 0)
+++ trunk/richfaces/common/src/test/java/org/richfaces/component/UIRangedNumberInputTest.java	2007-04-12 20:06:46 UTC (rev 392)
@@ -0,0 +1,120 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - 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.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+public class UIRangedNumberInputTest extends AbstractAjax4JsfTestCase {
+
+	private UIRangedNumberInput input;
+	
+	public UIRangedNumberInputTest(String name) {
+		super(name);
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+
+		input = new UIRangedNumberInput() {
+			private String minValue;
+			private String maxValue;
+			
+			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;
+			}
+		};
+
+		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();
+	}
+}

Added: trunk/richfaces/common/src/test/java/org/richfaces/json/JsonTest.java
===================================================================
--- trunk/richfaces/common/src/test/java/org/richfaces/json/JsonTest.java	                        (rev 0)
+++ trunk/richfaces/common/src/test/java/org/richfaces/json/JsonTest.java	2007-04-12 20:06:46 UTC (rev 392)
@@ -0,0 +1,115 @@
+/**
+ * 
+ */
+package org.richfaces.json;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski at 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();
+	}
+
+	/**
+	 * Test method for {@link org.richfaces.json.Test#main(java.lang.String[])}.
+	 */
+	public void testMain() {
+		Test.main(null);
+	}
+	
+	public void testMap() throws Exception {
+		JSONMap map = new JSONMap("{text: 12, moreData: { key: value, key1: 23.04 }}");
+		assertEquals(12, map.get("text"));
+		assertEquals(2, map.size());
+		
+		Map innerMap = (Map) map.get("moreData");
+		assertEquals("value", innerMap.get("key"));
+		assertEquals(23.04, innerMap.get("key1"));
+		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, innerMap.get("key1"));
+		assertEquals(2, innerMap.size());
+		
+		Collection innerCollection = (Collection) iterator.next();
+		assertEquals(3, innerCollection.size());
+		Iterator innerIterator = innerCollection.iterator();
+		
+		assertTrue(innerIterator.hasNext());
+		assertEquals(1, innerIterator.next());
+		assertTrue(innerIterator.hasNext());
+		assertEquals("a", innerIterator.next());
+		assertTrue(innerIterator.hasNext());
+		assertEquals(3, innerIterator.next());
+		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 testMapGetString() throws Exception {
+		JSONMap map = new JSONMap("{key: {innerKey: value, moreKey: {deepKey: aaa}}}");
+
+		String[] split = map.getString().split("\n");
+		assertTrue(split[1].startsWith("\"innerKey"));
+		assertTrue(split[2].startsWith("\"moreKey"));
+		
+		split = map.getString(3).split("\n");
+		assertTrue(split[1].startsWith("   \"innerKey"));
+		assertTrue(split[2].startsWith("   \"moreKey"));
+
+		split = map.getString(8).split("\n");
+		assertTrue(split[1].startsWith("        \"innerKey"));
+		assertTrue(split[2].startsWith("        \"moreKey"));
+	}
+}

Modified: trunk/richfaces/common/src/test/java/org/richfaces/renderkit/InputRendererBaseTest.java
===================================================================
--- trunk/richfaces/common/src/test/java/org/richfaces/renderkit/InputRendererBaseTest.java	2007-04-12 19:03:45 UTC (rev 391)
+++ trunk/richfaces/common/src/test/java/org/richfaces/renderkit/InputRendererBaseTest.java	2007-04-12 20:06:46 UTC (rev 392)
@@ -68,6 +68,8 @@
 	 */
 	public void tearDown() throws Exception {
 		super.tearDown();
+	
+		this.input = null;
 	}
 
 	public void testDoDecode() throws Exception {




More information about the richfaces-svn-commits mailing list