1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.job.internal

File UninstallJobTest.java

 

Code metrics

0
45
7
1
162
100
8
0.18
6.43
7
1.14

Classes

Class Line # Actions
UninstallJobTest 30 45 0% 8 0
1.0100%
 

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