1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension.xar.internal.job

File RepairXarJobTest.java

 

Code metrics

0
21
6
1
108
65
6
0.29
3.5
6
1

Classes

Class Line # Actions
RepairXarJobTest 38 21 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 3 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.extension.xar.internal.job;
21   
22    import org.junit.Before;
23    import org.junit.Test;
24    import org.xwiki.extension.ExtensionId;
25    import org.xwiki.extension.InstalledExtension;
26    import org.xwiki.extension.repository.InstalledExtensionRepository;
27    import org.xwiki.extension.test.AbstractExtensionHandlerTest;
28    import org.xwiki.extension.xar.internal.handler.XarExtensionHandler;
29    import org.xwiki.job.Job;
30    import org.xwiki.logging.LogLevel;
31    import org.xwiki.security.authorization.ContextualAuthorizationManager;
32    import org.xwiki.test.annotation.AfterComponent;
33    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
34   
35    import static org.junit.Assert.assertFalse;
36    import static org.junit.Assert.assertTrue;
37   
 
38    public class RepairXarJobTest extends AbstractExtensionHandlerTest
39    {
40    private InstalledExtensionRepository xarExtensionRepository;
41   
 
42  3 toggle @AfterComponent
43    public void afterComponent() throws Exception
44    {
45  3 this.repositoryUtil.getComponentManager().registerMockComponent(WikiDescriptorManager.class);
46    }
47   
 
48  3 toggle @Override
49    @Before
50    public void setUp() throws Exception
51    {
52  3 super.setUp();
53   
54  3 this.mocker.registerMockComponent(ContextualAuthorizationManager.class);
55   
56  3 this.xarExtensionRepository =
57    this.mocker.getInstance(InstalledExtensionRepository.class, XarExtensionHandler.TYPE);
58    }
59   
 
60  3 toggle protected Job repair(ExtensionId extensionId, String[] namespaces, LogLevel failFrom) throws Throwable
61    {
62  3 return install(RepairXarJob.JOBTYPE, extensionId, namespaces, failFrom);
63    }
64   
 
65  1 toggle @Test
66    public void testRepairOnRoot() throws Throwable
67    {
68  1 ExtensionId extensionId = new ExtensionId("test", "1.0");
69   
70  1 repair(extensionId, null, LogLevel.WARN);
71   
72  1 InstalledExtension installedExtension = this.xarExtensionRepository.resolve(extensionId);
73   
74  1 assertTrue(installedExtension.isValid(null));
75   
76  1 installedExtension = this.xarExtensionRepository.resolve(new ExtensionId("dependency", "1.0"));
77   
78  1 assertTrue(installedExtension.isValid(null));
79    }
80   
 
81  1 toggle @Test
82    public void testRepairOnWiki() throws Throwable
83    {
84  1 ExtensionId extensionId = new ExtensionId("test", "1.0");
85   
86  1 repair(extensionId, new String[] { "wiki:wiki1" }, LogLevel.WARN);
87   
88  1 InstalledExtension installedExtension = this.xarExtensionRepository.resolve(extensionId);
89   
90  1 assertTrue(installedExtension.isValid(null));
91   
92  1 installedExtension = this.xarExtensionRepository.resolve(new ExtensionId("dependency", "1.0"));
93   
94  1 assertTrue(installedExtension.isValid(null));
95    }
96   
 
97  1 toggle @Test
98    public void testRepairInvalidOnRoot() throws Throwable
99    {
100  1 ExtensionId extensionId = new ExtensionId("invalid", "1.0");
101   
102  1 repair(extensionId, null, LogLevel.ERROR);
103   
104  1 InstalledExtension installedExtension = this.xarExtensionRepository.resolve(extensionId);
105   
106  1 assertFalse(installedExtension.isValid(null));
107    }
108    }