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

File UninstallJobTest.java

 

Code metrics

0
46
7
1
166
102
8
0.17
6.57
7
1.14

Classes

Class Line # Actions
UninstallJobTest 32 46 0% 8 1
0.981132198.1%
 

Contributing tests

This file is covered by 6 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.job.internal;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24    import org.xwiki.extension.TestResources;
25    import org.xwiki.extension.UninstallException;
26    import org.xwiki.extension.handler.ExtensionHandler;
27    import org.xwiki.extension.test.AbstractExtensionHandlerTest;
28    import org.xwiki.extension.test.TestExtensionHandler;
29   
30    import static org.junit.Assert.fail;
31   
 
32    public class UninstallJobTest extends AbstractExtensionHandlerTest
33    {
34    private TestResources resources;
35   
36    private TestExtensionHandler handler;
37   
 
38  6 toggle @Override
39    public void setUp() throws Exception
40    {
41  6 super.setUp();
42   
43    // lookup
44   
45  6 this.handler = (TestExtensionHandler) this.mocker.getInstance(ExtensionHandler.class, "test");
46   
47    // resources
48   
49  6 this.resources = new TestResources();
50  6 this.resources.init(this.installedExtensionRepository);
51    }
52   
 
53  1 toggle @Test
54    public void testUninstall() throws Throwable
55    {
56  1 uninstall(TestResources.INSTALLED_ID, null);
57   
58  1 Assert.assertFalse(this.handler.getExtensions().get(null).contains(this.resources.installed));
59  1 Assert.assertNull(
60    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), null));
61   
62  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(this.resources.installedDependency));
63  1 Assert.assertNotNull(this.installedExtensionRepository
64    .getInstalledExtension(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
65    }
66   
 
67  1 toggle @Test
68    public void testUninstallWithBackwarDepencency() throws Throwable
69    {
70  1 uninstall(TestResources.INSTALLED_DEPENDENCY_ID, null);
71   
72  1 Assert.assertFalse(this.handler.getExtensions().get(null).contains(this.resources.installed));
73  1 Assert.assertNull(
74    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), null));
75   
76  1 Assert.assertFalse(this.handler.getExtensions().get(null).contains(this.resources.installedDependency));
77  1 Assert.assertNull(this.installedExtensionRepository
78    .getInstalledExtension(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
79    }
80   
 
81  1 toggle @Test
82    public void testUninstallTwice() throws Throwable
83    {
84  1 uninstall(TestResources.INSTALLED_ID, null);
85   
86  1 try {
87  1 uninstall(TestResources.INSTALLED_ID, null);
88   
89  0 fail("Should have failed to uninstall the extension twice");
90    } catch (UninstallException expected) {
91    // expected
92    }
93    }
94   
 
95  1 toggle @Test
96    public void testUninstallFromNamespace() throws Throwable
97    {
98    // prepare
99   
100  1 uninstall(TestResources.INSTALLED_DEPENDENCY_ID, null);
101  1 install(TestResources.INSTALLED_ID, "namespace1");
102  1 install(TestResources.INSTALLED_ID, "namespace2");
103   
104    // actual test
105   
106  1 uninstall(TestResources.INSTALLED_ID, "namespace1");
107   
108  1 Assert.assertFalse(this.handler.getExtensions().get("namespace1").contains(this.resources.installed));
109  1 Assert.assertNull(
110    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace1"));
111   
112  1 Assert.assertTrue(this.handler.getExtensions().get("namespace2").contains(this.resources.installed));
113  1 Assert.assertNotNull(
114    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace2"));
115    }
116   
 
117  1 toggle @Test
118    public void testUninstallFromNamespaceWithBackwarDepencency() throws Throwable
119    {
120    // prepare
121   
122  1 uninstall(TestResources.INSTALLED_DEPENDENCY_ID, null);
123  1 install(TestResources.INSTALLED_ID, "namespace1");
124  1 install(TestResources.INSTALLED_ID, "namespace2");
125   
126    // actual test
127   
128  1 uninstall(TestResources.INSTALLED_DEPENDENCY_ID, "namespace1");
129   
130  1 Assert.assertFalse(this.handler.getExtensions().get("namespace1").contains(this.resources.installed));
131  1 Assert.assertNull(
132    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace1"));
133  1 Assert.assertFalse(this.handler.getExtensions().get("namespace1").contains(this.resources.installedDependency));
134  1 Assert.assertNull(this.installedExtensionRepository
135    .getInstalledExtension(TestResources.INSTALLED_DEPENDENCY_ID.getId(), "namespace1"));
136   
137  1 Assert.assertTrue(this.handler.getExtensions().get("namespace2").contains(this.resources.installed));
138  1 Assert.assertNotNull(
139    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace2"));
140  1 Assert.assertTrue(this.handler.getExtensions().get("namespace2").contains(this.resources.installed));
141  1 Assert.assertNotNull(
142    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace2"));
143    }
144   
 
145  1 toggle @Test
146    public void testUninstallFromAllNamespaces() throws Throwable
147    {
148    // prepare
149   
150  1 uninstall(TestResources.INSTALLED_DEPENDENCY_ID, null);
151  1 install(TestResources.INSTALLED_ID, "namespace1");
152  1 install(TestResources.INSTALLED_ID, "namespace2");
153   
154    // actual test
155   
156  1 uninstall(TestResources.INSTALLED_ID, null);
157   
158  1 Assert.assertFalse(this.handler.getExtensions().get("namespace1").contains(this.resources.installed));
159  1 Assert.assertNull(
160    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace1"));
161   
162  1 Assert.assertFalse(this.handler.getExtensions().get("namespace2").contains(this.resources.installed));
163  1 Assert.assertNull(
164    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace2"));
165    }
166    }