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

File DefaultWebDAVTest.java

 

Code metrics

0
137
6
1
235
176
6
0.04
22.83
6
1

Classes

Class Line # Actions
DefaultWebDAVTest 40 137 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 6 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.webdav.test;
21   
22    import java.io.ByteArrayInputStream;
23   
24    import org.apache.commons.httpclient.methods.GetMethod;
25    import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
26    import org.apache.commons.httpclient.methods.PutMethod;
27    import org.apache.jackrabbit.webdav.DavServletResponse;
28    import org.apache.webdav.lib.methods.DeleteMethod;
29    import org.apache.webdav.lib.methods.MkcolMethod;
30    import org.apache.webdav.lib.methods.MoveMethod;
31    import org.junit.Test;
32   
33    import static org.junit.Assert.*;
34   
35    /**
36    * The integration test suite for webdav.
37    *
38    * @version $Id: 818bb3dbb8c720787eb3170197e2e1966a00bab8 $
39    */
 
40    public class DefaultWebDAVTest extends AbstractWebDAVTest
41    {
42    /**
43    * Test create and delete space.
44    */
 
45  1 toggle @Test
46    public void testCreateAndDeleteSpace() throws Exception
47    {
48  1 String spaceUrl = SPACES + "/TestSpace";
49  1 DeleteMethod deleteMethod = new DeleteMethod();
50  1 deleteMethod.setDoAuthentication(true);
51  1 MkcolMethod mkColMethod = new MkcolMethod();
52  1 mkColMethod.setDoAuthentication(true);
53   
54  1 deleteMethod.setPath(spaceUrl);
55  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
56  1 mkColMethod.setPath(spaceUrl);
57  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
58  1 deleteMethod.setPath(spaceUrl);
59  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
60    }
61   
62    /**
63    * Test rename space.
64    */
 
65  1 toggle @Test
66    public void testRenameSpace() throws Exception
67    {
68  1 String spaceUrl = SPACES + "/TestSpace";
69  1 String relativeDestinationPath = "/xwiki/webdav/spaces/RenamedTestSpace";
70  1 String movedSpaceUrl = SPACES + "/RenamedTestSpace";
71  1 DeleteMethod deleteMethod = new DeleteMethod();
72  1 deleteMethod.setDoAuthentication(true);
73  1 MkcolMethod mkColMethod = new MkcolMethod();
74  1 mkColMethod.setDoAuthentication(true);
75  1 MoveMethod moveMethod = new MoveMethod();
76  1 moveMethod.setDoAuthentication(true);
77   
78  1 deleteMethod.setPath(spaceUrl);
79  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
80  1 deleteMethod.setPath(movedSpaceUrl);
81  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
82  1 mkColMethod.setPath(spaceUrl);
83  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
84  1 moveMethod.setPath(spaceUrl);
85  1 moveMethod.setDestination(relativeDestinationPath);
86  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(moveMethod));
87  1 deleteMethod.setPath(movedSpaceUrl);
88  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
89    }
90   
91    /**
92    * Test create and delete page.
93    */
 
94  1 toggle @Test
95    public void testCreateAndDeletePage() throws Exception
96    {
97  1 String spaceUrl = SPACES + "/TestSpace";
98  1 String pageUrl = spaceUrl + "/TestPage";
99  1 DeleteMethod deleteMethod = new DeleteMethod();
100  1 deleteMethod.setDoAuthentication(true);
101  1 MkcolMethod mkColMethod = new MkcolMethod();
102  1 mkColMethod.setDoAuthentication(true);
103   
104  1 deleteMethod.setPath(spaceUrl);
105  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
106  1 mkColMethod.setPath(spaceUrl);
107  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
108  1 mkColMethod.setPath(pageUrl);
109  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
110  1 deleteMethod.setPath(pageUrl);
111  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
112  1 deleteMethod.setPath(spaceUrl);
113  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
114    }
115   
116    /**
117    * Test get page content.
118    */
 
119  1 toggle @Test
120    public void testGetPageWikiContent() throws Exception
121    {
122  1 String spaceUrl = SPACES + "/TestSpace";
123  1 String pageUrl = spaceUrl + "/TestPage";
124  1 String wikiTextFileUrl = pageUrl + "/wiki.txt";
125  1 String wikiXMLFileUrl = pageUrl + "/wiki.xml";
126  1 DeleteMethod deleteMethod = new DeleteMethod();
127  1 deleteMethod.setDoAuthentication(true);
128  1 MkcolMethod mkColMethod = new MkcolMethod();
129  1 mkColMethod.setDoAuthentication(true);
130  1 GetMethod getMethod = new GetMethod();
131  1 getMethod.setDoAuthentication(true);
132   
133  1 deleteMethod.setPath(spaceUrl);
134  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
135  1 mkColMethod.setPath(spaceUrl);
136  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
137  1 mkColMethod.setPath(pageUrl);
138  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
139  1 getMethod.setPath(wikiTextFileUrl);
140  1 assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod));
141  1 assertTrue(getMethod.getResponseBodyAsStream().read() != -1);
142  1 getMethod.setPath(wikiXMLFileUrl);
143  1 assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod));
144  1 assertTrue(getMethod.getResponseBodyAsStream().read() != -1);
145  1 deleteMethod.setPath(pageUrl);
146  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
147  1 deleteMethod.setPath(spaceUrl);
148  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
149    }
150   
151    /**
152    * Test update page content.
153    */
 
154  1 toggle @Test
155    public void testUpdatePageWikiContent() throws Exception
156    {
157  1 String spaceUrl = SPACES + "/TestSpace";
158  1 String pageUrl = spaceUrl + "/TestPage";
159  1 String wikiTextFileUrl = pageUrl + "/wiki.txt";
160  1 String wikiXMLFileUrl = pageUrl + "/wiki.xml";
161  1 String newContent = "New Content";
162  1 DeleteMethod deleteMethod = new DeleteMethod();
163  1 deleteMethod.setDoAuthentication(true);
164  1 MkcolMethod mkColMethod = new MkcolMethod();
165  1 mkColMethod.setDoAuthentication(true);
166  1 PutMethod putMethod = new PutMethod();
167  1 putMethod.setDoAuthentication(true);
168  1 GetMethod getMethod = new GetMethod();
169  1 getMethod.setDoAuthentication(true);
170   
171  1 deleteMethod.setPath(spaceUrl);
172  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
173  1 mkColMethod.setPath(spaceUrl);
174  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
175  1 mkColMethod.setPath(pageUrl);
176  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
177  1 putMethod.setPath(wikiTextFileUrl);
178  1 putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(newContent.getBytes())));
179    // Already existing resource, in which case SC_NO_CONTENT will be the return status.
180  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(putMethod));
181  1 getMethod.setPath(wikiTextFileUrl);
182  1 assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod));
183  1 assertEquals(newContent, getMethod.getResponseBodyAsString());
184  1 putMethod.setPath(wikiXMLFileUrl);
185  1 putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(newContent.getBytes())));
186    // XML saving was disabled recently. See http://jira.xwiki.org/jira/browse/XWIKI-2910
187  1 assertEquals(DavServletResponse.SC_METHOD_NOT_ALLOWED, getHttpClient().executeMethod(putMethod));
188  1 deleteMethod.setPath(pageUrl);
189  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
190  1 deleteMethod.setPath(spaceUrl);
191  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
192    }
193   
194    /**
195    * Test making attachment.
196    */
 
197  1 toggle @Test
198    public void testMakingAttachment() throws Exception
199    {
200  1 String spaceUrl = SPACES + "/TestSpace";
201  1 String pageUrl = spaceUrl + "/TestPage";
202  1 String attachmentUrl = pageUrl + "/attachment.txt";
203  1 String attachmentContent = "Attachment Content";
204  1 DeleteMethod deleteMethod = new DeleteMethod();
205  1 deleteMethod.setDoAuthentication(true);
206  1 MkcolMethod mkColMethod = new MkcolMethod();
207  1 mkColMethod.setDoAuthentication(true);
208  1 PutMethod putMethod = new PutMethod();
209  1 putMethod.setDoAuthentication(true);
210  1 GetMethod getMethod = new GetMethod();
211  1 getMethod.setDoAuthentication(true);
212   
213  1 deleteMethod.setPath(spaceUrl);
214  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
215  1 mkColMethod.setPath(spaceUrl);
216  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
217  1 mkColMethod.setPath(pageUrl);
218  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
219  1 getMethod.setPath(attachmentUrl);
220  1 assertEquals(DavServletResponse.SC_NOT_FOUND, getHttpClient().executeMethod(getMethod));
221  1 putMethod.setPath(attachmentUrl);
222  1 putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(attachmentContent
223    .getBytes())));
224  1 assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(putMethod));
225  1 getMethod.setPath(attachmentUrl);
226  1 assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod));
227  1 assertEquals(attachmentContent, getMethod.getResponseBodyAsString());
228  1 deleteMethod.setPath(attachmentUrl);
229  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
230  1 deleteMethod.setPath(pageUrl);
231  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
232  1 deleteMethod.setPath(spaceUrl);
233  1 assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
234    }
235    }