| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.store.migration; |
| 21 |
|
|
| 22 |
|
import java.util.ArrayList; |
| 23 |
|
import java.util.Arrays; |
| 24 |
|
import java.util.Collection; |
| 25 |
|
import java.util.List; |
| 26 |
|
|
| 27 |
|
import javax.inject.Named; |
| 28 |
|
import javax.inject.Singleton; |
| 29 |
|
|
| 30 |
|
import org.xwiki.component.annotation.Component; |
| 31 |
|
import org.xwiki.component.annotation.ComponentAnnotationLoader; |
| 32 |
|
import org.xwiki.component.descriptor.ComponentDescriptor; |
| 33 |
|
|
| 34 |
|
import com.xpn.xwiki.XWiki; |
| 35 |
|
import com.xpn.xwiki.XWikiContext; |
| 36 |
|
import com.xpn.xwiki.XWikiException; |
| 37 |
|
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase; |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@link |
| 41 |
|
|
| 42 |
|
@version |
| 43 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 6 |
Complexity Density: 0.21 |
|
| 44 |
|
public class XWikiMigrationManagerTest extends AbstractBridgedXWikiComponentTestCase |
| 45 |
|
{ |
| 46 |
|
|
| 47 |
|
@Component(staticRegistration = false) |
| 48 |
|
@Named("TestDataMigration") |
| 49 |
|
@Singleton |
| |
|
| 90.9% |
Uncovered Elements: 2 (22) |
Complexity: 10 |
Complexity Density: 0.83 |
|
| 50 |
|
public static class TestDataMigrationManager extends AbstractDataMigrationManager |
| 51 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 52 |
8 |
private DataMigration createMigrator(final int ver)... |
| 53 |
|
{ |
| 54 |
8 |
return new DataMigration() |
| 55 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 56 |
2 |
@Override... |
| 57 |
|
public String getName() |
| 58 |
|
{ |
| 59 |
2 |
return "Test"; |
| 60 |
|
} |
| 61 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 62 |
2 |
@Override... |
| 63 |
|
public String getDescription() |
| 64 |
|
{ |
| 65 |
2 |
return "Test"; |
| 66 |
|
} |
| 67 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 68 |
28 |
@Override... |
| 69 |
|
public XWikiDBVersion getVersion() |
| 70 |
|
{ |
| 71 |
28 |
return new XWikiDBVersion(ver); |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 74 |
2 |
@Override... |
| 75 |
|
public boolean shouldExecute(XWikiDBVersion startupVersion) |
| 76 |
|
{ |
| 77 |
2 |
return true; |
| 78 |
|
} |
| 79 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 80 |
0 |
@Override... |
| 81 |
|
public void migrate() |
| 82 |
|
{ |
| 83 |
|
} |
| 84 |
|
}; |
| 85 |
|
} |
| 86 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 87 |
2 |
@Override... |
| 88 |
|
protected List<DataMigration> getAllMigrations() |
| 89 |
|
{ |
| 90 |
2 |
List<DataMigration> lst = new ArrayList<DataMigration>(); |
| 91 |
2 |
lst.add(createMigrator(345)); |
| 92 |
2 |
lst.add(createMigrator(123)); |
| 93 |
2 |
lst.add(createMigrator(456)); |
| 94 |
2 |
lst.add(createMigrator(234)); |
| 95 |
|
|
| 96 |
2 |
return lst; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
XWikiDBVersion curversion; |
| 100 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 101 |
0 |
@Override... |
| 102 |
|
protected void initializeEmptyDB() throws DataMigrationException |
| 103 |
|
{ |
| 104 |
|
} |
| 105 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 106 |
1 |
@Override... |
| 107 |
|
protected void setDBVersionToDatabase(XWikiDBVersion version) |
| 108 |
|
{ |
| 109 |
1 |
this.curversion = version; |
| 110 |
|
} |
| 111 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 112 |
1 |
@Override... |
| 113 |
|
protected void updateSchema(Collection<XWikiMigration> migrations) |
| 114 |
|
{ |
| 115 |
|
} |
| 116 |
|
} |
| 117 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 118 |
4 |
private void registerComponent(Class<?> klass) throws Exception... |
| 119 |
|
{ |
| 120 |
4 |
ComponentAnnotationLoader loader = new ComponentAnnotationLoader(); |
| 121 |
4 |
List<ComponentDescriptor> descriptors = loader.getComponentsDescriptors(klass); |
| 122 |
|
|
| 123 |
4 |
for (ComponentDescriptor<?> descriptor : descriptors) { |
| 124 |
4 |
getComponentManager().registerComponent(descriptor); |
| 125 |
|
} |
| 126 |
|
} |
| 127 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 128 |
3 |
@Override... |
| 129 |
|
protected void setUp() throws Exception |
| 130 |
|
{ |
| 131 |
3 |
super.setUp(); |
| 132 |
3 |
getContext().setWiki(new XWiki() { |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 133 |
1 |
@Override... |
| 134 |
|
public List<String> getVirtualWikisDatabaseNames(XWikiContext context) throws XWikiException |
| 135 |
|
{ |
| 136 |
1 |
return Arrays.asList("xwiki"); |
| 137 |
|
} |
| 138 |
|
}); |
| 139 |
|
|
| 140 |
3 |
registerComponent(TestDataMigrationManager.class); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 144 |
1 |
public void testMigrationWhenNoVersion() throws Exception... |
| 145 |
|
{ |
| 146 |
1 |
TestDataMigrationManager mm = (TestDataMigrationManager) getComponentManager().getInstance( |
| 147 |
|
DataMigrationManager.class,"TestDataMigration"); |
| 148 |
1 |
Collection neededMigration = mm.getNeededMigrations(); |
| 149 |
1 |
assertEquals(0, neededMigration.size()); |
| 150 |
1 |
mm.startMigrations(); |
| 151 |
1 |
assertEquals(456, mm.curversion.getVersion()); |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 157 |
1 |
public void testMigrationOrderAndIgnore() throws Exception... |
| 158 |
|
{ |
| 159 |
1 |
getConfigurationSource().setProperty("xwiki.store.migration.version", "123"); |
| 160 |
1 |
getConfigurationSource().setProperty("xwiki.store.migration.ignored", "345"); |
| 161 |
1 |
TestDataMigrationManager mm = getComponentManager().getInstance( |
| 162 |
|
DataMigrationManager.class,"TestDataMigration"); |
| 163 |
1 |
Collection neededMigration = mm.getNeededMigrations(); |
| 164 |
1 |
assertEquals(2, neededMigration.size()); |
| 165 |
1 |
AbstractDataMigrationManager.XWikiMigration[] actual = new AbstractDataMigrationManager.XWikiMigration[2]; |
| 166 |
1 |
neededMigration.toArray(actual); |
| 167 |
1 |
assertEquals(234, actual[0].dataMigration.getVersion().getVersion()); |
| 168 |
1 |
assertEquals(456, actual[1].dataMigration.getVersion().getVersion()); |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
@Component(staticRegistration = false) |
| 172 |
|
@Named("TestForcedMigration") |
| 173 |
|
@Singleton |
| |
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 5 |
Complexity Density: 1.25 |
|
| 174 |
|
public static class TestForceMigration implements DataMigration |
| 175 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 176 |
1 |
@Override... |
| 177 |
|
public String getName() |
| 178 |
|
{ |
| 179 |
1 |
return "Test"; |
| 180 |
|
} |
| 181 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 182 |
1 |
@Override... |
| 183 |
|
public String getDescription() |
| 184 |
|
{ |
| 185 |
1 |
return "Test"; |
| 186 |
|
} |
| 187 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 188 |
2 |
@Override... |
| 189 |
|
public XWikiDBVersion getVersion() |
| 190 |
|
{ |
| 191 |
2 |
return new XWikiDBVersion(567); |
| 192 |
|
} |
| 193 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 194 |
0 |
@Override... |
| 195 |
|
public boolean shouldExecute(XWikiDBVersion startupVersion) |
| 196 |
|
{ |
| 197 |
0 |
return true; |
| 198 |
|
} |
| 199 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 200 |
0 |
@Override... |
| 201 |
|
public void migrate() throws DataMigrationException |
| 202 |
|
{ |
| 203 |
|
} |
| 204 |
|
} |
| 205 |
|
|
| 206 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 207 |
1 |
public void testMigrationForce() throws Exception... |
| 208 |
|
{ |
| 209 |
1 |
getConfigurationSource().setProperty("xwiki.store.migration.version", "234"); |
| 210 |
1 |
getConfigurationSource().setProperty("xwiki.store.migration.force", "TestForcedMigration"); |
| 211 |
1 |
registerComponent(TestForceMigration.class); |
| 212 |
|
|
| 213 |
1 |
TestDataMigrationManager mm = getComponentManager().getInstance( |
| 214 |
|
DataMigrationManager.class,"TestDataMigration"); |
| 215 |
1 |
Collection neededMigration = mm.getNeededMigrations(); |
| 216 |
1 |
assertEquals(1, neededMigration.size()); |
| 217 |
1 |
assertEquals(567, ((AbstractDataMigrationManager.XWikiMigration) neededMigration.toArray()[0]) |
| 218 |
|
.dataMigration.getVersion().getVersion()); |
| 219 |
|
} |
| 220 |
|
} |