Author: nbelaevski
Date: 2008-03-02 20:19:26 -0500 (Sun, 02 Mar 2008)
New Revision: 6472
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/TestDataGenerator.java
trunk/cdk/generator/src/main/resources/META-INF/templates12/componenttest.vm
Log:
CDK tests generation:
- test data for java.util.Date added
- java.lang.Enum support added
- several (two) test data sets added
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/TestDataGenerator.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/TestDataGenerator.java 2008-03-02
14:32:15 UTC (rev 6471)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/TestDataGenerator.java 2008-03-03
01:19:26 UTC (rev 6472)
@@ -3,6 +3,7 @@
*/
package org.ajax4jsf.builder.generator;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -38,6 +39,8 @@
testData.put(Float.class.getName(), "new Float(2.05f)");
testData.put(Double.class.getName(), "new Double(1.34d)");
+ testData.put(Date.class.getName(), "java.text.DateFormat.getDateInstance(" +
+ "java.text.DateFormat.SHORT,
java.util.Locale.US).parse(\"09/08/2007\")");
}
private static Map<String, String> testData1 = new HashMap<String,
String>();
@@ -60,6 +63,8 @@
testData1.put(Float.class.getName(), "new Float(1.05f)");
testData1.put(Double.class.getName(), "new Double(1.44d)");
+ testData1.put(Date.class.getName(), "java.text.DateFormat.getDateInstance("
+
+ "java.text.DateFormat.SHORT,
java.util.Locale.US).parse(\"02/29/2008\")");
}
private static Map<String, Class> primitiveToWrapper = new HashMap<String,
Class>();
@@ -137,7 +142,7 @@
}
- return "createTestData_" + propertyName + "()";
+ return "createTestData_" + number + "_" + propertyName +
"()";
}
public String getTestData(PropertyBean propertyBean) {
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/componenttest.vm
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates12/componenttest.vm 2008-03-02
14:32:15 UTC (rev 6471)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates12/componenttest.vm 2008-03-03
01:19:26 UTC (rev 6472)
@@ -115,22 +115,35 @@
testRestoreState(state);
}
- public void testGetters() {
+ public void testGetters() throws Exception {
${component.simpleClassName} component = new ${component.simpleClassName}();
#foreach( $prop in $component.properties )
- #if(!$prop.exist && !$prop.elonly &&
!$prop.classname.startsWith("javax.faces."))
- component.setValueBinding("${prop.name}", new
MockValueBinding($testDataGenerator.getTestVeData(${prop}),
${testDataGenerator.getTestVeClass(${prop})}.class));
- assertEquals($testDataGenerator.getTestData(${prop}), component.${prop.getterName}());
- component.${prop.setterName}($testDataGenerator.getTestData1(${prop}) );
- assertEquals($testDataGenerator.getTestData1(${prop}),
component.${prop.getterName}());
- #end
+ #if(!$prop.exist && !$prop.elonly &&
!$prop.classname.startsWith("javax.faces.") &&
!$prop.classname.startsWith("javax.el."))
+ #if( $prop.isInstanceof("java.lang.Enum") )
+ $prop.classname[] ${prop.name}Values = ${prop.classname}.values();
+ for (int i = 0; i < ${prop.name}Values.length; i++) {
+ component.setValueBinding("${prop.name}", new
MockValueBinding(${prop.name}Values[i], ${prop.classname}.class));
+ assertEquals(${prop.name}Values[i], component.${prop.getterName}());
+ }
+
+ for (int i = ${prop.name}Values.length - 1; i >=0 ; i--) {
+ component.${prop.setterName}(${prop.name}Values[i]);
+ assertEquals(${prop.name}Values[i], component.${prop.getterName}());
+ }
+ #else
+ component.setValueBinding("${prop.name}", new
MockValueBinding($testDataGenerator.getTestVeData(${prop}),
${testDataGenerator.getTestVeClass(${prop})}.class));
+ assertEquals($testDataGenerator.getTestData(${prop}),
component.${prop.getterName}());
+ component.${prop.setterName}($testDataGenerator.getTestData1(${prop}) );
+ assertEquals($testDataGenerator.getTestData1(${prop}),
component.${prop.getterName}());
+ #end
+ #end
#end
}
- private void testRestoreState(Object state){
+ public void testRestoreState(Object state){
${component.simpleClassName} restoredComponent = new ${component.simpleClassName}();
restoredComponent.restoreState(facesContext, state);
Show replies by date