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

File WebJarsTest.java

 

Code metrics

0
7
1
1
76
31
1
0.14
7
1
1

Classes

Class Line # Actions
WebJarsTest 38 7 0% 1 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.webjars.test.ui;
21   
22    import org.junit.Rule;
23    import org.junit.Test;
24    import org.openqa.selenium.By;
25    import org.openqa.selenium.WebElement;
26    import org.xwiki.test.ui.AbstractTest;
27    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
28    import org.xwiki.test.ui.po.ViewPage;
29   
30    import static org.junit.Assert.*;
31   
32    /**
33    * Functional tests for the WebJars integration.
34    *
35    * @version $Id: a88b89848ab774dfd7ed0e2022a358e3fa692be3 $
36    * @since 7.4M2
37    */
 
38    public class WebJarsTest extends AbstractTest
39    {
40    @Rule
41    public SuperAdminAuthenticationRule superAdminAuthenticationRule = new SuperAdminAuthenticationRule(getUtil());
42   
 
43  1 toggle @Test
44    public void testWebJars() throws Exception
45    {
46    // Delete pages that we create in the test
47  1 getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
48   
49    // Create a page in which:
50    // - we install a webjar in the main wiki
51    // - we use the WebJars Script Service to generate a URL for a resource inside that webjar
52    // - we create a link to that resource
53    // Then we click that link and verify we get the resource content.
54    //
55    // This test validates both the ability to generate webjars URL, the serving of webjars through the webjars URL
56    // and the ability to access a webjars installed in a specific wiki.
57  1 String content = "{{velocity}}\n"
58    + "#set ($job = $services.extension.install('org.webjars:AjaxQ', '0.0.2', 'wiki:mywiki'))\n"
59    + "#set ($discard = $job.join())\n"
60    + "installed: $services.extension.installed.getInstalledExtension('org.webjars:AjaxQ', 'wiki:mywiki').id\n"
61    + "[[AjaxQ>>path:$services.webjars.url('org.webjars:AjaxQ', 'ajaxq.js', {'wiki' : 'mywiki'})]]\n"
62    + "{{/velocity}}";
63  1 ViewPage vp = getUtil().createPage(getTestClassName(), getTestMethodName(), content, "WebJars Test");
64   
65  1 assertTrue(vp.getContent().contains("installed: org.webjars:AjaxQ-0.0.2"));
66   
67    // Click the link!
68    // Note: For understanding why there's a r=1 query string, see WebJarsScriptService#getResourceReference()
69  1 WebElement link = getDriver().findElementWithoutWaiting(
70    By.xpath("//a[@href = '/xwiki/webjars/wiki%3Amywiki/AjaxQ/0.0.2/ajaxq.js?r=1']"));
71  1 link.click();
72   
73    // Verify that the served resource is the one from the webjars
74  1 assertTrue(getDriver().getPageSource().contains("// AjaxQ jQuery Plugin"));
75    }
76    }