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

File WatchlistMacroTest.java

 

Code metrics

0
27
2
1
93
50
2
0.07
13.5
2
1

Classes

Class Line # Actions
WatchlistMacroTest 35 27 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.watchlist.test.ui;
21   
22    import org.apache.commons.lang.RandomStringUtils;
23    import org.junit.Assert;
24    import org.junit.Before;
25    import org.junit.Test;
26    import org.xwiki.test.ui.AbstractTest;
27    import org.xwiki.test.ui.po.ViewPage;
28    import org.xwiki.watchlist.test.po.WatchlistMacro;
29   
30    /**
31    * Tests Watchlist Macro features.
32    *
33    * @version $Id: e831264cfee43292ac46e4f89c2452f517653c42 $
34    */
 
35    public class WatchlistMacroTest extends AbstractTest
36    {
37    private WatchlistMacro watchlistMacro;
38    private String testSpace;
39    private String testPage;
40   
 
41  1 toggle @Before
42    public void setUp() {
43  1 String userName = RandomStringUtils.randomAlphanumeric(5);
44  1 getUtil().createUserAndLogin(userName, "password");
45   
46  1 this.watchlistMacro = new WatchlistMacro();
47  1 this.testSpace = userName + "Test";
48  1 this.testPage = "TestWatchlist";
49    }
50   
 
51  1 toggle @Test
52    public void testWatchAndRemoveEntries() {
53    // create a new page
54  1 ViewPage testPageView = getUtil().createPage(this.testSpace, this.testPage, "{{watchlist /}}", "Watch list");
55   
56    // check if new page is registered in the watchlist, but not its space
57  1 Assert.assertTrue("Newly created page is not watched",
58    this.watchlistMacro.isWatched(this.testSpace, this.testPage));
59  1 Assert.assertFalse("Newly created space is watched", this.watchlistMacro.isWatched(this.testSpace));
60  1 Assert.assertFalse("Complete wiki is watched", this.watchlistMacro.isWikiWatched());
61   
62  1 testPageView.watchSpace();
63  1 testPageView.watchWiki();
64   
65    // now need to reload the watchlist; doing so by going away from the page and then back
66  1 getUtil().gotoPage("Main", "WebHome");
67  1 testPageView = getUtil().gotoPage(this.testSpace, this.testPage);
68   
69  1 Assert.assertTrue("Newly created page is not watched",
70    this.watchlistMacro.isWatched(this.testSpace, this.testPage));
71  1 Assert.assertTrue("Test space is not watched", this.watchlistMacro.isWatched(this.testSpace));
72  1 Assert.assertTrue("Complete wiki is not watched", this.watchlistMacro.isWikiWatched());
73   
74  1 this.watchlistMacro.unWatch(null, null);
75  1 this.watchlistMacro.unWatch(this.testSpace, this.testPage);
76   
77    // change should have taken effect immediately, but instead reload page to avoid timing effects:
78  1 getUtil().gotoPage("Main", "WebHome");
79  1 testPageView = getUtil().gotoPage(this.testSpace, this.testPage);
80   
81  1 Assert.assertFalse("Newly created page is still watched",
82    this.watchlistMacro.isWatched(this.testSpace, this.testPage));
83  1 Assert.assertTrue("Test space is not watched", this.watchlistMacro.isWatched(this.testSpace));
84  1 Assert.assertFalse("Complete wiki is still watched", this.watchlistMacro.isWikiWatched());
85   
86  1 this.watchlistMacro.unWatch(this.testSpace, null);
87   
88    // next page reload .... see above
89  1 getUtil().gotoPage("Main", "WebHome");
90  1 testPageView = getUtil().gotoPage(this.testSpace, this.testPage);
91  1 Assert.assertFalse("Test space is still watched", this.watchlistMacro.isWatched(this.testSpace));
92    }
93    }