1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.storage

File DocumentTest.java

 

Code metrics

0
34
11
1
166
97
11
0.32
3.09
11
1

Classes

Class Line # Actions
DocumentTest 38 34 0% 11 0
1.0100%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.storage;
21   
22    import java.util.HashMap;
23   
24    import org.apache.commons.httpclient.HttpMethod;
25    import org.apache.commons.lang.RandomStringUtils;
26    import org.junit.Assert;
27    import org.junit.Before;
28    import org.junit.Test;
29    import org.xwiki.test.storage.framework.AbstractTest;
30    import org.xwiki.test.storage.framework.StoreTestUtils;
31   
32    /**
33    * Test saving and downloading of attachments.
34    *
35    * @version $Id: 3b4a50945f8407498c883e654b5403132b5a2a19 $
36    * @since 3.2M1
37    */
 
38    public class DocumentTest extends AbstractTest
39    {
40    private String spaceName;
41    private String pageName;
42   
 
43  8 toggle @Before
44    public void setUp()
45    {
46  8 this.spaceName = this.getClass().getSimpleName();
47  8 this.pageName = this.getTestMethodName();
48    }
49   
 
50  2 toggle @Test
51    public void testRollback() throws Exception
52    {
53  2 final String spaceName = "DocumentTest";
54  2 final String pageName = "testRollback";
55   
56  2 final String versionOne = "This is version one";
57  2 final String versionTwo = "This is version two";
58   
59  2 final String pageURL = this.getAddressPrefix() + "get/" + spaceName + "/" + pageName + "?xpage=plain";
60   
61    // Delete the document if it exists.
62  2 doPostAsAdmin(spaceName, pageName, null, "delete", "confirm=1", null);
63   
64    // Create a document. v1.1
65  2 doPostAsAdmin(spaceName, pageName, null, "save", null,
 
66  2 toggle new HashMap<String, String>() {{
67  2 put("content", versionOne);
68    }});
69   
70    // Change the document v2.1
71  2 doPostAsAdmin(spaceName, pageName, null, "save", null,
 
72  2 toggle new HashMap<String, String>() {{
73  2 put("content", versionTwo);
74    }});
75   
76    // Make sure it's version 2.
77  2 Assert.assertEquals("<p>" + versionTwo + "</p>", StoreTestUtils.getPageAsString(pageURL));
78   
79    // Do a rollback. v3.1
80  2 doPostAsAdmin(spaceName, pageName, null, "rollback", "rev=1.1&confirm=1", null);
81   
82    // Make sure it's the same as version 1.
83  2 Assert.assertEquals("<p>" + versionOne + "</p>", StoreTestUtils.getPageAsString(pageURL));
84   
85    // Make sure the latest current version is actually v3.1
86  2 HttpMethod ret =
87    doPostAsAdmin(spaceName, pageName, null, "preview", "xpage=plain",
 
88  2 toggle new HashMap<String, String>() {{
89  2 put("content", "{{velocity}}$doc.getVersion(){{/velocity}}");
90    }});
91  2 Assert.assertEquals("<p>3.1</p>", new String(ret.getResponseBody(), "UTF-8"));
92    }
93   
94    /**
95    * check that http://jira.xwiki.org/browse/XWIKI-7943 has not regressed.
96    * Jetty prevents saving of large documents unless you specify max form size on the command line.
97    *
98    * @since 4.1.1
99    * @since 4.0.1
100    */
 
101  2 toggle @Test
102    public void testSaveOfThreeHundredKilobyteDocument() throws Exception
103    {
104  2 final String content = RandomStringUtils.randomAlphanumeric(300000);
105  2 final HttpMethod ret =
106    this.doPostAsAdmin(this.spaceName, this.pageName, null, "save", null,
 
107  2 toggle new HashMap<String, String>() {{
108  2 put("content", content);
109    }});
110    // save forwards the user to view, if it's too big, jetty gives you a 500
111  2 Assert.assertEquals(302, ret.getStatusCode());
112    }
113   
 
114  2 toggle @Test
115    public void testDocumentIsSameAfterSaving() throws Exception
116    {
117  2 final String content =
118    "{{groovy}}\n"
119    + "def content = 'test content'\n"
120    + "doc.setContent(content);\n"
121    + "doc.saveAsAuthor();\n"
122    + "println(doc.getContent());\n"
123    + "{{/groovy}}";
124   
125    // Delete the document if it exists.
126  2 doPostAsAdmin(this.spaceName, this.pageName, null, "delete", "confirm=1", null);
127   
128    // Create a document.
129  2 doPostAsAdmin(this.spaceName, this.pageName, null, "save", null,
 
130  2 toggle new HashMap<String, String>(){{
131  2 put("content", content);
132    }});
133   
134  2 final String url =
135    this.getAddressPrefix() + "view/" + this.spaceName + "/" + this.pageName + "?xpage=plain";
136   
137  2 Assert.assertEquals("<p>test content</p>", StoreTestUtils.getPageAsString(url));
138    }
139   
 
140  2 toggle @Test
141    public void testOtherDocumentIsSameAfterSaving() throws Exception
142    {
143  2 final String content =
144    "{{groovy}}\n"
145    + "def content = 'test content'\n"
146    + "otherDoc = xwiki.getDocument('" + this.spaceName + "','" + this.pageName + "x')\n"
147    + "otherDoc.setContent(content);\n"
148    + "otherDoc.saveAsAuthor();\n"
149    + "println(otherDoc.getContent());\n"
150    + "{{/groovy}}";
151   
152    // Delete the document if it exists.
153  2 doPostAsAdmin(this.spaceName, this.pageName, null, "delete", "confirm=1", null);
154   
155    // Create a document.
156  2 doPostAsAdmin(this.spaceName, this.pageName, null, "save", null,
 
157  2 toggle new HashMap<String, String>(){{
158  2 put("content", content);
159    }});
160   
161  2 final String url =
162    this.getAddressPrefix() + "view/" + this.spaceName + "/" + this.pageName + "?xpage=plain";
163   
164  2 Assert.assertEquals("<p>test content</p>", StoreTestUtils.getPageAsString(url));
165    }
166    }