|
Added
Link Here
|
| 1 |
package org.eclipse.equinox.p2.tests.mirror; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.net.*; |
| 5 |
import java.util.HashMap; |
| 6 |
import java.util.Map; |
| 7 |
import org.eclipse.equinox.app.IApplicationContext; |
| 8 |
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; |
| 9 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
| 10 |
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository; |
| 11 |
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; |
| 12 |
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; |
| 13 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; |
| 14 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; |
| 15 |
import org.eclipse.equinox.internal.provisional.p2.query.Collector; |
| 16 |
import org.eclipse.equinox.internal.simpleconfigurator.utils.URIUtil; |
| 17 |
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication; |
| 18 |
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; |
| 19 |
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; |
| 20 |
import org.osgi.framework.Bundle; |
| 21 |
|
| 22 |
public class MetadataNewMirrorApplicationTest extends AbstractProvisioningTest { |
| 23 |
protected File destRepoLocation; |
| 24 |
protected File sourceRepoLocation; //helloworldfeature |
| 25 |
protected File sourceRepo2Location; //anotherfeature |
| 26 |
protected File sourceRepo3Location; //helloworldfeature + yetanotherfeature |
| 27 |
protected File sourceRepo4Location; //helloworldfeature v1.0.1 |
| 28 |
|
| 29 |
/* (non-Javadoc) |
| 30 |
* @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#setUp() |
| 31 |
*/ |
| 32 |
protected void setUp() throws Exception { |
| 33 |
super.setUp(); |
| 34 |
//load all the repositories |
| 35 |
sourceRepoLocation = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space"); |
| 36 |
sourceRepo2Location = getTestData("0.1", "/testData/mirror/mirrorSourceRepo2"); |
| 37 |
sourceRepo3Location = getTestData("0.2", "/testData/mirror/mirrorSourceRepo3"); |
| 38 |
sourceRepo4Location = getTestData("0.3", "/testData/mirror/mirrorSourceRepo4"); |
| 39 |
|
| 40 |
//create destination location |
| 41 |
destRepoLocation = new File(getTempFolder(), "BasicMirrorApplicationTest"); |
| 42 |
AbstractProvisioningTest.delete(destRepoLocation); |
| 43 |
} |
| 44 |
|
| 45 |
/* (non-Javadoc) |
| 46 |
* @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#tearDown() |
| 47 |
*/ |
| 48 |
protected void tearDown() throws Exception { |
| 49 |
//remove all the repositories |
| 50 |
getMetadataRepositoryManager().removeRepository(destRepoLocation.toURI()); |
| 51 |
getMetadataRepositoryManager().removeRepository(sourceRepoLocation.toURI()); |
| 52 |
getMetadataRepositoryManager().removeRepository(sourceRepo2Location.toURI()); |
| 53 |
getMetadataRepositoryManager().removeRepository(sourceRepo3Location.toURI()); |
| 54 |
getMetadataRepositoryManager().removeRepository(sourceRepo4Location.toURI()); |
| 55 |
|
| 56 |
//delete the destination location (no left over files for the next test) |
| 57 |
delete(destRepoLocation); |
| 58 |
super.tearDown(); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* runs the mirror application with arguments args |
| 63 |
*/ |
| 64 |
private void runMirrorApplication(String message, final String[] args) throws Exception { |
| 65 |
MirrorApplication application = new MirrorApplication(); |
| 66 |
application.start(new IApplicationContext() { |
| 67 |
|
| 68 |
public void applicationRunning() { |
| 69 |
} |
| 70 |
|
| 71 |
public Map getArguments() { |
| 72 |
Map arguments = new HashMap(); |
| 73 |
|
| 74 |
arguments.put(IApplicationContext.APPLICATION_ARGS, args); |
| 75 |
|
| 76 |
return arguments; |
| 77 |
} |
| 78 |
|
| 79 |
public String getBrandingApplication() { |
| 80 |
return null; |
| 81 |
} |
| 82 |
|
| 83 |
public Bundle getBrandingBundle() { |
| 84 |
return null; |
| 85 |
} |
| 86 |
|
| 87 |
public String getBrandingDescription() { |
| 88 |
return null; |
| 89 |
} |
| 90 |
|
| 91 |
public String getBrandingId() { |
| 92 |
return null; |
| 93 |
} |
| 94 |
|
| 95 |
public String getBrandingName() { |
| 96 |
return null; |
| 97 |
} |
| 98 |
|
| 99 |
public String getBrandingProperty(String key) { |
| 100 |
return null; |
| 101 |
} |
| 102 |
}); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Runs mirror application with default arguments. source is the source repo, |
| 107 |
* destination is the destination repo, append is if the "-writeMode clean" argument should be excluded |
| 108 |
* |
| 109 |
* Note: We use URL here because command line applications traffic in unencoded URLs, |
| 110 |
* so we can't use java.net.URI which will always use the encoded form |
| 111 |
*/ |
| 112 |
private void basicRunMirrorApplication(String message, URL source, URL destination, boolean append) throws Exception { |
| 113 |
MirrorApplication app = new MirrorApplication(); |
| 114 |
|
| 115 |
RepositoryDescriptor dest = new RepositoryDescriptor(); |
| 116 |
dest.setLocation(URIUtil.fromString(destination.toExternalForm())); |
| 117 |
dest.setAppend(append); |
| 118 |
dest.setKind("metadata"); |
| 119 |
app.addDestination(dest); |
| 120 |
|
| 121 |
RepositoryDescriptor src = new RepositoryDescriptor(); |
| 122 |
src.setLocation(URIUtil.fromString(source.toExternalForm())); |
| 123 |
src.setKind("metadata"); |
| 124 |
app.addSource(src); |
| 125 |
|
| 126 |
app.run(null); |
| 127 |
} |
| 128 |
|
| 129 |
private void basicRunMirrorApplication(String message, URL source, URL destination, boolean append, String name) throws Exception { |
| 130 |
MirrorApplication app = new MirrorApplication(); |
| 131 |
|
| 132 |
RepositoryDescriptor dest = new RepositoryDescriptor(); |
| 133 |
dest.setLocation(URIUtil.fromString(destination.toExternalForm())); |
| 134 |
dest.setAppend(append); |
| 135 |
dest.setKind("metadata"); |
| 136 |
dest.setName(name); |
| 137 |
app.addDestination(dest); |
| 138 |
|
| 139 |
RepositoryDescriptor src = new RepositoryDescriptor(); |
| 140 |
src.setLocation(URIUtil.fromString(source.toExternalForm())); |
| 141 |
src.setKind("metadata"); |
| 142 |
app.addSource(src); |
| 143 |
|
| 144 |
app.run(null); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* just a wrapper method for compatibility |
| 149 |
*/ |
| 150 |
private void runMirrorApplication(String message, File source, File destination, boolean append) { |
| 151 |
try { |
| 152 |
basicRunMirrorApplication(message, source.toURL(), destination.toURL(), append); |
| 153 |
} catch (Exception e) { |
| 154 |
fail(message, e); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Takes 2 collectors, compares them, and returns the number of unique keys |
| 160 |
* Needed to verify that only the appropriate number of files have been transfered by the mirror application |
| 161 |
*/ |
| 162 |
private int getNumUnique(Collector c1, Collector c2) { |
| 163 |
Object[] repo1 = c1.toCollection().toArray(); |
| 164 |
Object[] repo2 = c2.toCollection().toArray(); |
| 165 |
|
| 166 |
//initialize to the size of both collectors |
| 167 |
int numKeys = repo1.length + repo2.length; |
| 168 |
|
| 169 |
for (int i = 0; i < repo1.length; i++) { |
| 170 |
for (int j = 0; j < repo2.length; j++) { |
| 171 |
if (isEqual((IInstallableUnit) repo1[i], (IInstallableUnit) repo2[j])) |
| 172 |
numKeys--; |
| 173 |
//identical keys has bee found, therefore the number of unique keys is one less than previously thought |
| 174 |
} |
| 175 |
} |
| 176 |
return numKeys; |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Tests mirroring all metadata in a repository to an empty repository |
| 181 |
* Source contains A, B |
| 182 |
* Target contains |
| 183 |
*/ |
| 184 |
private void metadataMirrorToEmpty(String message, boolean append) { |
| 185 |
//destination repo is created blank |
| 186 |
runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, append); //do not append |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries |
| 191 |
* Source contains A, B |
| 192 |
* Target contains C, D |
| 193 |
*/ |
| 194 |
private void metadataMirrorToPopulated(String message, boolean append) { |
| 195 |
//Setup: populate destination with non-duplicate metadata |
| 196 |
runMirrorApplication(message + ".0", sourceRepo2Location, destRepoLocation, false); //value of append does not matter |
| 197 |
|
| 198 |
try { |
| 199 |
//Setup: ensure setup completed successfully |
| 200 |
assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 201 |
} catch (ProvisionException e) { |
| 202 |
fail(message + ".2", e); |
| 203 |
} |
| 204 |
|
| 205 |
//mirror test data |
| 206 |
runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Tests mirroring all metadata in a repository to a repository populated with exact duplicate data |
| 211 |
* @throws Exception |
| 212 |
* Source contains A, B |
| 213 |
* Target contains A, B |
| 214 |
*/ |
| 215 |
private void metadataMirrorToFullDuplicate(String message, boolean append) { |
| 216 |
//Setup: populate destination with duplicate metadata |
| 217 |
runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); //value of append does not matter |
| 218 |
|
| 219 |
try { |
| 220 |
//Setup: verify contents |
| 221 |
assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 222 |
} catch (ProvisionException e) { |
| 223 |
fail(message + ".2", e); |
| 224 |
} |
| 225 |
|
| 226 |
//mirror test data |
| 227 |
runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Tests mirroring all metadata in a repository to a repository populated with partially duplicate data |
| 232 |
* Source contains A, B, C, D |
| 233 |
* Target contains A, B |
| 234 |
*/ |
| 235 |
private void metadataMirrorToPartialDuplicate(String message, boolean append) { |
| 236 |
//Setup: populate destination with duplicate metadata |
| 237 |
runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); //value of append does not matter |
| 238 |
|
| 239 |
try { |
| 240 |
//Setup: verify contents |
| 241 |
assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 242 |
} catch (ProvisionException e) { |
| 243 |
fail(message + ".2", e); |
| 244 |
} |
| 245 |
|
| 246 |
//mirror test data |
| 247 |
runMirrorApplication(message + ".4", sourceRepo3Location, destRepoLocation, append); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data |
| 252 |
* Source contains A, B |
| 253 |
* Target contains A, B, C, D |
| 254 |
*/ |
| 255 |
private void metadataMirrorToPopulatedWithFullDuplicate(String message, boolean append) { |
| 256 |
//Setup: populate destination with non-duplicate metadata |
| 257 |
runMirrorApplication(message + ".0", sourceRepo3Location, destRepoLocation, false); //value of append does not matter |
| 258 |
|
| 259 |
try { |
| 260 |
//Setup: verify |
| 261 |
assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 262 |
} catch (ProvisionException e) { |
| 263 |
fail(message + ".2", e); |
| 264 |
} |
| 265 |
|
| 266 |
//mirror duplicate data |
| 267 |
runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data |
| 272 |
* Source contains A, B, C, D |
| 273 |
* Target contains A, B, E, F |
| 274 |
*/ |
| 275 |
private void metadataMirrorToPopulatedWithPartialDuplicate(String message, boolean append) { |
| 276 |
//Setup: populate destination with non-duplicate metadata |
| 277 |
runMirrorApplication(message + ".0", sourceRepo2Location, destRepoLocation, false); //value of append does not matter |
| 278 |
|
| 279 |
try { |
| 280 |
//Setup: verify |
| 281 |
assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 282 |
} catch (ProvisionException e) { |
| 283 |
fail(message + ".2", e); |
| 284 |
} |
| 285 |
|
| 286 |
//Setup: populate destination with duplicate metadata |
| 287 |
runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, true); |
| 288 |
|
| 289 |
try { |
| 290 |
//Setup: verify |
| 291 |
assertContains(message + ".5", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 292 |
assertContains(message + ".6", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 293 |
} catch (ProvisionException e) { |
| 294 |
fail(message + ".7", e); |
| 295 |
} |
| 296 |
|
| 297 |
//mirror duplicate data |
| 298 |
runMirrorApplication(message + ".7", sourceRepo3Location, destRepoLocation, append); |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* Tests mirroring all artifacts in a repository to an empty repository |
| 303 |
* Source contains A, B |
| 304 |
* Target contains |
| 305 |
*/ |
| 306 |
private File metadataMirrorEmpty(String message, boolean append) { |
| 307 |
//Setup: Create an empty repository |
| 308 |
File emptyRepository = new File(getTempFolder(), getUniqueString()); |
| 309 |
//Setup: remove repository if it exists |
| 310 |
getMetadataRepositoryManager().removeRepository(emptyRepository.toURI()); |
| 311 |
//Setup: delete any data that may be in the folder |
| 312 |
AbstractProvisioningTest.delete(emptyRepository); |
| 313 |
try { |
| 314 |
getMetadataRepositoryManager().createRepository(emptyRepository.toURI(), "Empty Repository", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 315 |
} catch (ProvisionException e) { |
| 316 |
fail(message + ".1", e); |
| 317 |
} |
| 318 |
|
| 319 |
runMirrorApplication(message + ".0", emptyRepository, destRepoLocation, append); |
| 320 |
return emptyRepository; //return the repository for use in verification |
| 321 |
} |
| 322 |
|
| 323 |
/** |
| 324 |
* Tests mirroring all metadata from an empty repository |
| 325 |
* Source contains |
| 326 |
*/ |
| 327 |
private File metadataMirrorEmptyToPopulated(String message, boolean append) { |
| 328 |
//Setup: Populate the repository |
| 329 |
runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); |
| 330 |
|
| 331 |
return metadataMirrorEmpty(message + ".1", append); //create the empty repository, perform the mirror, pass the result back |
| 332 |
} |
| 333 |
|
| 334 |
/** |
| 335 |
* Tests mirroring all metadata in a repository to an empty repository |
| 336 |
* Source contains A, B |
| 337 |
* Target contains |
| 338 |
* Expected is A, B |
| 339 |
*/ |
| 340 |
public void testMetadataMirrorToEmpty() { |
| 341 |
metadataMirrorToEmpty("1.0", true); //run the test with append set to true |
| 342 |
|
| 343 |
try { |
| 344 |
//verify destination's content |
| 345 |
assertContentEquals("1.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 346 |
} catch (ProvisionException e) { |
| 347 |
fail("1.2", e); |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* Tests mirroring all metadata in a repository to an empty repository with "-writeMode clean" |
| 353 |
* Source contains A, B |
| 354 |
* Target contains |
| 355 |
* Expected is A, B |
| 356 |
*/ |
| 357 |
public void testMetadataMirrorToEmptyWithClean() { |
| 358 |
metadataMirrorToEmpty("2.0", false); //run the test with append set to false |
| 359 |
|
| 360 |
try { |
| 361 |
//verify destination's content |
| 362 |
assertContentEquals("2.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 363 |
} catch (ProvisionException e) { |
| 364 |
fail("2.2", e); |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
/** |
| 369 |
* Tests mirroring all metadata in a repository to a repository populated with exact duplicate data |
| 370 |
* Source contains A, B |
| 371 |
* Target contains A, B |
| 372 |
* Expected is A, B |
| 373 |
*/ |
| 374 |
public void testMetadataMirrorToFullDuplicate() { |
| 375 |
metadataMirrorToFullDuplicate("3.0", true); //run the test with append set to true |
| 376 |
|
| 377 |
try { |
| 378 |
//verify destination's content |
| 379 |
assertContentEquals("3.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 380 |
} catch (ProvisionException e) { |
| 381 |
fail("3.2", e); |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
/** |
| 386 |
* Tests mirroring all metadata in a repository to a repository populated with exact duplicate data with "-writeMode clean" |
| 387 |
* Source contains A, B |
| 388 |
* Target contains A, B |
| 389 |
* Expected is A, B |
| 390 |
*/ |
| 391 |
public void testMetadataMirrorToFullDuplicateWithClean() { |
| 392 |
metadataMirrorToFullDuplicate("4.0", false); //run the test with append set to false |
| 393 |
|
| 394 |
try { |
| 395 |
//verify destination's content |
| 396 |
assertContentEquals("4.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 397 |
} catch (ProvisionException e) { |
| 398 |
fail("4.2", e); |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
/** |
| 403 |
* Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries |
| 404 |
* Source contains A, B |
| 405 |
* Target contains C, D |
| 406 |
* Expected is A, B, C, D |
| 407 |
*/ |
| 408 |
public void testMetadataMirrorToPopulated() { |
| 409 |
metadataMirrorToPopulated("5.0", true); //run the test with append set to true |
| 410 |
|
| 411 |
try { |
| 412 |
//verify destination's content |
| 413 |
assertContains("5.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 414 |
assertContains("5.2", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 415 |
//checks that the destination has the correct number of keys (no extras) |
| 416 |
assertEquals("5.3", getNumUnique(getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); |
| 417 |
} catch (ProvisionException e) { |
| 418 |
fail("5.4", e); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
/** |
| 423 |
* Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries with "-writeMode clean" |
| 424 |
* Source contains A, B |
| 425 |
* Target contains C, D |
| 426 |
* Expected is A, B |
| 427 |
*/ |
| 428 |
public void testMetadataMirrorToPopulatedWithClean() { |
| 429 |
metadataMirrorToPopulated("6.0", false); //run the test with append set to false |
| 430 |
|
| 431 |
try { |
| 432 |
//verify destination's content |
| 433 |
assertContentEquals("6.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 434 |
} catch (ProvisionException e) { |
| 435 |
fail("6.2", e); |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* Tests mirroring all metadata in a repository to a repository populated with partially duplicate data |
| 441 |
* Source contains A, B, C, D |
| 442 |
* Target contains A, B |
| 443 |
* Expected is A, B, C, D |
| 444 |
*/ |
| 445 |
public void testMetadataMirrorToPartialDuplicate() { |
| 446 |
metadataMirrorToPartialDuplicate("7.0", true); //run the test with append set to true |
| 447 |
|
| 448 |
try { |
| 449 |
//verify destination's content |
| 450 |
assertContentEquals("7.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 451 |
} catch (ProvisionException e) { |
| 452 |
fail("7.2", e); |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
/** |
| 457 |
* Tests mirroring all metadata in a repository to a repository populated with partially duplicate data with "-writeMode clean" |
| 458 |
* Source contains A, B, C, D |
| 459 |
* Target contains A, B |
| 460 |
* Expected is A, B, C, D |
| 461 |
*/ |
| 462 |
public void testMetadataMirrorToPartialDuplicateWithClean() { |
| 463 |
metadataMirrorToPartialDuplicate("8.0", false); //run the test with append set to false |
| 464 |
|
| 465 |
try { |
| 466 |
//verify destination's content |
| 467 |
assertContentEquals("8.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 468 |
} catch (ProvisionException e) { |
| 469 |
fail("8.2", e); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
/** |
| 474 |
* Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data |
| 475 |
* Source contains A, B |
| 476 |
* Target contains A, B, C, D |
| 477 |
* Expected is A, B, C, D |
| 478 |
*/ |
| 479 |
public void testMetadataMirrorToPopulatedWithFullDuplicate() { |
| 480 |
metadataMirrorToPopulatedWithFullDuplicate("9.0", true); //run the test with append set to true |
| 481 |
|
| 482 |
try { |
| 483 |
//verify destination's content |
| 484 |
assertContentEquals("9.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 485 |
} catch (ProvisionException e) { |
| 486 |
fail("9.2", e); |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
/** |
| 491 |
* Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data with "-writeMode clean" |
| 492 |
* Source contains A, B |
| 493 |
* Target contains A, B, C, D |
| 494 |
* Expected is A, B |
| 495 |
*/ |
| 496 |
public void testMetadataMirrorToPopulatedWithFullDuplicateWithClean() { |
| 497 |
metadataMirrorToPopulatedWithFullDuplicate("10.0", false); //run the test with append set to false |
| 498 |
|
| 499 |
try { |
| 500 |
//verify destination's content |
| 501 |
assertContentEquals("10.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 502 |
} catch (ProvisionException e) { |
| 503 |
fail("10.2", e); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
/** |
| 508 |
* Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data |
| 509 |
* Source contains A, B, C, D |
| 510 |
* Target contains A, B, E, F |
| 511 |
* Expected is A, B, C, D, E, F |
| 512 |
*/ |
| 513 |
public void testMetadataMirrorToPopulatedWithPartialDuplicate() { |
| 514 |
metadataMirrorToPopulatedWithPartialDuplicate("11.0", true); //run the test with append set to true |
| 515 |
|
| 516 |
try { |
| 517 |
//verify destination's content |
| 518 |
assertContains("11.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 519 |
assertContains("11.2", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 520 |
//checks that the destination has the correct number of keys (no extras) |
| 521 |
assertEquals("11.3", getNumUnique(getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); |
| 522 |
} catch (ProvisionException e) { |
| 523 |
fail("11.4", e); |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data with "-writeMode clean" |
| 529 |
* Source contains A, B, C, D |
| 530 |
* Target contains A, B, E, F |
| 531 |
* Expected is A, B, C, D |
| 532 |
*/ |
| 533 |
public void testMetadataMirrorToPopulatedWithPartialDuplicateWithClean() { |
| 534 |
metadataMirrorToPopulatedWithPartialDuplicate("12.0", false); //run the test with append set to false |
| 535 |
|
| 536 |
try { |
| 537 |
//verify destination's content |
| 538 |
assertContentEquals("12.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 539 |
} catch (ProvisionException e) { |
| 540 |
fail("12.2", e); |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
/** |
| 545 |
* Tests MirrorApplication's behaviour when given an invalid source repository |
| 546 |
*/ |
| 547 |
public void testMetadataMirrorFromInvalid() { |
| 548 |
//get a temp folder |
| 549 |
File invalidRepository = new File(getTempFolder(), getUniqueString()); |
| 550 |
//delete any data that may exist in that temp folder |
| 551 |
delete(invalidRepository); |
| 552 |
|
| 553 |
try { |
| 554 |
basicRunMirrorApplication("13.1", invalidRepository.toURL(), destRepoLocation.toURL(), true); |
| 555 |
//we expect a provisioning exception to be thrown and should never get here |
| 556 |
fail("13.0 ProvisionExpection not thrown"); |
| 557 |
} catch (ProvisionException e) { |
| 558 |
return; //correct type of exception has been received |
| 559 |
} catch (Exception e) { |
| 560 |
fail("13.2", e); |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
/** |
| 565 |
* Tests MirrorApplication's behaviour when given an invalid destination repository |
| 566 |
*/ |
| 567 |
public void testMetadataMirrorToInvalid() { |
| 568 |
URI invalidDestRepository; |
| 569 |
try { |
| 570 |
invalidDestRepository = new URI("http://foobar.com/abcdefg"); |
| 571 |
basicRunMirrorApplication("14.1", sourceRepoLocation.toURL(), invalidDestRepository.toURL(), true); |
| 572 |
//we expect an illegal state exception to be thrown and should never get here |
| 573 |
fail("14.0 IllegalStateExpection not thrown"); |
| 574 |
} catch (UnsupportedOperationException e) { |
| 575 |
return; //correct type of exception has been received |
| 576 |
} catch (Exception e) { |
| 577 |
fail("14.1", e); |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* Tests MirrorApplication's behaviour when given both an invalid source and an invalid destination repository |
| 583 |
*/ |
| 584 |
public void testMetadataMirrorBothInvalid() { |
| 585 |
File invalidRepository = new File(getTempFolder(), getUniqueString()); |
| 586 |
delete(invalidRepository); |
| 587 |
|
| 588 |
try { |
| 589 |
URI invalidDestRepository = new URI("http://foobar.com/abcdefg"); |
| 590 |
basicRunMirrorApplication("15.1", invalidRepository.toURL(), invalidDestRepository.toURL(), true); |
| 591 |
//we expect a provisioning exception to be thrown and should never get here |
| 592 |
fail("15.0 ProvisionExpection not thrown"); |
| 593 |
} catch (ProvisionException e) { |
| 594 |
return; //correct type of exception has been thrown |
| 595 |
} catch (Exception e) { |
| 596 |
fail("15.2", e); |
| 597 |
} |
| 598 |
} |
| 599 |
|
| 600 |
/** |
| 601 |
* Tests mirroring an empty repository to another empty repository |
| 602 |
* Source contains |
| 603 |
* Target contains |
| 604 |
* Expected is |
| 605 |
*/ |
| 606 |
public void testMetadataMirrorEmptyToEmpty() { |
| 607 |
File emptyRepository = metadataMirrorEmpty("19.0", false); |
| 608 |
|
| 609 |
try { |
| 610 |
//verify destination's content |
| 611 |
assertContentEquals("16.1", getMetadataRepositoryManager().loadRepository(emptyRepository.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 612 |
} catch (ProvisionException e) { |
| 613 |
fail("16.2", e); |
| 614 |
} |
| 615 |
|
| 616 |
//remove the empty repository |
| 617 |
getMetadataRepositoryManager().removeRepository(emptyRepository.toURI()); |
| 618 |
//delete any leftover data |
| 619 |
delete(emptyRepository); |
| 620 |
} |
| 621 |
|
| 622 |
/** |
| 623 |
* Tests mirroring an empty repository to a populated repository |
| 624 |
* Source contains |
| 625 |
* Target contains A, B |
| 626 |
* Expected is A, B |
| 627 |
*/ |
| 628 |
public void testArtifactMirrorEmptyToPopulated() { |
| 629 |
File emptyRepository = metadataMirrorEmptyToPopulated("17.0", true); |
| 630 |
|
| 631 |
try { |
| 632 |
//verify destination's content |
| 633 |
assertContains("17.1", getMetadataRepositoryManager().loadRepository(emptyRepository.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 634 |
assertContentEquals("17.2", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 635 |
} catch (ProvisionException e) { |
| 636 |
fail("17.3", e); |
| 637 |
} |
| 638 |
|
| 639 |
//remove the empty repository |
| 640 |
getMetadataRepositoryManager().removeRepository(emptyRepository.toURI()); |
| 641 |
//delete any leftover data |
| 642 |
delete(emptyRepository); |
| 643 |
} |
| 644 |
|
| 645 |
/** |
| 646 |
* Tests mirroring an empty repository to a populated repository with "-writeMode clean" |
| 647 |
* Source contains |
| 648 |
* Target contains A, B |
| 649 |
* Expected is |
| 650 |
*/ |
| 651 |
public void testArtifactMirrorEmptyToPopulatedWithClean() { |
| 652 |
File emptyRepository = metadataMirrorEmptyToPopulated("18.0", false); |
| 653 |
|
| 654 |
try { |
| 655 |
//verify destination's content |
| 656 |
assertContentEquals("18.1", getMetadataRepositoryManager().loadRepository(emptyRepository.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 657 |
} catch (ProvisionException e) { |
| 658 |
fail("18.2", e); |
| 659 |
} |
| 660 |
|
| 661 |
//remove the empty repository |
| 662 |
getMetadataRepositoryManager().removeRepository(emptyRepository.toURI()); |
| 663 |
//delete any leftover data |
| 664 |
delete(emptyRepository); |
| 665 |
} |
| 666 |
|
| 667 |
/** |
| 668 |
* Tests mirroring a repository to itself |
| 669 |
* Source contains A, B |
| 670 |
* Target contains A, B |
| 671 |
* Expected is A, B |
| 672 |
*/ |
| 673 |
public void testArtifactMirrorSourceIsDestination() { |
| 674 |
//Setup: Populate the repository |
| 675 |
runMirrorApplication("19.0", sourceRepoLocation, destRepoLocation, false); |
| 676 |
|
| 677 |
//run the mirror application with the source being the same as the destination |
| 678 |
runMirrorApplication("19.1", destRepoLocation, destRepoLocation, true); |
| 679 |
|
| 680 |
try { |
| 681 |
//verify destination's content |
| 682 |
assertContentEquals("19.2", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 683 |
} catch (ProvisionException e) { |
| 684 |
fail("19.3", e); |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
/** |
| 689 |
* Tests mirroring a repository with a different version of the same package |
| 690 |
* Source contains A, B (v1.0.1) |
| 691 |
* Target contains A, B (v1.0.0) |
| 692 |
* Expected is A, B (v1.0.0) and A, B (v1.0.1) |
| 693 |
*/ |
| 694 |
public void testArtifactMirrorDifferentVersions() { |
| 695 |
//Setup: Populate the repository |
| 696 |
runMirrorApplication("20.0", sourceRepoLocation, destRepoLocation, false); |
| 697 |
|
| 698 |
//start a mirror application where the source contains the same artifacts but with a different version compared to the destination |
| 699 |
runMirrorApplication("20.1", sourceRepo4Location, destRepoLocation, true); |
| 700 |
|
| 701 |
try { |
| 702 |
//verify destination's content |
| 703 |
assertContains("20.2", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 704 |
assertContains("20.3", getMetadataRepositoryManager().loadRepository(sourceRepo4Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 705 |
//checks that the destination has the correct number of keys (no extras) |
| 706 |
assertEquals("20.4", getNumUnique(getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getMetadataRepositoryManager().loadRepository(sourceRepo4Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); |
| 707 |
} catch (ProvisionException e) { |
| 708 |
fail("20.5", e); |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
/** |
| 713 |
* Tests how mirror application handles an unspecified source |
| 714 |
*/ |
| 715 |
public void testArtifactMirrorNullSource() { |
| 716 |
String[] args = null; |
| 717 |
//create arguments without a "-source" |
| 718 |
args = new String[] {"-destination", destRepoLocation.toURI().toString()}; |
| 719 |
|
| 720 |
try { |
| 721 |
runMirrorApplication("21.1", args); |
| 722 |
//We expect the IllegalStateException to be thrown |
| 723 |
fail("21.3 IllegalStateException not thrown"); |
| 724 |
} catch (ProvisionException e) { |
| 725 |
return; //expected type of exception has been thrown |
| 726 |
} catch (Exception e) { |
| 727 |
fail("21.2", e); |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
/** |
| 732 |
* Tests how mirror application handles an unspecified destination |
| 733 |
*/ |
| 734 |
public void testArtifactMirrorNullDestination() { |
| 735 |
String[] args = null; |
| 736 |
//create arguments without a "-destination" |
| 737 |
args = new String[] {"-source", sourceRepoLocation.toURI().toString()}; |
| 738 |
|
| 739 |
try { |
| 740 |
runMirrorApplication("22.1", args); |
| 741 |
//We expect the IllegalStateException to be thrown |
| 742 |
fail("22.3 IllegalStateException not thrown"); |
| 743 |
} catch (ProvisionException e) { |
| 744 |
return; //expected type of exception has been thrown |
| 745 |
} catch (Exception e) { |
| 746 |
fail("22.2", e); |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
/** |
| 751 |
* Tests how mirror application handles both an unspecified source and an unspecified destination |
| 752 |
*/ |
| 753 |
public void testArtifactMirrorNullBoth() { |
| 754 |
//create arguments with neither "-destination" nor "-source" |
| 755 |
String[] args = new String[] {}; |
| 756 |
|
| 757 |
try { |
| 758 |
runMirrorApplication("23.0", args); |
| 759 |
//We expect the IllegalStateException to be thrown |
| 760 |
fail("23.2 IllegalStateException not thrown"); |
| 761 |
} catch (ProvisionException e) { |
| 762 |
return; //expected type of exception has been thrown |
| 763 |
} catch (Exception e) { |
| 764 |
fail("23.1", e); |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
/** |
| 769 |
* Ensures that a repository created by the mirror application is a copy of the source |
| 770 |
*/ |
| 771 |
public void testNewArtifactRepoProperties() { |
| 772 |
//run mirror application with source not pre-existing |
| 773 |
metadataMirrorToEmpty("24.0", true); |
| 774 |
|
| 775 |
try { |
| 776 |
IMetadataRepository sourceRepository = getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); |
| 777 |
IMetadataRepository destinationRepository = getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null); |
| 778 |
assertEquals("24.1", sourceRepository.getName(), destinationRepository.getName()); |
| 779 |
assertRepositoryProperties("24.2", sourceRepository.getProperties(), destinationRepository.getProperties()); |
| 780 |
} catch (ProvisionException e) { |
| 781 |
fail("24.3", e); |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
/** |
| 786 |
* Ensures that a repository created before the mirror application is run does not have its properties changed |
| 787 |
*/ |
| 788 |
public void testExistingArtifactRepoProperties() { |
| 789 |
//Setup: create the destination |
| 790 |
String name = "Destination Name"; |
| 791 |
Map properties = null; //default properties |
| 792 |
try { |
| 793 |
//create the repository and get the resulting properties |
| 794 |
properties = getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties).getProperties(); |
| 795 |
} catch (ProvisionException e) { |
| 796 |
fail("25.0", e); |
| 797 |
} |
| 798 |
|
| 799 |
//run the mirror application |
| 800 |
metadataMirrorToEmpty("25.2", true); |
| 801 |
|
| 802 |
try { |
| 803 |
IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null); |
| 804 |
assertEquals("25.3", name, repository.getName()); |
| 805 |
assertRepositoryProperties("25.4", properties, repository.getProperties()); |
| 806 |
} catch (ProvisionException e) { |
| 807 |
fail("25.5", e); |
| 808 |
} |
| 809 |
} |
| 810 |
|
| 811 |
/** |
| 812 |
* Ensures that a repository created by the mirror application has specified name |
| 813 |
* For Bug 256909 |
| 814 |
*/ |
| 815 |
public void testNewArtifactRepoWithNewName() { |
| 816 |
String name = "Bug 256909 test - new"; |
| 817 |
try { |
| 818 |
//set the arguments |
| 819 |
//run the mirror application |
| 820 |
basicRunMirrorApplication("Bug 256909 Test", sourceRepoLocation.toURL(), destRepoLocation.toURL(), false, name); |
| 821 |
} catch (MalformedURLException e) { |
| 822 |
fail("Error creating URLs for Source/Detination", e); |
| 823 |
} catch (Exception e) { |
| 824 |
fail("Error running mirror application", e); |
| 825 |
} |
| 826 |
|
| 827 |
try { |
| 828 |
assertEquals("Assert name was set correct", name, getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getName()); |
| 829 |
} catch (ProvisionException e) { |
| 830 |
fail("Cannot obtain destination", e); |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
/** |
| 835 |
* Ensures that an existing destination used by the mirror application is given specified name |
| 836 |
* For Bug 256909 |
| 837 |
*/ |
| 838 |
public void testExistingArtifactRepoWithNewName() { |
| 839 |
String oldName = "The original naem for Bug 256909 test - existing"; |
| 840 |
String newName = "Bug 256909 test - existing"; |
| 841 |
//Setup create the repository |
| 842 |
IMetadataRepository destinationRepo = null; |
| 843 |
try { |
| 844 |
destinationRepo = getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), oldName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 845 |
} catch (ProvisionException e) { |
| 846 |
fail("Error creating repo at destination", e); |
| 847 |
} |
| 848 |
assertEquals("Assert name is set correctly before mirror", oldName, destinationRepo.getName()); |
| 849 |
|
| 850 |
try { |
| 851 |
//set the arguments |
| 852 |
String[] args = new String[] {"-source", sourceRepoLocation.toURL().toExternalForm(), "-destination", destRepoLocation.toURL().toExternalForm(), "-destinationName", newName}; |
| 853 |
//run the mirror application |
| 854 |
runMirrorApplication("Bug 256909 Test", args); |
| 855 |
} catch (MalformedURLException e) { |
| 856 |
fail("Error creating URLs for Source/Detination", e); |
| 857 |
} catch (Exception e) { |
| 858 |
fail("Error running mirror application", e); |
| 859 |
} |
| 860 |
|
| 861 |
try { |
| 862 |
assertEquals("Assert name is set correctly after mirror", newName, getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getName()); |
| 863 |
} catch (ProvisionException e) { |
| 864 |
fail("Error loading destination", e); |
| 865 |
} |
| 866 |
} |
| 867 |
|
| 868 |
//for Bug 235683 |
| 869 |
public void testMirrorCompressedSource() { |
| 870 |
File compressedSource = getTestData("0", "/testData/mirror/mirrorCompressedRepo"); |
| 871 |
|
| 872 |
//Setup: get the content.jar file |
| 873 |
File compressedMetadataXML = new File(compressedSource.getAbsoluteFile() + "/content.jar"); |
| 874 |
//Setup: make sure content.jar exists |
| 875 |
assertTrue("1", compressedMetadataXML.exists()); |
| 876 |
|
| 877 |
try { |
| 878 |
basicRunMirrorApplication("2", compressedSource.toURL(), destRepoLocation.toURL(), false); |
| 879 |
} catch (MalformedURLException e) { |
| 880 |
fail("3", e); |
| 881 |
} catch (Exception e) { |
| 882 |
fail("4", e); |
| 883 |
} |
| 884 |
|
| 885 |
//get the content.jar file |
| 886 |
File destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.jar"); |
| 887 |
//make sure content.jar exists |
| 888 |
assertTrue("5", destMetadataXML.exists()); |
| 889 |
} |
| 890 |
|
| 891 |
//for Bug 235683 |
| 892 |
public void testMirrorCompressedSourcetoUncompressedDestination() { |
| 893 |
File compressedSource = getTestData("0", "/testData/mirror/mirrorCompressedRepo"); |
| 894 |
|
| 895 |
//Setup: get the content.jar file |
| 896 |
File compressedMetadataXML = new File(compressedSource.getAbsoluteFile() + "/content.jar"); |
| 897 |
//Setup: make sure content.jar exists |
| 898 |
assertTrue("1", compressedMetadataXML.exists()); |
| 899 |
|
| 900 |
//Setup: create the destination |
| 901 |
try { |
| 902 |
String name = "Destination Name " + destRepoLocation; |
| 903 |
getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 904 |
} catch (ProvisionException e) { |
| 905 |
fail("2", e); |
| 906 |
} |
| 907 |
|
| 908 |
try { |
| 909 |
basicRunMirrorApplication("3", compressedSource.toURL(), destRepoLocation.toURL(), false); |
| 910 |
} catch (MalformedURLException e) { |
| 911 |
fail("4", e); |
| 912 |
} catch (Exception e) { |
| 913 |
fail("5", e); |
| 914 |
} |
| 915 |
|
| 916 |
//get the content.jar file |
| 917 |
File destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.jar"); |
| 918 |
//make sure content.jar does not exist |
| 919 |
assertFalse("6", destMetadataXML.exists()); |
| 920 |
//get the content.xml file |
| 921 |
destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.xml"); |
| 922 |
//make sure content.xml exists |
| 923 |
assertTrue("7", destMetadataXML.exists()); |
| 924 |
} |
| 925 |
|
| 926 |
public void testMirrorUncompressedSourceToCompressedDestination() { |
| 927 |
File uncompressedSource = getTestData("0", "/testData/mirror/mirrorSourceRepo3"); |
| 928 |
|
| 929 |
//Setup: get the content.xml file |
| 930 |
File uncompressedContentXML = new File(uncompressedSource.getAbsoluteFile() + "/content.xml"); |
| 931 |
//Setup: make sure content.xml exists |
| 932 |
assertTrue("1", uncompressedContentXML.exists()); |
| 933 |
|
| 934 |
//Setup: create the destination |
| 935 |
try { |
| 936 |
String name = "Destination Name " + destRepoLocation; |
| 937 |
Map property = new HashMap(); |
| 938 |
property.put(IRepository.PROP_COMPRESSED, "true"); |
| 939 |
getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, property); |
| 940 |
} catch (ProvisionException e) { |
| 941 |
fail("2", e); |
| 942 |
} |
| 943 |
|
| 944 |
assertTrue("2.1", new File(destRepoLocation, "content.jar").exists()); |
| 945 |
try { |
| 946 |
basicRunMirrorApplication("3", uncompressedSource.toURL(), destRepoLocation.toURL(), false); |
| 947 |
} catch (MalformedURLException e) { |
| 948 |
fail("4", e); |
| 949 |
} catch (Exception e) { |
| 950 |
fail("5", e); |
| 951 |
} |
| 952 |
|
| 953 |
//get the content.jar file |
| 954 |
File destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.jar"); |
| 955 |
//make sure content.jar does exist |
| 956 |
assertTrue("6", destMetadataXML.exists()); |
| 957 |
//get the content.xml file |
| 958 |
destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.xml"); |
| 959 |
//make sure content.xml exists |
| 960 |
assertFalse("7", destMetadataXML.exists()); |
| 961 |
} |
| 962 |
|
| 963 |
public void testMirrorApplicationWithCompositeSource() { |
| 964 |
//Setup Make composite repository |
| 965 |
File repoLocation = new File(getTempFolder(), "CompositeMetadataMirrorTest"); |
| 966 |
AbstractProvisioningTest.delete(repoLocation); |
| 967 |
IMetadataRepository repo = null; |
| 968 |
try { |
| 969 |
repo = getMetadataRepositoryManager().createRepository(repoLocation.toURI(), "metadata name", IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null); |
| 970 |
} catch (ProvisionException e) { |
| 971 |
fail("Could not create repository"); |
| 972 |
} |
| 973 |
//ensure proper type of repository has been created |
| 974 |
if (!(repo instanceof CompositeMetadataRepository)) |
| 975 |
fail("Repository is not a CompositeMetadataRepository"); |
| 976 |
//Populate source |
| 977 |
File child1 = getTestData("1", "/testData/mirror/mirrorSourceRepo1 with space"); |
| 978 |
File child2 = getTestData("2", "/testData/mirror/mirrorSourceRepo2"); |
| 979 |
((CompositeMetadataRepository) repo).addChild(child1.toURI()); |
| 980 |
((CompositeMetadataRepository) repo).addChild(child2.toURI()); |
| 981 |
|
| 982 |
runMirrorApplication("Mirroring from Composite Source", repoLocation, destRepoLocation, false); |
| 983 |
|
| 984 |
try { |
| 985 |
assertContentEquals("Verifying contents", repo, getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 986 |
|
| 987 |
//Verify that result is the same as mirroring from the 2 repositories seperately |
| 988 |
assertContains("3", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 989 |
assertContains("4", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 990 |
//checks that the destination has the correct number of keys (no extras) |
| 991 |
assertEquals("5", getNumUnique(getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); |
| 992 |
} catch (ProvisionException e) { |
| 993 |
fail("Could not load destination", e); |
| 994 |
} |
| 995 |
} |
| 996 |
} |