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

File UIExtensionTest.java

 

Code metrics

0
9
2
1
95
57
2
0.22
4.5
2
1

Classes

Class Line # Actions
UIExtensionTest 36 9 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.uiextension.test.ui;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.test.ui.AbstractTest;
27    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
28    import org.xwiki.test.ui.po.ViewPage;
29   
30    /**
31    * UI tests for the UI Extension feature.
32    *
33    * @version $Id: d1bd687e8caa67a40d80a36c5c135637de0b9f69 $
34    * @since 4.2M3
35    */
 
36    public class UIExtensionTest extends AbstractTest
37    {
38    private static final String HELLOWORLD_UIX_PAGE = "HelloWorld";
39   
40    private static final String HELLOWIKIWORLD_UIX_PAGE = "HelloWikiWorld";
41   
42    // Login as superadmin to have delete rights.
43    @Rule
44    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
45   
 
46  1 toggle @Before
47    public void setUp()
48    {
49    // Delete pages that we create in the test
50  1 getUtil().deletePage(getTestClassName(), HELLOWORLD_UIX_PAGE);
51  1 getUtil().deletePage(getTestClassName(), HELLOWIKIWORLD_UIX_PAGE);
52   
53  1 getUtil().gotoPage("Main", "WebHome");
54    }
55   
 
56  1 toggle @Test
57    public void testUIExtension()
58    {
59    // Test Java UI extensions
60  1 final ViewPage testPage = getUtil().createPage(getTestClassName(), HELLOWORLD_UIX_PAGE, "{{velocity}}\n"
61    + "\n"
62    + "{{html}}\n"
63    + "#foreach($uix in $services.uix.getExtensions('hello', {'sortByParameter' : 'HelloWorldKey'}))"
64    + "$services.rendering.render($uix.execute(), "
65    + "'xhtml/1.0')#end\n"
66    + "{{/html}}\n"
67    + "\n"
68    + "#foreach($uix in $services.uix.getExtensions('hello', {'sortByParameter' : 'HelloWorldKey'}))\n"
69    + "$uix.parameters\n"
70    + "#end\n"
71    + "{{/velocity}}\n", "Hello World");
72  1 Assert.assertEquals("HelloWorld\n"
73    + "{HelloWorldKey=HelloWorldValue}", testPage.getContent());
74   
75    // Test Wiki UI extension
76   
77  1 getUtil().addObject(getTestClassName(), HELLOWIKIWORLD_UIX_PAGE, "XWiki.UIExtensionClass",
78    "name", "helloWikiWorld2",
79    "extensionPointId", "hello",
80    "content", "HelloWikiWorld2",
81    "parameters", "HelloWorldKey=zz2_$xcontext.user");
82  1 getUtil().addObject(getTestClassName(), HELLOWIKIWORLD_UIX_PAGE, "XWiki.UIExtensionClass",
83    "name", "helloWikiWorld1",
84    "extensionPointId", "hello",
85    "content", "HelloWikiWorld1",
86    "parameters", "HelloWorldKey=zz1_$xcontext.user");
87  1 getUtil().gotoPage(getTestClassName(), HELLOWORLD_UIX_PAGE);
88  1 Assert.assertEquals("HelloWorld\n"
89    + "HelloWikiWorld1\n"
90    + "HelloWikiWorld2\n"
91    + "{HelloWorldKey=HelloWorldValue}\n"
92    + "{HelloWorldKey=zz1_XWiki.superadmin}\n"
93    + "{HelloWorldKey=zz2_XWiki.superadmin}", testPage.getContent());
94    }
95    }