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

File UpgradePlanJobTest.java

 

Code metrics

0
92
5
1
247
130
5
0.05
18.4
5
1

Classes

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