Author: nbelaevski
Date: 2007-04-13 20:37:54 -0400 (Fri, 13 Apr 2007)
New Revision: 84
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBean.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TagBean.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TestClassHolder.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentTestGenerator.java
trunk/cdk/generator/src/main/resources/META-INF/schema/component-config.dtd
trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm
Log:
Test generation enhanced:
- classname & superclassname in tests can be made optional with reasonal defaults
- dangerous tests commented for now
- 2 quick & dirty test data sets implemented for now
- component getters tests implemented. El things & javax.faces.* stuff skipped for
now
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBean.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBean.java 2007-04-13
18:57:52 UTC (rev 83)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBean.java 2007-04-14
00:37:54 UTC (rev 84)
@@ -398,4 +398,15 @@
}
return false;
}
+
+ @Override
+ public TestClassHolder getTest() {
+ return super.getTest();
+ }
+
+ @Override
+ public void setTest(TestClassHolder test) {
+ super.setTest(test);
+ test.setClassname(getClassname() + "ComponentTest");
+ }
}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TagBean.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TagBean.java 2007-04-13
18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TagBean.java 2007-04-14
00:37:54 UTC (rev 84)
@@ -81,4 +81,14 @@
this._generate = generate;
}
+ @Override
+ public void setTest(TestClassHolder test) {
+ super.setTest(test);
+ test.setClassname(getClassname() + "TagTest");
+ }
+
+ @Override
+ public TestClassHolder getTest() {
+ return super.getTest();
+ }
}
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TestClassHolder.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TestClassHolder.java 2007-04-13
18:57:52 UTC (rev 83)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/TestClassHolder.java 2007-04-14
00:37:54 UTC (rev 84)
@@ -9,7 +9,7 @@
private String _classname;
- private String _superclassname;
+ private String _superclassname =
"org.ajax4jsf.tests.AbstractAjax4JsfTestCase";
public String getClassname() {
return _classname;
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentTestGenerator.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentTestGenerator.java 2007-04-13
18:57:52 UTC (rev 83)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentTestGenerator.java 2007-04-14
00:37:54 UTC (rev 84)
@@ -28,6 +28,9 @@
VelocityContext context = new VelocityContext();
Template template = getTemplate();
context.put("generator",this);
+
+ context.put("testDataGenerator", new TestDataGenerator(getClassLoader(),
getLog()));
+
// Put common properties
for (Iterator iter = config.iterator(); iter.hasNext();) {
ComponentBean component = (ComponentBean) iter.next();
Modified: trunk/cdk/generator/src/main/resources/META-INF/schema/component-config.dtd
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/schema/component-config.dtd 2007-04-13
18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/resources/META-INF/schema/component-config.dtd 2007-04-14
00:37:54 UTC (rev 84)
@@ -48,7 +48,7 @@
bodyContent (JSP|empty) "JSP"
-<!ELEMENT test (classname,superclassname)>
+<!ELEMENT test (classname?,superclassname?)>
<!--!ELEMENT classname (#PCDATA)-->
<!ELEMENT superclassname (#PCDATA)>
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm 2007-04-13
18:57:52 UTC (rev 83)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/componenttest.vm 2007-04-14
00:37:54 UTC (rev 84)
@@ -33,6 +33,9 @@
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.component.UIViewRoot;
+
+import org.ajax4jsf.tests.MockValueBinding;
+
//import ${component.classname};
#if(${generator.key})
@@ -81,12 +84,8 @@
component.setId("component");
#foreach( $prop in $component.properties )
- #if(!$prop.exist && $prop.name != "value")
- #if($prop.classname == "java.lang.String")
- component.${prop.setterName}( " __$prop.name" );
- #elseif($prop.classname == "java.lang.Boolean")
- component.${prop.setterName}( new Boolean(true) );
- #end
+ #if(!$prop.exist && !$prop.elonly &&
!$prop.classname.startsWith("javax.faces."))
+ component.${prop.setterName}($testDataGenerator.getTestData(${prop}) );
#end
#end
@@ -104,13 +103,17 @@
}
public void testComponent() throws Exception {
-
+ #if(${component.renderer})
+ assertEquals("${component.renderer.name}", component.getRendererType());
+ #end
+
+/*
HtmlPage renderedView = renderView();
assertNotNull(renderedView);
System.out.println(renderedView.getWebResponse().getContentAsString());
HtmlElement element = renderedView.getHtmlElementById(form.getId() + ":" +
component.getId());
assertNotNull(element);
-
+*/
// values[0] = component.saveState(facesContext);
}
@@ -122,15 +125,30 @@
public void testContext(){
Object state = component.saveState(facesContext);
-
+/*
UIViewRoot root = facesContext.getViewRoot();
root.processDecodes(facesContext);
root.processValidators(facesContext);
root.processUpdates(facesContext);
root.processApplication(facesContext);
-
+*/
testRestoreState(state);
}
+
+ public void testGetters() {
+ ${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
+#end
+
+
+ }
private void testRestoreState(Object state){
${component.simpleClassName} restoredComponent = new ${component.simpleClassName}();
@@ -144,4 +162,11 @@
}
-}
\ No newline at end of file
+ private void assertEquals(double d1, double d2) {
+ assertEquals(d1, d2, 0);
+ }
+
+ private void assertEquals(float d1, float d2) {
+ assertEquals(d1, d2, 0);
+ }
+}