rdonkin 2003/07/13 14:30:27
Modified: betwixt/src/test/org/apache/commons/betwixt/digester
TestXMLIntrospectorHelper.java
betwixt/src/test/org/apache/commons/betwixt/dotbetwixt
MixedContentBean.java TestBeanToXml.java
TestXmlToBean.java
Log:
Added tests for simple reading of beans with mixed content. Patch submitted by Aslak
Hellesoy.
Revision Changes Path
1.4 +7 -8
jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/TestXMLIntrospectorHelper.java
Index: TestXMLIntrospectorHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/TestXMLIntrospectorHelper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestXMLIntrospectorHelper.java 5 Jun 2003 20:59:16 -0000 1.3
+++ TestXMLIntrospectorHelper.java 13 Jul 2003 21:30:27 -0000 1.4
@@ -127,10 +127,9 @@
PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
for (int i=0; i<properties.length; i++) {
if (propertyName.equals(properties[i].getName())) {
- NodeDescriptor desc = XMLIntrospectorHelper
+ NodeDescriptor desc = (NodeDescriptor) introspector
.createDescriptor(properties[i],
- introspector.isAttributesForPrimitives(),
- introspector);
+ introspector.isAttributesForPrimitives());
return desc;
}
}
1.2 +5 -3
jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/MixedContentBean.java
Index: MixedContentBean.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/MixedContentBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MixedContentBean.java 19 Mar 2003 22:57:40 -0000 1.1
+++ MixedContentBean.java 13 Jul 2003 21:30:27 -0000 1.2
@@ -79,6 +79,8 @@
setBeta(beta);
setGamma(gamma);
}
+
+ public MixedContentBean() {}
//--------------------------- Properties
1.11 +20 -4
jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestBeanToXml.java
Index: TestBeanToXml.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestBeanToXml.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TestBeanToXml.java 19 Mar 2003 22:57:40 -0000 1.10
+++ TestBeanToXml.java 13 Jul 2003 21:30:27 -0000 1.11
@@ -182,5 +182,21 @@
parseString(xml),
parseString(out.toString()));
}
+
+ /** Test output of bean with mixed content */
+ public void testSimpleMixedContent() throws Exception {
+ StringWriter out = new StringWriter();
+ out.write("<?xml version='1.0' encoding='UTF-8'?>");
+ BeanWriter writer = new BeanWriter( out );
+ writer.write( new MixedContentOne("Life,", "The Universe And Everything",
42) );
+
+ String xml = "<?xml version='1.0' encoding='UTF-8'?><deep-thought
alpha='Life,' gamma='42'>"
+ + "The Universe And Everything</deep-thought>";
+
+ xmlAssertIsomorphicContent(
+ parseString(xml),
+ parseString(out.toString()));
+ }
+
}
1.2 +28 -4
jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestXmlToBean.java
Index: TestXmlToBean.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestXmlToBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestXmlToBean.java 8 Apr 2003 13:42:48 -0000 1.1
+++ TestXmlToBean.java 13 Jul 2003 21:30:27 -0000 1.2
@@ -162,6 +162,30 @@
assertEquals("Bad item two wrong", "Death", badItems.get(1));
}
+
+ /** Test output of bean with mixed content */
+ public void testMixedContent() throws Exception {
+
+ StringReader xml = new StringReader(
+ "<?xml version='1.0' encoding='UTF-8'?><deep-thought alpha='Life'
gamma='42'>"
+ + "The Universe And Everything</deep-thought>");
+
+ //SimpleLog log = new SimpleLog("[testMixedContent:BeanRuleSet]");
+ //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
+ //BeanRuleSet.setLog(log);
+ //log = new SimpleLog("[testMixedContent:BeanReader]");
+ //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
+
+ BeanReader reader = new BeanReader();
+ //reader.setLog(log);
+ reader.registerBeanClass(MixedContentOne.class);
+ Object resultObject = reader.parse(xml);
+ assertEquals("Object is MixedContentOne", true, resultObject instanceof
MixedContentOne);
+ MixedContentOne result = (MixedContentOne) resultObject;
+ assertEquals("Property Alpha matches", "Life", result.getAlpha());
+ assertEquals("Property Beta matches", "The Universe And Everything",
result.getBeta());
+ assertEquals("Property Gamma matches", 42, result.getGamma());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]