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

File AttachmentTest.java

 

Code metrics

0
38
4
1
153
88
4
0.11
9.5
4
1

Classes

Class Line # Actions
AttachmentTest 43 38 0% 4 16
0.6190476461.9%
 

Contributing tests

This file is covered by 2 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.ui;
21   
22    import org.apache.commons.lang.math.RandomUtils;
23    import org.junit.Assert;
24    import org.junit.Before;
25    import org.junit.Ignore;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.openqa.selenium.By;
29    import org.xwiki.test.ui.browser.IgnoreBrowser;
30    import org.xwiki.test.ui.browser.IgnoreBrowsers;
31    import org.xwiki.test.ui.po.AttachmentsPane;
32    import org.xwiki.test.ui.po.ViewPage;
33   
34    /**
35    * Test saving and downloading of attachments.
36    *
37    * A number of these tests paste code into the document and expect an output. This is wrong IMO but the way we have
38    * presently to test components which require the database to function.
39    *
40    * @version $Id: fb835ec75f6d3b5013c4c6fdb28f2ffdc0d7e04b $
41    * @since 2.5M1
42    */
 
43    public class AttachmentTest extends AbstractTest
44    {
45    @Rule
46    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
47   
48    private final String testAttachment = "SmallAttachment.txt";
49   
50    private final String testAttachment2 = "SmallAttachment2.txt";
51   
 
52  2 toggle @Before
53    public void setUp() throws Exception
54    {
55  2 getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
56    }
57   
 
58  0 toggle @Test
59    @Ignore("WebDriver doesn't support uploading multiple files in one input, see http://code.google.com/p/selenium/issues/detail?id=2239")
60    @IgnoreBrowsers({
61    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
62    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
63    })
64    public void testUploadDownloadTwoAttachmentsInParallel()
65    {
66  0 ViewPage vp = getUtil().createPage(getTestClassName(), getTestMethodName(), null,
67    getTestClassName() + "#" + getTestMethodName());
68   
69    // TODO: Remove when XWIKI-6688 (Possible race condition when clicking on a tab at the bottom of a page in
70    // view mode) is fixed.
71  0 vp.waitForDocExtraPaneActive("comments");
72   
73  0 AttachmentsPane ap = vp.openAttachmentsDocExtraPane();
74  0 ap.setFileToUpload(this.getClass().getResource("/" + this.testAttachment).getPath());
75  0 ap.addAnotherFile();
76  0 ap.setFileToUpload(this.getClass().getResource("/" + this.testAttachment2).getPath());
77  0 ap.clickAttachFiles();
78   
79  0 Assert.assertEquals("1.1", ap.getLatestVersionOfAttachment(this.testAttachment));
80  0 Assert.assertEquals("1.1", ap.getLatestVersionOfAttachment(this.testAttachment2));
81   
82    // Verify attachment contents
83   
84  0 ap.getAttachmentLink(this.testAttachment).click();
85   
86  0 Assert.assertEquals("This is a small attachment.", getDriver().findElement(By.tagName("html")).getText());
87  0 getDriver().navigate().back();
88  0 vp.waitForDocExtraPaneActive("attachments");
89  0 ap.getAttachmentLink(this.testAttachment2).click();
90  0 Assert.assertEquals("This is another small attachment.", getDriver().findElement(By.tagName("html")).getText());
91    }
92   
 
93  1 toggle @Test
94    @IgnoreBrowsers( {
95    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146"),
96    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See http://jira.xwiki.org/browse/XE-1177")})
97    public void testUploadDownloadTwoAttachmentsInSequence()
98    {
99  1 ViewPage vp = getUtil().createPage(getTestClassName(), getTestMethodName(), null,
100    getTestClassName() + "#" + getTestMethodName());
101   
102    // TODO: Remove when XWIKI-6688 (Possible race condition when clicking on a tab at the bottom of a page in
103    // view mode) is fixed.
104  1 vp.waitForDocExtraPaneActive("comments");
105   
106  1 AttachmentsPane ap = vp.openAttachmentsDocExtraPane();
107  1 ap.setFileToUpload(this.getClass().getResource("/" + this.testAttachment).getPath());
108  1 ap.waitForUploadToFinish(this.testAttachment);
109  1 ap.clickHideProgress();
110  1 ap.setFileToUpload(this.getClass().getResource("/" + this.testAttachment2).getPath());
111  1 ap.waitForUploadToFinish(this.testAttachment2);
112   
113  1 Assert.assertEquals("1.1", ap.getLatestVersionOfAttachment(this.testAttachment));
114  1 Assert.assertEquals("1.1", ap.getLatestVersionOfAttachment(this.testAttachment2));
115   
116    // Verify attachment contents
117   
118  1 ap.getAttachmentLink(this.testAttachment).click();
119   
120  1 Assert.assertEquals("This is a small attachment.", getDriver().findElement(By.tagName("html")).getText());
121  1 getDriver().navigate().back();
122  1 vp.waitForDocExtraPaneActive("attachments");
123  1 ap.getAttachmentLink(this.testAttachment2).click();
124  1 Assert.assertEquals("This is another small attachment.", getDriver().findElement(By.tagName("html")).getText());
125    }
126   
127    /**
128    * See XWIKI-5896: The image handling in the WYSIWYG-editor with GIF images is buggy.
129    */
 
130  1 toggle @Test
131    @IgnoreBrowsers({
132    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
133    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
134    })
135    public void testAttachAndViewGifImage()
136    {
137    // Prepare the page to display the GIF image. We explicitly set the width to a value greater than the actual
138    // image width because we want the code that resizes the image on the server side to be executed (even if the
139    // image is not actually resized).
140  1 ViewPage viewPage = getUtil().createPage(getClass().getSimpleName(), getTestMethodName(),
141    String.format("[[image:image.gif||width=%s]]", (20 + RandomUtils.nextInt(200))), getTestClassName());
142   
143    // TODO: Remove when XWIKI-6688 (Possible race condition when clicking on a tab at the bottom of a page in
144    // view mode) is fixed.
145  1 viewPage.waitForDocExtraPaneActive("comments");
146   
147    // Attach the GIF image.
148  1 AttachmentsPane attachmentsPane = viewPage.openAttachmentsDocExtraPane();
149  1 attachmentsPane.setFileToUpload(getClass().getResource("/image.gif").getPath());
150  1 attachmentsPane.waitForUploadToFinish("image.gif");
151  1 Assert.assertTrue(attachmentsPane.attachmentExistsByFileName("image.gif"));
152    }
153    }