| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (97) |
Complexity: 5 |
Complexity Density: 0.05 |
|
| 35 |
|
public class UpgradePlanJobTest extends AbstractExtensionHandlerTest |
| 36 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
| 37 |
1 |
@Test... |
| 38 |
|
public void testUpgradePlanOnRoot() throws Throwable |
| 39 |
|
{ |
| 40 |
|
|
| 41 |
1 |
install(TestResources.REMOTE_UPGRADE10_ID); |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
1 |
ExtensionPlan plan = upgradePlan(); |
| 46 |
|
|
| 47 |
|
|
| 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 |
|
|
| 78 |
|
|
| 79 |
1 |
Assert.assertEquals(3, plan.getActions().size()); |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 92 |
1 |
@Test... |
| 93 |
|
public void testUpgradePlanOnNamespaceWithExtensionOnRoot() throws Throwable |
| 94 |
|
{ |
| 95 |
|
|
| 96 |
1 |
install(TestResources.REMOTE_UPGRADE10_ID); |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
1 |
ExtensionPlan plan = upgradePlan("namespace"); |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
1 |
Assert.assertEquals(0, plan.getTree().size()); |
| 105 |
|
} |
| 106 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 107 |
1 |
@Test... |
| 108 |
|
public void testUpgradePlanWithDependencyOnRoot() throws Throwable |
| 109 |
|
{ |
| 110 |
|
|
| 111 |
1 |
install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID); |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
1 |
ExtensionPlan plan = upgradePlan(); |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
1 |
Assert.assertEquals(2, plan.getTree().size()); |
| 121 |
|
|
| 122 |
|
|
| 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 |
|
|
| 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 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
1 |
Assert.assertEquals(4, plan.getActions().size()); |
| 163 |
|
} |
| 164 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 165 |
1 |
@Test... |
| 166 |
|
public void testUpgradePlanWithDependencyOnNamespace() throws Throwable |
| 167 |
|
{ |
| 168 |
|
|
| 169 |
1 |
install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID, "namespace"); |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
1 |
ExtensionPlan plan = upgradePlan("namespace"); |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
1 |
Assert.assertEquals(1, plan.getTree().size()); |
| 179 |
|
|
| 180 |
1 |
Iterator<ExtensionPlanNode> iterator = plan.getTree().iterator(); |
| 181 |
|
|
| 182 |
|
|
| 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 |
|
|
| 202 |
1 |
Assert.assertFalse(iterator.hasNext()); |
| 203 |
|
|
| 204 |
|
|
| 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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 215 |
1 |
@Test... |
| 216 |
|
public void testUpgradePlanOnRootWithTargetDependencyExtension() throws Throwable |
| 217 |
|
{ |
| 218 |
|
|
| 219 |
1 |
install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID); |
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
1 |
InstallRequest installRequest = new InstallRequest(); |
| 224 |
1 |
installRequest.addExtension(TestResources.REMOTE_UPGRADE10_ID); |
| 225 |
1 |
ExtensionPlan plan = upgradePlan(installRequest); |
| 226 |
|
|
| 227 |
|
|
| 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 |
|
|
| 242 |
|
|
| 243 |
1 |
Assert.assertEquals(1, plan.getActions().size()); |
| 244 |
|
|
| 245 |
1 |
Assert.assertSame(action, plan.getActions().iterator().next()); |
| 246 |
|
} |
| 247 |
|
} |