KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > querying > impl > xtas > TestObjectMarshalling


1 package org.exoplatform.services.xml.querying.impl.xtas;
2
3 import junit.framework.TestCase;
4 import junit.framework.Test;
5 import junit.framework.TestSuite;
6
7 import org.xml.sax.InputSource JavaDoc;
8 import java.io.*;
9 import java.util.Iterator JavaDoc;
10 import java.util.ArrayList JavaDoc;
11 import org.exoplatform.services.xml.querying.impl.xtas.BaseStatement;
12 import org.exoplatform.services.xml.querying.impl.xtas.Query;
13 import org.exoplatform.services.xml.querying.impl.xtas.UniFormTreeFragment;
14 import org.exoplatform.services.xml.querying.impl.xtas.XTASMLStatement;
15 import org.w3c.dom.Node JavaDoc;
16 import org.w3c.dom.NodeList JavaDoc;
17 import org.w3c.dom.Document JavaDoc;
18 /*
19 import org.exoplatform.services.xml.querying.impl.xtas.BaseStatement;
20 import org.exoplatform.services.xml.querying.impl.xtas.XTASMLStatement;
21 import org.exoplatform.services.xml.querying.impl.xtas.Query;
22 import org.exoplatform.services.xml.querying.impl.xtas.UniFormTreeFragment;
23 import org.exoplatform.services.xml.querying.impl.xtas.WellFormedUniFormTree;
24 import org.exoplatform.services.xml.querying.impl.xtas.UniFormConverter;
25 */

26 /**
27  * Test Case for Object Marshalling related things
28  * @version $Id: TestObjectMarshalling.java 566 2005-01-25 12:50:49Z kravchuk $
29  */

30 public class TestObjectMarshalling extends TestCase {
31
32     public TestObjectMarshalling(String JavaDoc name)
33     {
34         super(name);
35     }
36     public static Test suite()
37     {
38         return new TestSuite(TestObjectMarshalling.class);
39     }
40
41
42     public void testSimpleBeanWMapping()
43     {
44         ArrayList JavaDoc list = new ArrayList JavaDoc();
45 /*
46         try {
47
48             BaseStatement qc = new XTASMLStatement ("tmp/test-bean-query.xml");
49             Query q = new Query (qc);
50             q.execute();
51
52 // InputSource mapping = new InputSource(new FileReader("tmp/mapping1.xml"));
53
54 // UniFormTreeFragment ro = UniFormConverter.toFragment(q.getResult());
55
56             UniFormTreeFragment ro = (UniFormTreeFragment)q.getResult();
57
58 //System.out.println("RO -> "+ro.getAsCollection( "tmp/mapping1.xml" ));
59
60             Iterator i = ro.getAsCollection( "tmp/mapping1.xml" ).iterator();
61
62             while(i.hasNext()) {
63
64               TmpBean tb = (TmpBean)i.next();
65               list.add(tb);
66
67            }
68
69         } catch ( Exception e ) {
70             e.printStackTrace();
71             fail( " testSimpleBean() failed ! "+e.toString());
72
73         }
74
75
76         this.assertEquals("Bean(0).property not equal","Test String#1",((TmpBean)list.get(0)).getProperty());
77         this.assertEquals("Bean(0).e1 not equal",new Integer(1),((TmpBean)list.get(0)).getE1());
78         this.assertNull("Bean(0).f2 not null",((TmpBean)list.get(0)).getF2());
79
80         this.assertEquals("Bean(1).property not equal",((TmpBean)list.get(1)).getProperty(),"Test String#2");
81         this.assertEquals("Bean(1).e1 not equal",((TmpBean)list.get(1)).getE1(),new Integer(2));
82         this.assertEquals("Bean(1).f2 not equal",((TmpBean)list.get(1)).getF2(),new Float(2.22f));
83
84         this.assertNull("Bean(4).property not null",((TmpBean)list.get(4)).getProperty());
85 */

86
87     }
88
89
90
91     public void testSimpleBeanWOMapping()
92     {
93         ArrayList JavaDoc list = new ArrayList JavaDoc();
94         try {
95
96             BaseStatement qc = new XTASMLStatement ("tmp/test-bean-query.xml");
97             Query q = new Query (qc);
98             q.execute();
99
100 // UniFormTree ro = q.getResult();
101

102
103             UniFormTreeFragment ro = (UniFormTreeFragment)q.getResult();
104
105 //System.out.println("RO -> "+ro);
106

107
108             Iterator JavaDoc i = ro.getAsCollection( TmpBean.class ).iterator();
109
110             while(i.hasNext()) {
111
112               TmpBean tb = (TmpBean)i.next();
113               list.add(tb);
114
115            }
116
117         } catch ( Exception JavaDoc e ) {
118 // e.printStackTrace();
119
fail( " testSimpleBeanWOMapping() failed ! "+e.toString());
120
121         }
122
123         assertEquals("Bean(0).property not equal",((TmpBean)list.get(0)).getProperty(),"Test String#1");
124         assertEquals("Bean(0).e1 not equal",((TmpBean)list.get(0)).getE1(),new Integer JavaDoc(1));
125         assertNull("Bean(0).f2 not null",((TmpBean)list.get(0)).getF2());
126
127         assertEquals("Bean(1).property not equal",((TmpBean)list.get(1)).getProperty(),"Test String#2");
128         assertEquals("Bean(1).e1 not equal",((TmpBean)list.get(1)).getE1(),new Integer JavaDoc(2));
129         assertEquals("Bean(1).f2 not equal",((TmpBean)list.get(1)).getF2(),new Float JavaDoc(2.22f));
130
131         assertNull("Bean(4).property not null",((TmpBean)list.get(4)).getProperty());
132
133     }
134
135     public void testSimpleBeanWOMapping1()
136     {
137
138         ArrayList JavaDoc list = new ArrayList JavaDoc();
139         try {
140
141             BaseStatement qc = new XTASMLStatement ("tmp/test-addresses.xml");
142             Query q = new Query (qc);
143             q.execute();
144
145 // UniFormTree ro = q.getResult();
146
UniFormTreeFragment ro = (UniFormTreeFragment)q.getResult();
147
148             Addresses a = (Addresses) ro.getAsCollection( Addresses.class ).iterator().next();
149
150             // Mapped to Array of Objects !!!
151
Address[] a1 = a.getAddresses();
152 // System.out.println(a1+" "+a.getCountry());
153

154 // for(int i=0;i<a1.length;i++)
155
// System.out.println(a1[i].getStreet1()+" "+a1[i].getZip());
156

157            assertEquals("","Ukraine",a.getCountry());
158            assertEquals("","Kiev",a1[0].getCity());
159            assertEquals("","Cherkassy",a1[1].getCity());
160
161
162         } catch ( Exception JavaDoc e ) {
163 // e.printStackTrace();
164
fail( " testSimpleBeanWOMapping1() failed ! "+e.toString());
165
166         }
167
168     }
169
170
171     public void testMarshallingWOMapping()
172     {
173 /*
174         try {
175
176              String testStr = "<test-bean><property>Test String</property><e1>1</e1><f2>0.1</f2></test-bean>";
177             TmpBean tb = new TmpBean("Test String", new Integer(1), new Float(0.1f));
178
179             WellFormedUniFormTree ro = new WellFormedUniFormTree ();
180
181 // UniFormTreeFragment ro = new UniFormTreeFragment();
182
183             ro.init( tb );
184             assertEquals(testStr, util.packXmlString(ro.toString()));
185
186 // System.out.println( ro );
187
188         } catch ( Exception e ) {
189 // e.printStackTrace();
190             fail( " testMarshallingWOMapping() failed ! "+e.toString());
191
192         }
193   */

194
195     }
196
197
198     public void testMarshallingWMapping()
199     {
200 /*
201         try {
202
203              String testStr = "<bean property=\"Test String\"><e1>1</e1><f2>0.1</f2></bean>";
204             TmpBean tb = new TmpBean("Test String", new Integer(1), new Float(0.1f));
205
206 // UniFormTree ro = new UniFormTree( tb );
207
208             WellFormedUniFormTree ro = new WellFormedUniFormTree ();
209             ro.init( "tmp/mapping1.xml", tb );
210
211             assertEquals(testStr, util.packXmlString(ro.toString()));
212
213 // System.out.println( ro );
214
215         } catch ( Exception e ) {
216 // e.printStackTrace();
217             fail( " testMarshallingWMapping() failed ! "+e.toString());
218
219         }
220 */

221
222     }
223
224
225     public void testMarshallingWMapping1()
226     {
227 /*
228         try {
229
230             EmployeeBean eb = new EmployeeBean();
231             eb.setId("N1");
232             eb.setFirstname("One");
233             eb.setLastname("Man");
234
235             WellFormedUniFormTree ro = new WellFormedUniFormTree ();
236             ro.init( "tmp/employees-map.xml", eb );
237
238
239             EmployeeBean eb1 = (EmployeeBean) UniFormConverter.toFragment(ro).getAsCollection(EmployeeBean.class).iterator().next();
240
241             assertEquals("",eb.getId(),eb1.getId());
242            assertEquals("",eb.getFirstname(), eb1.getFirstname());
243            assertEquals("",eb.getLastname(), eb1.getLastname());
244
245 // System.out.println( UniFormConverter.toFragment(ro) );
246
247 // assertEquals(testStr, util.packXmlString(ro.toString()));
248
249
250         } catch ( Exception e ) {
251 // e.printStackTrace();
252             fail( " testMarshallingWMapping() failed ! "+e.toString());
253
254         }
255 */

256
257     }
258
259
260 }
261
Popular Tags