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

File UpgradePlanJobTest.java

 

Code metrics

0
93
5
1
251
133
5
0.05
18.6
5
1

Classes

Class Line # Actions
UpgradePlanJobTest 37 93 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 5 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 java.util.Arrays;
23    import java.util.Iterator;
24   
25    import org.junit.Assert;
26    import org.junit.Test;
27    import org.xwiki.extension.InstalledExtension;
28    import org.xwiki.extension.TestResources;
29    import org.xwiki.extension.job.InstallRequest;
30    import org.xwiki.extension.job.plan.ExtensionPlan;
31    import org.xwiki.extension.job.plan.ExtensionPlanAction;
32    import org.xwiki.extension.job.plan.ExtensionPlanAction.Action;
33    import org.xwiki.extension.job.plan.ExtensionPlanNode;
34    import org.xwiki.extension.repository.internal.installed.DefaultInstalledExtension;
35    import org.xwiki.extension.test.AbstractExtensionHandlerTest;
36   
 
37    public class UpgradePlanJobTest extends AbstractExtensionHandlerTest
38    {
 
39  1 toggle @Test
40    public void testUpgradePlanOnRoot() throws Throwable
41    {
42    // Install first version
43  1 InstalledExtension extension = (DefaultInstalledExtension) install(TestResources.REMOTE_UPGRADE10_ID);
44    // Tag it as dependency
45  1 this.installedExtensionRepository.installExtension(extension, null, true);
46   
47    // check upgrade
48   
49  1 ExtensionPlan plan = upgradePlan();
50   
51    // Tree
52   
53  1 Assert.assertEquals(2, plan.getTree().size());
54   
55  1 ExtensionPlanNode node = getNode(TestResources.REMOTE_UPGRADE20_ID, plan.getTree());
56  1 ExtensionPlanAction action = node.getAction();
57   
58  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
59  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
60  1 Assert.assertNull(action.getNamespace());
61  1 Assert.assertEquals(0, node.getChildren().size());
62   
63  1 node = getNode(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID, plan.getTree());
64  1 action = node.getAction();
65   
66  1 Assert.assertEquals(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID, action.getExtension().getId());
67  1 Assert.assertEquals(Action.REPAIR, action.getAction());
68  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
69  1 Assert.assertNull(action.getNamespace());
70  1 Assert.assertEquals(1, node.getChildren().size());
71   
72  1 node = node.getChildren().iterator().next();
73  1 action = node.getAction();
74   
75  1 Assert.assertEquals(TestResources.REMOTE_MISSINGDEPENDENCY_ID, action.getExtension().getId());
76  1 Assert.assertEquals(Action.INSTALL, action.getAction());
77  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
78  1 Assert.assertNull(action.getNamespace());
79  1 Assert.assertEquals(0, node.getChildren().size());
80   
81    // Actions
82   
83  1 Assert.assertEquals(3, plan.getActions().size());
84   
85    // //////////////////////
86    // Exclude extension
87   
88  1 Assert.assertEquals(0,
89    upgradePlan(null,
90    Arrays.asList(TestResources.REMOTE_UPGRADE10_ID, TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID))
91    .getTree().size());
92  1 Assert.assertEquals(1, upgradePlan(null, Arrays.asList(TestResources.REMOTE_UPGRADE10_ID)).getTree().size());
93  1 Assert.assertEquals(2, upgradePlan(null, Arrays.asList(TestResources.REMOTE_UPGRADE20_ID)).getTree().size());
94    }
95   
 
96  1 toggle @Test
97    public void testUpgradePlanOnNamespaceWithExtensionOnRoot() throws Throwable
98    {
99    // install first version
100  1 install(TestResources.REMOTE_UPGRADE10_ID);
101   
102    // check upgrade
103   
104  1 ExtensionPlan plan = upgradePlan("namespace");
105   
106    // Tree
107   
108  1 Assert.assertEquals(0, plan.getTree().size());
109    }
110   
 
111  1 toggle @Test
112    public void testUpgradePlanWithDependencyOnRoot() throws Throwable
113    {
114    // install first version
115  1 install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID);
116   
117    // check upgrade
118   
119  1 ExtensionPlan plan = upgradePlan();
120   
121    // Tree
122    // ////////
123   
124  1 Assert.assertEquals(2, plan.getTree().size());
125   
126    // First node
127  1 ExtensionPlanNode node = getNode(TestResources.REMOTE_UPGRADEWITHDEPENDENCY20_ID, plan.getTree());
128  1 ExtensionPlanAction action = node.getAction();
129   
130  1 Assert.assertEquals(TestResources.REMOTE_UPGRADEWITHDEPENDENCY20_ID, action.getExtension().getId());
131  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
132  1 Assert.assertNull(action.getNamespace());
133   
134  1 Assert.assertEquals(1, node.getChildren().size());
135   
136  1 ExtensionPlanNode childNode = node.getChildren().iterator().next();
137   
138  1 ExtensionPlanAction childAction = childNode.getAction();
139   
140  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, childAction.getExtension().getId());
141  1 Assert.assertEquals(Action.UPGRADE, childAction.getAction());
142  1 Assert.assertNull(childAction.getNamespace());
143   
144    // Second node
145  1 node = getNode(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID, plan.getTree());
146  1 action = node.getAction();
147   
148  1 Assert.assertEquals(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID, action.getExtension().getId());
149  1 Assert.assertEquals(Action.REPAIR, action.getAction());
150  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
151  1 Assert.assertNull(action.getNamespace());
152  1 Assert.assertEquals(1, node.getChildren().size());
153   
154  1 node = node.getChildren().iterator().next();
155  1 action = node.getAction();
156   
157  1 Assert.assertEquals(TestResources.REMOTE_MISSINGDEPENDENCY_ID, action.getExtension().getId());
158  1 Assert.assertEquals(Action.INSTALL, action.getAction());
159  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
160  1 Assert.assertNull(action.getNamespace());
161  1 Assert.assertEquals(0, node.getChildren().size());
162   
163    // Actions
164    // ////////
165   
166  1 Assert.assertEquals(4, plan.getActions().size());
167    }
168   
 
169  1 toggle @Test
170    public void testUpgradePlanWithDependencyOnNamespace() throws Throwable
171    {
172    // install first version
173  1 install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID, "namespace");
174   
175    // check upgrade
176   
177  1 ExtensionPlan plan = upgradePlan("namespace");
178   
179    // Tree
180    // ////////
181   
182  1 Assert.assertEquals(1, plan.getTree().size());
183   
184  1 Iterator<ExtensionPlanNode> iterator = plan.getTree().iterator();
185   
186    // First node
187  1 ExtensionPlanNode node = iterator.next();
188   
189  1 ExtensionPlanAction action = node.getAction();
190   
191  1 Assert.assertEquals(TestResources.REMOTE_UPGRADEWITHDEPENDENCY20_ID, action.getExtension().getId());
192  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
193  1 Assert.assertEquals("namespace", action.getNamespace());
194   
195  1 Assert.assertEquals(1, node.getChildren().size());
196   
197  1 ExtensionPlanNode childNode = node.getChildren().iterator().next();
198   
199  1 ExtensionPlanAction childAction = childNode.getAction();
200   
201  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, childAction.getExtension().getId());
202  1 Assert.assertEquals(Action.UPGRADE, childAction.getAction());
203  1 Assert.assertEquals("namespace", childAction.getNamespace());
204   
205    // Second node
206  1 Assert.assertFalse(iterator.hasNext());
207   
208    // Actions
209    // ////////
210   
211  1 Assert.assertEquals(2, plan.getActions().size());
212   
213  1 Iterator<ExtensionPlanAction> actionIterator = plan.getActions().iterator();
214   
215  1 Assert.assertSame(childAction, actionIterator.next());
216  1 Assert.assertSame(action, actionIterator.next());
217    }
218   
 
219  1 toggle @Test
220    public void testUpgradePlanOnRootWithTargetDependencyExtension() throws Throwable
221    {
222    // install first version
223  1 install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID);
224   
225    // check upgrade
226   
227  1 InstallRequest installRequest = new InstallRequest();
228  1 installRequest.addExtension(TestResources.REMOTE_UPGRADE10_ID);
229  1 ExtensionPlan plan = upgradePlan(installRequest);
230   
231    // Tree
232   
233  1 Assert.assertEquals(1, plan.getTree().size());
234   
235  1 ExtensionPlanNode node = plan.getTree().iterator().next();
236   
237  1 ExtensionPlanAction action = node.getAction();
238   
239  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
240  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
241  1 Assert.assertNull(action.getNamespace());
242   
243  1 Assert.assertEquals(0, node.getChildren().size());
244   
245    // Actions
246   
247  1 Assert.assertEquals(1, plan.getActions().size());
248   
249  1 Assert.assertSame(action, plan.getActions().iterator().next());
250    }
251    }