Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/xpn/xwiki/test/ViewEditTest.java


1   
2   package com.xpn.xwiki.test;
3   
4   import com.xpn.xwiki.XWikiException;
5   import com.xpn.xwiki.doc.XWikiAttachment;
6   import com.xpn.xwiki.doc.XWikiDocument;
7   import com.xpn.xwiki.doc.XWikiLock;
8   import com.xpn.xwiki.objects.BaseObject;
9   import com.xpn.xwiki.objects.ListProperty;
10  import com.xpn.xwiki.objects.NumberProperty;
11  import com.xpn.xwiki.objects.StringProperty;
12  import com.xpn.xwiki.objects.classes.BaseClass;
13  import com.xpn.xwiki.objects.classes.NumberClass;
14  import com.xpn.xwiki.objects.classes.StringClass;
15  import com.xpn.xwiki.objects.classes.DateClass;
16  import com.xpn.xwiki.store.XWikiCacheStoreInterface;
17  import com.xpn.xwiki.store.XWikiHibernateStore;
18  import com.xpn.xwiki.store.XWikiStoreInterface;
19  import org.hibernate.HibernateException;
20  import org.apache.cactus.WebRequest;
21  import org.apache.cactus.WebResponse;
22  import org.apache.commons.httpclient.methods.multipart.FilePart;
23  import org.apache.commons.httpclient.methods.multipart.Part;
24  import org.apache.struts.action.ActionServlet;
25  import org.dom4j.DocumentException;
26  
27  import javax.servlet.ServletException;
28  import java.io.File;
29  import java.io.IOException;
30  import java.io.PipedInputStream;
31  import java.io.PipedOutputStream;
32  import java.text.ParseException;
33  import java.util.HashMap;
34  import java.util.List;
35  import java.util.Map;
36  import java.util.Vector;
37  
38  /**
39   * ===================================================================
40   *
41   * Copyright (c) 2003 Ludovic Dubost, All rights reserved.
42   *
43   * This program is free software; you can redistribute it and/or
44   * modify it under the terms of the GNU General Public License
45   * as published by the Free Software Foundation; either version 2
46   * of the License, or (at your option) any later version.
47   *
48   * This program is distributed in the hope that it will be useful,
49   * but WITHOUT ANY WARRANTY; without even the implied warranty of
50   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
51   * GNU General Public License for more details, published at
52   * http://www.gnu.org/copyleft/gpl.html or in gpl.txt in the
53   * root folder of this distribution.
54  
55   * Created by
56   * User: Ludovic Dubost
57   * Date: 11 janv. 2004
58   * Time: 12:08:01
59   */
60  
61  public class ViewEditTest extends ServletTest {
62  
63      public void beginViewNotOk(WebRequest webRequest) throws HibernateException, XWikiException {
64          XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
65          StoreHibernateTest.cleanUp(hibstore, context);
66          clientSetUp(hibstore);
67          setUrl(webRequest, "view", "ViewNotOkTest");
68      }
69  
70      public void endViewNotOk(WebResponse webResponse) throws HibernateException {
71          try {
72              String result = webResponse.getText();
73              assertTrue("Page should have no version: " + result, result.indexOf("1.1")==-1);
74          } finally {
75              clientTearDown();
76          }
77      }
78  
79      public void testViewNotOk() throws Throwable {
80          launchTest();
81      }
82  
83      public void beginViewOk(WebRequest webRequest) throws HibernateException, XWikiException {
84          XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
85          StoreHibernateTest.cleanUp(hibstore, context);
86          clientSetUp(hibstore);
87          String content = Utils.content1;
88          Utils.content1 = "Hello $doc.name\n----\n";
89          Utils.createDoc(hibstore, "Main", "ViewOkTest", context);
90          Utils.content1 = content;
91          setUrl(webRequest, "view", "ViewOkTest");
92      }
93  
94      public void endViewOk(WebResponse webResponse) throws HibernateException {
95          try {
96              String result = webResponse.getText();
97              assertTrue("Could not find Hello in Content: " + result, result.indexOf("Hello")!=-1);
98              assertTrue("Could not find page name in content: " + result, result.indexOf("ViewOkTest")!=-1);
99              assertTrue("Could not find hr in content: " + result, result.indexOf("<hr")!=-1);
100         } finally {
101             clientTearDown();
102         }
103     }
104 
105     public void testViewOk() throws IOException, Throwable {
106         launchTest();
107     }
108 
109     public void beginViewRawOk(WebRequest webRequest) throws HibernateException, XWikiException {
110         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
111         StoreHibernateTest.cleanUp(hibstore, context);
112         clientSetUp(hibstore);
113         String content = Utils.content1;
114         Utils.content1 = "Hello $doc.name\n----\n";
115         Utils.createDoc(hibstore, "Main", "ViewRawOkTest", context);
116         Utils.content1 = content;
117         setUrl(webRequest, "view", "ViewRawOkTest");
118         webRequest.addParameter("raw","1");
119     }
120 
121     public void endViewRawOk(WebResponse webResponse) throws HibernateException {
122         try {
123             String result = webResponse.getText();
124             assertTrue("Could not find Hello in Content: " + result, result.indexOf("Hello")!=-1);
125             assertTrue("Could not find raw page name in content: " + result, result.indexOf("$doc.name")!=-1);
126             assertTrue("Could not find raw hr in content: " + result, result.indexOf("----")!=-1);
127         } finally {
128             clientTearDown();
129         }
130     }
131 
132     public void testViewRawOk() throws IOException, Throwable {
133         launchTest();
134     }
135 
136     public void beginViewCodeOk(WebRequest webRequest) throws HibernateException, XWikiException {
137         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
138         StoreHibernateTest.cleanUp(hibstore, context);
139         clientSetUp(hibstore);
140         String content = Utils.content1;
141         Utils.content1 = "Hello $doc.name\n----\n";
142         Utils.createDoc(hibstore, "Main", "ViewRawOkTest", context);
143         Utils.content1 = content;
144         setUrl(webRequest, "view", "ViewRawOkTest");
145         webRequest.addParameter("xpage","code");
146     }
147 
148     public void endViewCodeOk(WebResponse webResponse) throws HibernateException {
149         try {
150             String result = webResponse.getText();
151             assertTrue("Could not find Hello in Content: " + result, result.indexOf("Hello")!=-1);
152             assertTrue("Could not find raw page name in content: " + result, result.indexOf("$doc.name")!=-1);
153             assertTrue("Could not find raw hr in content: " + result, result.indexOf("----")!=-1);
154         } finally {
155             clientTearDown();
156         }
157     }
158 
159     public void testViewCodeOk() throws IOException, Throwable {
160         launchTest();
161     }
162 
163     public void beginViewXMLOk(WebRequest webRequest) throws HibernateException, XWikiException {
164         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
165         StoreHibernateTest.cleanUp(hibstore, context);
166         clientSetUp(hibstore);
167         String content = Utils.content1;
168         Utils.content1 = "Hello $doc.name\n----\n";
169         Utils.createDoc(hibstore, "Main", "ViewXMLOkTest", context);
170         Utils.content1 = content;
171         setUrl(webRequest, "view", "ViewXMLOkTest");
172         webRequest.addParameter("xpage","xml");
173     }
174 
175     public void endViewXMLOk(WebResponse webResponse) throws HibernateException, IllegalAccessException, DocumentException, ParseException, ClassNotFoundException, InstantiationException, XWikiException {
176         try {
177             String result = webResponse.getText();
178             assertTrue("Could not find Hello in Content: " + result, result.indexOf("Hello")!=-1);
179             assertTrue("Could not find raw page name in content: " + result, result.indexOf("$doc.name")!=-1);
180             assertTrue("Could not find raw hr in content: " + result, result.indexOf("----")!=-1);
181             assertTrue("Could not find xml tags in content: " + result, result.indexOf("<content")!=-1);
182 
183             XWikiDocument doc1 = (XWikiDocument) xwiki.getDocument("Main.ViewXMLOkTest", context);
184             XWikiDocument doc2 = new XWikiDocument();
185             doc2.fromXML(result);
186             Utils.assertEquals(doc1, doc2);
187         } finally {
188             clientTearDown();
189         }
190     }
191 
192     public void testViewXMLOk() throws IOException, Throwable {
193         launchTest();
194     }
195 
196 
197     public void beginViewGetDocument(WebRequest webRequest) throws HibernateException, XWikiException {
198         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
199         StoreHibernateTest.cleanUp(hibstore, context);
200         clientSetUp(hibstore);
201         Utils.createDoc(hibstore, "Main", "ViewGetDocumentContent", context);
202         String content = Utils.content1;
203         Utils.content1 = "test\n$xwiki.getDocument(\"Main.ViewGetDocumentContent\").getContent()\ntest\n";
204         Utils.createDoc(hibstore, "Main", "ViewGetDocument", context);
205         Utils.content1 = content;
206         setUrl(webRequest, "view", "ViewGetDocument");
207     }
208 
209     public void endViewGetDocument(WebResponse webResponse) throws HibernateException {
210         try {
211             String result = webResponse.getText();
212             assertTrue("Could not find content in result:\n" + result, result.indexOf("Hello")!=-1);
213         } finally {
214             clientTearDown();
215         }
216     }
217 
218     public void testViewGetDocument() throws Throwable {
219         launchTest();
220     }
221 
222 
223     public void beginViewDocumentLink(WebRequest webRequest) throws HibernateException, XWikiException {
224         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
225         StoreHibernateTest.cleanUp(hibstore, context);
226         clientSetUp(hibstore);
227         // Utils.createDoc(hibstore, "Main", "ViewDocumentTestLinkTest", context);
228         String content = Utils.content1;
229         Utils.content1 = "[Main.ViewDocumentLink]";
230         Utils.createDoc(hibstore, "Main", "ViewDocumentLink", context);
231         Utils.content1 = content;
232         setUrl(webRequest, "view", "ViewDocumentLink");
233     }
234 
235     public void endViewDocumentLink(WebResponse webResponse) throws HibernateException {
236         try {
237             String result = webResponse.getText();
238             assertTrue("Could not find content in result:\n" + result, result.indexOf("<a href")!=-1);
239         } finally {
240             clientTearDown();
241         }
242     }
243 
244     public void testViewDocumentLink() throws Throwable {
245         launchTest();
246     }
247 
248 
249     public void beginPreviewOk(WebRequest webRequest) throws HibernateException, XWikiException {
250         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
251         StoreHibernateTest.cleanUp(hibstore, context);
252         clientSetUp(hibstore);
253         XWikiDocument doc = new XWikiDocument();
254         Utils.prepareObject(doc, "Main.PreviewOkTest");
255         BaseClass bclass = doc.getxWikiClass();
256         BaseObject bobject = doc.getObject(bclass.getName(), 0);
257         Utils.createDoc(hibstore, "Main", "PreviewOkTest", bobject, bclass, context);
258         setUrl(webRequest, "preview", "PreviewOkTest");
259     }
260 
261     public void endPreviewOk(WebResponse webResponse) throws HibernateException {
262         try {
263             String result = webResponse.getText();
264             assertTrue("Could not find WebHome Content: " + result, result.indexOf("Hello")!=-1);
265             assertTrue("Could not find object hidden form nb: " + result, result.indexOf("<input type=\"hidden\" name=\"Main.PreviewOkTest_nb\" value=\"1\"")!=-1);
266             assertTrue("Could not find object hidden form value: " + result, result.indexOf("Main.PreviewOkTest_0_first_name")!=-1);
267             assertTrue("Could not find object hidden form value: " + result, result.indexOf("Ludovic")!=-1);
268         } finally {
269             clientTearDown();
270         }
271     }
272 
273     public void testPreviewOk() throws Throwable {
274         launchTest();
275     }
276 
277     public void beginEditOk(WebRequest webRequest) throws HibernateException, XWikiException {
278         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
279         StoreHibernateTest.cleanUp(hibstore, context);
280         clientSetUp(hibstore);
281         XWikiDocument doc = new XWikiDocument();
282         Utils.prepareObject(doc, "Main.EditOkTest");
283         BaseClass bclass = doc.getxWikiClass();
284         BaseObject bobject = doc.getObject(bclass.getName(), 0);
285         Utils.createDoc(hibstore, "Main", "EditOkTest", bobject, bclass, context);
286         setUrl(webRequest, "edit", "EditOkTest");
287     }
288 
289     public void endEditOk(WebResponse webResponse) throws HibernateException {
290         try {
291             String result = webResponse.getText();
292             assertTrue("Could not find WebHome Content: " + result, result.indexOf("Hello")!=-1);
293         } finally {
294             clientTearDown();
295         }
296     }
297 
298     public void testEditOk() throws Throwable {
299         launchTest();
300     }
301 
302 
303     public void beginEditObjectOk(WebRequest webRequest) throws HibernateException, XWikiException {
304         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
305         StoreHibernateTest.cleanUp(hibstore, context);
306         clientSetUp(hibstore);
307         XWikiDocument doc = new XWikiDocument();
308         Utils.prepareObject(doc, "Main.EditObjectOkTest");
309         BaseClass bclass = doc.getxWikiClass();
310         BaseObject bobject = doc.getObject(bclass.getName(), 0);
311         Utils.createDoc(hibstore, "Main", "EditObjectOkTest", bobject, bclass, context);
312         setUrl(webRequest, "edit", "EditObjectOkTest");
313         webRequest.addParameter("xpage", "editobject");
314     }
315 
316     public void endEditObjectOk(WebResponse webResponse) throws HibernateException {
317         try {
318             String result = webResponse.getText();
319             assertTrue("Could not find object hidden form nb: " + result, result.indexOf("<input type=\"hidden\" name=\"Main.EditObjectOkTest_nb\" value=\"1\"")!=-1);
320             assertTrue("Could not find object form value: " + result, result.indexOf("Main.EditObjectOkTest_0_first_name")!=-1);
321             assertTrue("Could not find object form value: " + result, result.indexOf("Ludovic")!=-1);
322         } finally {
323             clientTearDown();
324         }
325     }
326 
327     public void testEditObjectOk() throws Throwable {
328         launchTest();
329     }
330 
331 
332     public void beginEditClassOk(WebRequest webRequest) throws HibernateException, XWikiException {
333         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
334         StoreHibernateTest.cleanUp(hibstore, context);
335         clientSetUp(hibstore);
336         XWikiDocument doc = new XWikiDocument();
337         Utils.prepareObject(doc, "Main.EditClassOkTest");
338         BaseClass bclass = doc.getxWikiClass();
339         BaseObject bobject = doc.getObject(bclass.getName(), 0);
340         Utils.createDoc(hibstore, "Main", "EditClassOkTest", bobject, bclass, context);
341         setUrl(webRequest, "edit", "EditClassOkTest");
342         webRequest.addParameter("xpage", "editclass");
343     }
344 
345     public void endEditClassOk(WebResponse webResponse) throws HibernateException {
346         try {
347             String result = webResponse.getText();
348             assertTrue("Could not find Add Class: " + result, result.indexOf("com.xpn.xwiki.objects.classes.NumberClass")!=-1);
349             assertTrue("Could not find Add Class: " + result, result.indexOf("com.xpn.xwiki.objects.classes.StringClass")!=-1);
350             assertTrue("Could not find Add Class: " + result, result.indexOf("com.xpn.xwiki.objects.classes.TextAreaClass")!=-1);
351             assertTrue("Could not find Add Class: " + result, result.indexOf("com.xpn.xwiki.objects.classes.PasswordClass")!=-1);
352             assertTrue("Could not find Add Class: " + result, result.indexOf("com.xpn.xwiki.objects.classes.BooleanClass")!=-1);
353             assertTrue("Could not find Add Class: " + result, result.indexOf("com.xpn.xwiki.objects.classes.DBListClass")!=-1);
354         } finally {
355             clientTearDown();
356         }
357     }
358 
359     public void testEditClassOk() throws Throwable {
360            launchTest();
361        }
362 
363 
364     public void beginEditWithTemplateOk(WebRequest webRequest) throws HibernateException, XWikiException {
365         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
366         StoreHibernateTest.cleanUp(hibstore, context);
367         clientSetUp(hibstore);
368         XWikiDocument doc = new XWikiDocument();
369         Utils.prepareObject(doc, "Main.EditOkTestTemplate");
370         BaseClass bclass = doc.getxWikiClass();
371         BaseObject bobject = doc.getObject(bclass.getName(), 0);
372         String content = Utils.content1;
373         Utils.content1 = "Template content";
374         Utils.createDoc(hibstore, "Main", "EditOkTestTemplate", bobject, bclass, context);
375         Utils.content1 = content;
376         setUrl(webRequest, "edit", "EditOkWithTestTemplate");
377         webRequest.addParameter("template", "Main.EditOkTestTemplate");
378         webRequest.addParameter("parent", "XWiki.TestParentComesFromTemplate");
379     }
380 
381     public void endEditWithTemplateOk(WebResponse webResponse) throws HibernateException {
382         try {
383             String result = webResponse.getText();
384             assertTrue("Could not find WebHome Content: " + result, result.indexOf("Template content")!=-1);
385             assertTrue("Could not find parent: " + result, result.indexOf("TestParentComesFromTemplate")!=-1);
386         } finally {
387             clientTearDown();
388         }
389     }
390 
391     public void testEditWithTemplateOk() throws Throwable {
392         launchTest();
393     }
394 
395 
396     public void testEditWithTemplateNotOk() throws Throwable {
397         try {
398             launchTest();
399         } catch (XWikiException e) {
400         }
401     }
402 
403     public void beginEditWithTemplateNotOk(WebRequest webRequest) throws HibernateException, XWikiException {
404         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
405         StoreHibernateTest.cleanUp(hibstore, context);
406         clientSetUp(hibstore);
407 
408         // Document already exist.. This will make template system fail
409         Utils.createDoc(hibstore, "Main", "EditOkTestWithTemplate", context);
410         XWikiDocument doc = new XWikiDocument();
411         Utils.prepareObject(doc, "Main.EditOkTestTemplate");
412         BaseClass bclass = doc.getxWikiClass();
413         BaseObject bobject = doc.getObject(bclass.getName(), 0);
414         String content = Utils.content1;
415         Utils.content1 = "Template content";
416         Utils.createDoc(hibstore, "Main", "EditOkTestTemplate", bobject, bclass, context);
417         Utils.content1 = content;
418         setUrl(webRequest, "edit", "EditOkTestWithTemplate");
419         webRequest.addParameter("template", "Main.EditOkTestTemplate");
420         webRequest.addParameter("parent", "XWiki.TestParentComesFromTemplate");
421     }
422 
423     public void endEditWithTemplateNotOk(WebResponse webResponse) throws HibernateException {
424         try {
425             String result = webResponse.getText();
426             assertFalse("Template content should be ignored: " + result, result.indexOf("Template content")!=-1);
427         } finally {
428             clientTearDown();
429         }
430     }
431 
432     public void testSaveWithTemplateOk() throws Throwable {
433         launchTest();
434     }
435 
436 
437     public void beginSaveWithTemplateOk(WebRequest webRequest) throws HibernateException, XWikiException {
438         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
439         StoreHibernateTest.cleanUp(hibstore, context);
440         clientSetUp(hibstore);
441         XWikiDocument doc = new XWikiDocument();
442         Utils.prepareObject(doc, "Main.SaveOkTestTemplate");
443         BaseClass bclass = doc.getxWikiClass();
444         BaseObject bobject = doc.getObject(bclass.getName(), 0);
445         String content = Utils.content1;
446         Utils.content1 = "Template content";
447         Utils.createDoc(hibstore, "Main", "SaveOkTestTemplate", bobject, bclass, context);
448         Utils.content1 = content;
449         setUrl(webRequest, "save", "SaveOkWithTestTemplate");
450         webRequest.addParameter("template", "Main.SaveOkTestTemplate");
451         webRequest.addParameter("parent", "XWiki.TestParentComesFromTemplate");
452         webRequest.addParameter("content", "Template content");
453     }
454 
455     public void endSaveWithTemplateOk(WebResponse webResponse) throws HibernateException, XWikiException {
456         try {
457             String result = webResponse.getText();
458             // Verify return
459             assertTrue("Saving returned exception: " + result, result.indexOf("Exception")==-1);
460 
461             XWikiStoreInterface hibstore = new XWikiHibernateStore(getHibpath());
462             XWikiDocument doc2 = new XWikiDocument("Main", "SaveOkWithTestTemplate");
463             doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
464             String content2 = doc2.getContent();
465             assertEquals("Content is not identical", "Template content",content2);
466             assertEquals("Parent is not identical", "XWiki.TestParentComesFromTemplate", doc2.getParent());
467         } finally {
468             clientTearDown();
469         }
470     }
471 
472     public void beginViewLatestRevOk(WebRequest webRequest) throws HibernateException, XWikiException {
473         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
474         StoreHibernateTest.cleanUp(hibstore, context);
475         clientSetUp(hibstore);
476         String content = Utils.content1;
477         Utils.content1 = "Hello $doc.name\n----\n";
478         Utils.createDoc(hibstore, "Main", "ViewRevOkTest", context);
479         Utils.content1 = content;
480         XWikiDocument doc2 = new XWikiDocument("Main", "ViewRevOkTest");
481         doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
482         doc2.setContent("zzzzzzzzzzzzzzzzzzzzzzzz");
483         hibstore.saveXWikiDoc(doc2, context);
484         setUrl(webRequest, "view", "ViewRevOkTest", "");
485         webRequest.addParameter("rev", "1.2");
486     }
487 
488 
489 
490     public void endViewLatestRevOk(WebResponse webResponse) throws XWikiException, HibernateException {
491         try {
492             String result = webResponse.getText();
493             assertTrue("Could not find zzz in Content: " + result, result.indexOf("zzzzzzzzzzzzzzzzzzzzzzzz")!=-1);
494         } finally {
495             clientTearDown();
496         }
497     }
498 
499     public void testViewLatestRevOk() throws Throwable {
500         launchTest();
501     }
502 
503 
504     public void beginViewRevOk(WebRequest webRequest) throws HibernateException, XWikiException {
505         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
506         StoreHibernateTest.cleanUp(hibstore, context);
507         clientSetUp(hibstore);
508         String content = Utils.content1;
509         Utils.content1 = "Hello $doc.name\n----\n";
510         Utils.createDoc(hibstore, "Main", "ViewRevOkTest", context);
511         Utils.content1 = content;
512         XWikiDocument doc2 = new XWikiDocument("Main", "ViewRevOkTest");
513         doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
514         hibstore.saveXWikiDoc(doc2, context);
515         doc2.setContent("zzzzzzzzzzzzzzzzzzzzzzzz");
516         hibstore.saveXWikiDoc(doc2, context);
517         setUrl(webRequest, "view", "ViewRevOkTest", "");
518         webRequest.addParameter("rev", "1.2");
519     }
520 
521 
522 
523     public void endViewRevOk(WebResponse webResponse) throws XWikiException, HibernateException {
524         try {
525             String result = webResponse.getText();
526             assertTrue("Could not find Hello in Content: " + result, result.indexOf("Hello")!=-1);
527             assertTrue("Could not find raw page name in content: " + result, result.indexOf("ViewRevOkTest")!=-1);
528             assertTrue("Could not find raw hr in content: " + result, result.indexOf("<hr")!=-1);
529         } finally {
530             clientTearDown();
531         }
532     }
533 
534     public void testViewRevOk() throws Throwable {
535         launchTest();
536     }
537 
538 
539     public void beginViewRevWithObjOk(WebRequest webRequest) throws HibernateException, XWikiException {
540         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
541         StoreHibernateTest.cleanUp(hibstore, context);
542         clientSetUp(hibstore);
543         XWikiDocument doc = new XWikiDocument();
544         Utils.prepareObject(doc, "Main.ViewRevWithObjOkTest");
545         BaseClass bclass = doc.getxWikiClass();
546         BaseObject bobject = doc.getObject(bclass.getName(), 0);
547         String content = Utils.content1;
548         Utils.content1 = "Hello First name is $doc.first_name";
549         Utils.createDoc(hibstore, "Main", "ViewRevWithObjOkTest", bobject, bclass, context);
550         Utils.content1 = content;
551 
552         XWikiDocument doc2 = new XWikiDocument("Main", "ViewRevWithObjOkTest");
553         doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
554         hibstore.saveXWikiDoc(doc2, context);
555         doc2.setStringValue("Main.ViewRevWithObjOkTest", "first_name", "John");
556         doc2.setContent("Hello First name now is $doc.last_name");
557         hibstore.saveXWikiDoc(doc2, context);
558         setUrl(webRequest, "view", "ViewRevWithObjOkTest", "");
559         webRequest.addParameter("rev", "1.2");
560     }
561 
562 
563 
564     public void endViewRevWithObjOk(WebResponse webResponse) throws XWikiException, HibernateException {
565         try {
566             String result = webResponse.getText();
567             assertTrue("Could not find Hello in Content: " + result, result.indexOf("Hello")!=-1);
568             assertTrue("Could not find raw page name in content: " + result, result.indexOf("First name is Ludovic")!=-1);
569         } finally {
570             clientTearDown();
571         }
572     }
573 
574     public void testRollbackRevWithObjOk() throws Throwable {
575         launchTest();
576     }
577 
578     public void beginRollbackRevWithObjOk(WebRequest webRequest) throws HibernateException, XWikiException {
579         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
580         StoreHibernateTest.cleanUp(hibstore, context);
581         clientSetUp(hibstore);
582         XWikiDocument doc = new XWikiDocument();
583         Utils.prepareObject(doc, "Main.RollbackRevWithObjOkTest");
584         BaseClass bclass = doc.getxWikiClass();
585         BaseObject bobject = doc.getObject(bclass.getName(), 0);
586         String content = Utils.content1;
587         Utils.content1 = "Hello First name is $doc.first_name";
588         Utils.createDoc(hibstore, "Main", "RollbackRevWithObjOkTest", bobject, bclass, context);
589         Utils.content1 = content;
590 
591         XWikiDocument doc2 = new XWikiDocument("Main", "RollbackRevWithObjOkTest");
592         doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
593         hibstore.saveXWikiDoc(doc2, context);
594         doc2.setStringValue("Main.RollbackRevWithObjOkTest", "first_name", "John");
595         doc2.setContent("Hello First name now is $doc.last_name");
596         hibstore.saveXWikiDoc(doc2, context);
597         setUrl(webRequest, "rollback", "RollbackRevWithObjOkTest", "");
598         webRequest.addParameter("rev", "1.2");
599     }
600 
601     public void endRollbackRevWithObjOk(WebResponse webResponse) throws XWikiException, HibernateException {
602         try {
603             String result = webResponse.getText();
604 
605             XWikiStoreInterface hibstore = new XWikiHibernateStore(getHibpath());
606             XWikiDocument doc2 = new XWikiDocument("Main", "RollbackRevWithObjOkTest");
607             doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
608             String content2 = doc2.getContent();
609             String name = doc2.getStringValue("Main.RollbackRevWithObjOkTest", "first_name");
610 
611             assertEquals("Content has not been rolled back", "Hello First name is $doc.first_name", content2);
612             assertEquals("First name had not been rolledback", "Ludovic", name);
613             assertEquals("Version is incorrect", "1.4", doc2.getVersion());
614         } finally {
615             clientTearDown();
616         }
617     }
618 
619     public void testViewRevWithObjOk() throws Throwable {
620         launchTest();
621     }
622 
623     public void beginViewRawRevOk(WebRequest webRequest) throws HibernateException, XWikiException {
624         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
625         StoreHibernateTest.cleanUp(hibstore, context);
626         clientSetUp(hibstore);
627         String content = Utils.content1;
628         Utils.content1 = "Hello $doc.name\n----\n";
629         Utils.createDoc(hibstore, "Main", "ViewRawRevOkTest", context);
630         Utils.content1 = content;
631         XWikiDocument doc2 = new XWikiDocument("Main", "ViewRawRevOkTest");
632         doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
633         hibstore.saveXWikiDoc(doc2, context);
634         doc2.setContent("zzzzzzzzzzzzzzzzzzzzzzzz");
635         hibstore.saveXWikiDoc(doc2, context);
636         setUrl(webRequest, "view", "ViewRawRevOkTest", "");
637         webRequest.addParameter("rev","1.2");
638         webRequest.addParameter("raw","1");
639     }
640 
641 
642     public void endViewRawRevOk(WebResponse webResponse) throws XWikiException, HibernateException {
643         try {
644             String result = webResponse.getText();
645             assertTrue("Could not find Hello in Content: " + result, result.indexOf("Hello")!=-1);
646             assertTrue("Could not find raw page name in content: " + result, result.indexOf("$doc.name")!=-1);
647             assertTrue("Could not find raw hr in content: " + result, result.indexOf("----")!=-1);
648         } finally {
649             clientTearDown();
650         }
651     }
652 
653     public void testViewRawRevOk() throws Throwable {
654         launchTest();
655     }
656 
657     public void beginViewCodeRevOk(WebRequest webRequest) throws HibernateException, XWikiException {
658         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
659         StoreHibernateTest.cleanUp(hibstore, context);
660         clientSetUp(hibstore);
661         String content = Utils.content1;
662         Utils.content1 = "Hello $doc.name\n----\n";
663         Utils.createDoc(hibstore, "Main", "ViewRawRevOkTest", context);
664         Utils.content1 = content;
665         XWikiDocument doc2 = new XWikiDocument("Main", "ViewRawRevOkTest");
666         doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
667         hibstore.saveXWikiDoc(doc2, context);
668         doc2.setContent("zzzzzzzzzzzzzzzzzzzzzzzz");
669         hibstore.saveXWikiDoc(doc2, context);
670         setUrl(webRequest, "view", "ViewRawRevOkTest", "");
671         webRequest.addParameter("rev","1.2");
672         webRequest.addParameter("xpage","code");
673     }
674 
675 
676     public void endViewCodeRevOk(WebResponse webResponse) throws XWikiException, HibernateException {
677         try {
678             String result = webResponse.getText();
679             assertTrue("Could not find Hello in Content: " + result, result.indexOf("Hello")!=-1);
680             assertTrue("Could not find raw page name in content: " + result, result.indexOf("$doc.name")!=-1);
681             assertTrue("Could not find raw hr in content: " + result, result.indexOf("----")!=-1);
682         } finally {
683             clientTearDown();
684         }
685     }
686 
687     public void testViewCodeRevOk() throws Throwable {
688         launchTest();
689     }
690 
691     public void testSave() throws IOException, Throwable {
692         try {
693             ActionServlet servlet = new ActionServlet();
694             servlet.init(config);
695             servlet.service(request, response);
696             cleanSession(session);
697         } catch (ServletException e) {
698             e.getRootCause().printStackTrace();
699             throw e.getRootCause();
700         }
701 
702     }
703 
704     public void beginSave(WebRequest webRequest) throws HibernateException, XWikiException {
705         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
706         StoreHibernateTest.cleanUp(hibstore, context);
707         clientSetUp(hibstore);
708         setUrl(webRequest, "save", "SaveTest");
709         webRequest.addParameter("content","Hello1Hello2Hello3");
710         webRequest.addParameter("parent","Main.WebHome");
711     }
712 
713     public void endSave(WebResponse webResponse) throws XWikiException, HibernateException {
714         try {
715             String result = webResponse.getText();
716             // Verify return
717             assertTrue("Saving returned exception: " + result, result.indexOf("Exception")==-1);
718 
719             XWikiStoreInterface hibstore = new XWikiHibernateStore(getHibpath());
720             XWikiDocument doc2 = new XWikiDocument("Main", "SaveTest");
721             doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
722             String content2 = doc2.getContent();
723             assertEquals("Content is not indentical", "Hello1Hello2Hello3",content2);
724             assertEquals("Parent is not identical", "Main.WebHome", doc2.getParent());
725         } finally {
726             clientTearDown();
727         }
728     }
729 
730 
731     public void testDelete() throws Throwable {
732         launchTest();
733     }
734 
735     public void beginDelete(WebRequest webRequest) throws HibernateException, XWikiException {
736         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
737         StoreHibernateTest.cleanUp(hibstore, context);
738         clientSetUp(hibstore);
739         Utils.createDoc(hibstore, "Main", "DeleteTest", context);
740         setUrl(webRequest, "delete", "DeleteTest");
741         webRequest.addParameter("confirm","1");
742     }
743 
744     public void endDelete(WebResponse webResponse) throws XWikiException, HibernateException {
745         try {
746             String result = webResponse.getText();
747             // Verify return
748             assertTrue("Delete returned exception: " + result, result.indexOf("Exception")==-1);
749 
750             XWikiStoreInterface hibstore = new XWikiHibernateStore(getHibpath());
751             XWikiDocument doc2 = new XWikiDocument("Main", "DeleteTest");
752             doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
753 
754             assertTrue("Document should not exist", doc2.isNew());
755         } finally {
756             clientTearDown();
757         }
758     }
759 
760 
761     public void testDeleteWithoutConfirm() throws Throwable {
762         launchTest();
763     }
764 
765     public void beginDeleteWithoutConfirm(WebRequest webRequest) throws HibernateException, XWikiException {
766         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
767         StoreHibernateTest.cleanUp(hibstore, context);
768         clientSetUp(hibstore);
769         Utils.createDoc(hibstore, "Main", "DeleteTest2", context);
770         setUrl(webRequest, "delete", "DeleteTest2");
771     }
772 
773     public void endDeleteWithoutConfirm(WebResponse webResponse) throws XWikiException, HibernateException {
774         try {
775             String result = webResponse.getText();
776             // Verify return
777             assertTrue("DeleteWithoutConfirm returned exception: " + result, result.indexOf("Exception")==-1);
778 
779             XWikiStoreInterface hibstore = new XWikiHibernateStore(getHibpath());
780             XWikiDocument doc2 = new XWikiDocument("Main", "DeleteTest2");
781             doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
782 
783             assertFalse("Document should exist", doc2.isNew());
784         } finally {
785             clientTearDown();
786         }
787     }
788 
789 
790     public void testAddProp(Class cclass) throws Throwable {
791         launchTest();
792     }
793 
794     public void beginAddProp(WebRequest webRequest, String name, Class cclass) throws HibernateException, XWikiException {
795         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
796         StoreHibernateTest.cleanUp(hibstore, context);
797         clientSetUp(hibstore);
798         Utils.createDoc(hibstore, "Main", "PropAddTest", context);
799         setUrl(webRequest, "propadd", "PropAddTest");
800         webRequest.addParameter("propname", name);
801         webRequest.addParameter("proptype", cclass.getName());
802     }
803 
804     public void endAddProp(WebResponse webResponse, String name, Class cclass) throws XWikiException, HibernateException {
805         try {
806             String result = webResponse.getText();
807             // Verify return
808             assertTrue("Adding Property " + cclass.getName() + " returned exception: " + result, result.indexOf("Exception")==-1);
809             XWikiStoreInterface hibstore = new XWikiHibernateStore(getHibpath());
810             XWikiDocument doc2 = new XWikiDocument("Main", "PropAddTest");
811             doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
812             BaseClass bclass = doc2.getxWikiClass();
813             assertNotNull("Class does not exist for " + cclass.getName(), bclass);
814             assertNotNull("Property of type " + cclass.getName() + " has not been added", bclass.safeget(name));
815             assertEquals("Property type is not correct for " + cclass.getName(), cclass, bclass.safeget(name).getClass());
816         } finally {
817             clientTearDown();
818         }
819     }
820 
821     public void testAddNumberProp() throws IOException, Throwable {
822         testAddProp(NumberClass.class);
823     }
824 
825     public void beginAddNumberProp(WebRequest webRequest) throws HibernateException, XWikiException {
826         beginAddProp(webRequest, "score", NumberClass.class);
827     }
828 
829     public void endAddNumberProp(WebResponse response)  throws XWikiException, HibernateException {
830             endAddProp(response, "score", NumberClass.class);
831     }
832 
833     public void testAddDateProp() throws IOException, Throwable {
834         testAddProp(DateClass.class);
835     }
836 
837     public void beginAddDateProp(WebRequest webRequest) throws HibernateException, XWikiException {
838         beginAddProp(webRequest, "birthday", DateClass.class);
839     }
840 
841     public void endAddDateProp(WebResponse response)  throws XWikiException, HibernateException {
842             endAddProp(response, "birthday", DateClass.class);
843     }
844 
845     public void testAddStringProp() throws IOException, Throwable {
846         testAddProp(StringClass.class);
847     }
848 
849     public void beginAddStringProp(WebRequest webRequest) throws HibernateException, XWikiException {
850         beginAddProp(webRequest, "category", StringClass.class);
851     }
852 
853     public void endAddStringProp(WebResponse response)  throws XWikiException, HibernateException {
854             endAddProp(response, "category", StringClass.class);
855     }
856 
857     public void testAddObject() throws Throwable {
858         launchTest();
859     }
860 
861     public void beginAddObject(WebRequest webRequest) throws HibernateException, XWikiException {
862         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
863         StoreHibernateTest.cleanUp(hibstore, context);
864         clientSetUp(hibstore);
865         XWikiDocument doc = new XWikiDocument();
866         Utils.prepareObject(doc, "Main.PropAddObjectClass");
867         BaseClass bclass = doc.getxWikiClass();
868         BaseObject bobject = doc.getObject(bclass.getName(), 0);
869         Utils.createDoc(hibstore, "Main", "PropAddObjectClass", bobject, bclass, context);
870         Utils.createDoc(hibstore, "Main", "PropAddObject", context);
871         setUrl(webRequest, "objectadd", "PropAddObject");
872         webRequest.addParameter("classname", "Main.PropAddObjectClass");
873     }
874 
875     public void endAddObject(WebResponse webResponse) throws XWikiException, HibernateException {
876         try {
877             String result = webResponse.getText();
878             // Verify return
879             assertTrue("Adding Class returned exception: " + result, result.indexOf("Exception")==-1);
880             XWikiStoreInterface hibstore = new XWikiHibernateStore(getHibpath());
881             XWikiDocument doc2 = new XWikiDocument("Main", "PropAddObject");
882             doc2 = (XWikiDocument) hibstore.loadXWikiDoc(doc2, context);
883             Map bobjects = doc2.getxWikiObjects();
884             BaseObject bobject = null;
885             try { bobject = (BaseObject) doc2.getObject("Main.PropAddObjectClass", 0); }
886             catch (Exception e) {}
887             assertNotNull("Added Object does not exist", bobject);
888 
889             BaseClass bclass = bobject.getxWikiClass(context);
890             assertNotNull("Added Object does not have a wikiClass", bclass);
891 
892             assertNotNull("Added Object wikiClass should have ageclass property", bclass.safeget("age"));
893             assertNotNull("Added Object wikiClass should have nameclass property", bclass.safeget("first_name"));
894         } finally {
895             clientTearDown();
896         }
897     }
898 
899     public void testAddSecondObject() throws Throwable {
900         launchTest();
901     }
902 
903 
904     public void beginAddSecondObject(WebRequest webRequest) throws HibernateException, XWikiException {
905         XWikiHibernateStore hibstore = new XWikiHibernateStore(getHibpath());
906         StoreHibernateTest.cleanUp(hibstore, context);
907         clientSetUp(hibstore);
908         XWikiDocument doc = new XWikiDocument();
909         Utils.prepareObject(doc, "Main.PropAddSecondObjectClass");
910         BaseClass bclass = doc.getxWikiClass();
911         BaseObject bobject = doc.getObject(bclass.getName(), 0);
912         bclass.setName("PropAddSecondObjectClass");
913         Utils.createDoc(hibstore, "Main", "PropAddSecondObjectClass", bobject, bclass, context);
914         Map bobjects = new HashMap();
915         Vector bobjlist = new Vector();
916         bobject.setName("Main.PropAddSecondObject");
917         bobjlist.add(bobject);
918         bobjects.put("Main.PropAddSecondObjectClass", bobjlist);
919         Utils.createDoc(hibstore, "Main", "PropAddSecondObject", null, null, bobjects, context);
920         setUrl(webRequest, "objectadd", "PropAddSecondObject");
921         webRequest.addParameter("classname", "Main.PropAddSecondObjectClass");
922     }
923 
924     public void endAddSecondObject(WebResponse webResponse) throws XWikiException, HibernateException {
925         try {
926             String result = webResponse.getText();
927             // Verify return
928             assertTrue("Adding Class returned exception: " + result, result.indexOf(<