1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.test.cluster

File PanelsTest.java

 

Code metrics

4
33
1
1
103
57
3
0.09
33
1
3

Classes

Class Line # Actions
PanelsTest 40 33 0% 3 9
0.763157976.3%
 

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.test.cluster;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24    import org.openqa.selenium.By;
25    import org.xwiki.model.reference.LocalDocumentReference;
26    import org.xwiki.panels.internal.PanelClassDocumentInitializer;
27    import org.xwiki.rest.model.jaxb.Objects;
28    import org.xwiki.rest.model.jaxb.Page;
29    import org.xwiki.test.cluster.framework.AbstractClusterHttpTest;
30   
31    import static org.junit.Assert.assertEquals;
32    import static org.xwiki.test.ui.TestUtils.RestTestUtils.object;
33    import static org.xwiki.test.ui.TestUtils.RestTestUtils.property;
34   
35    /**
36    * Verify modifying a panel affect the other members of the cluster.
37    *
38    * @version $Id: a59b0235106e6bb8991a3af3d6bbbf9a4db74534 $
39    */
 
40    public class PanelsTest extends AbstractClusterHttpTest
41    {
42    private static LocalDocumentReference PANEL_REFERENCE = new LocalDocumentReference("Test", "SharedPanel");
43   
44    private static LocalDocumentReference HOME_REFERENCE = new LocalDocumentReference("Main", "WebHome");
45   
 
46  1 toggle @Test
47    public void testModifyPanel() throws Exception
48    {
49  1 String panelContent = "Hey I'm here !";
50  1 String modifiedPanelContent = "Hey I'm still here !";
51  1 String id = "testpanel";
52   
53    // Create panel on node 0
54  1 getUtil().switchExecutor(0);
55   
56  1 Page panelPage = getUtil().rest().page(PANEL_REFERENCE);
57  1 panelPage.setObjects(new Objects());
58  1 org.xwiki.rest.model.jaxb.Object panelObject = object(PanelClassDocumentInitializer.CLASS_REFERENCE_STRING);
59  1 panelObject.getProperties().add(property("content", "(%id='" + id + "'%)" + panelContent));
60  1 panelPage.getObjects().getObjectSummaries().add(panelObject);
61  1 getUtil().rest().save(panelPage);
62   
63    // Add the panel to wiki right panels
64  1 getUtil().setWikiPreference("rightPanels", "Test.SharedPanel");
65   
66  1 getUtil().gotoPage(HOME_REFERENCE);
67   
68  1 assertEquals(panelContent, getUtil().getDriver().findElement(By.id(id)).getText());
69   
70    // Display panel on node 1
71  1 getUtil().switchExecutor(1);
72   
73  1 getUtil().gotoPage(HOME_REFERENCE);
74  1 assertEquals(panelContent, getUtil().getDriver().findElement(By.id(id)).getText());
75   
76    // Modify panel on node 1
77  1 panelObject = getUtil().rest().object(PANEL_REFERENCE, PanelClassDocumentInitializer.CLASS_REFERENCE_STRING);
78  1 panelObject.getProperties().add(property("content", "(%id='" + id + "'%)" + modifiedPanelContent));
79  1 getUtil().rest().update(panelObject);
80   
81    // Reload the page after modifying the panel
82  1 getUtil().getDriver().navigate().refresh();
83  1 assertEquals(modifiedPanelContent, getUtil().getDriver().findElement(By.id(id)).getText());
84   
85    // Verify panel rendering on node 0
86    // Since it can take time for the Cluster to propagate the change, we need to wait and set up a timeout.
87  1 getUtil().switchExecutor(0);
88  1 getUtil().gotoPage(HOME_REFERENCE);
89  1 long t1 = System.currentTimeMillis();
90  1 long t2;
91  1 String result;
92  1 assertEquals(modifiedPanelContent, getUtil().getDriver().findElement(By.id(id)).getText());
93  ? while (!(result = getUtil().getDriver().findElement(By.id(id)).getText())
94    .equalsIgnoreCase(modifiedPanelContent)) {
95  0 t2 = System.currentTimeMillis();
96  0 if (t2 - t1 > 10000L) {
97  0 Assert.fail("Content should have been [" + modifiedPanelContent + "] but was [" + result + "]");
98    }
99  0 Thread.sleep(100);
100  0 getUtil().getDriver().navigate().refresh();
101    }
102    }
103    }