|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.equinox.p2.tests.mirror; |
| 12 |
|
| 13 |
import java.io.*; |
| 14 |
import java.lang.reflect.Field; |
| 15 |
import java.net.MalformedURLException; |
| 16 |
import java.net.URI; |
| 17 |
import java.util.*; |
| 18 |
import org.eclipse.core.runtime.*; |
| 19 |
import org.eclipse.equinox.internal.p2.artifact.processors.md5.Messages; |
| 20 |
import org.eclipse.equinox.internal.p2.artifact.repository.*; |
| 21 |
import org.eclipse.equinox.internal.p2.artifact.repository.Activator; |
| 22 |
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; |
| 23 |
import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; |
| 24 |
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; |
| 25 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; |
| 26 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
| 27 |
import org.eclipse.equinox.internal.provisional.p2.core.Version; |
| 28 |
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; |
| 29 |
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; |
| 30 |
import org.eclipse.equinox.p2.internal.repository.tools.*; |
| 31 |
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; |
| 32 |
import org.eclipse.equinox.p2.tests.TestActivator; |
| 33 |
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; |
| 34 |
import org.eclipse.osgi.framework.log.FrameworkLog; |
| 35 |
import org.eclipse.osgi.util.NLS; |
| 36 |
|
| 37 |
/** |
| 38 |
* Test API of the basic mirror application functionality's implementation. |
| 39 |
*/ |
| 40 |
public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest { |
| 41 |
protected File destRepoLocation; |
| 42 |
protected File sourceRepoLocation; //helloworldfeature |
| 43 |
protected File sourceRepo2Location; //anotherfeature |
| 44 |
protected File sourceRepo3Location; //helloworldfeature + yetanotherfeature |
| 45 |
protected File sourceRepo4Location; //helloworldfeature v1.0.1 |
| 46 |
|
| 47 |
/* (non-Javadoc) |
| 48 |
* @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#setUp() |
| 49 |
*/ |
| 50 |
protected void setUp() throws Exception { |
| 51 |
super.setUp(); |
| 52 |
//load all the repositories |
| 53 |
sourceRepoLocation = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space"); |
| 54 |
sourceRepo2Location = getTestData("0.1", "/testData/mirror/mirrorSourceRepo2"); |
| 55 |
sourceRepo3Location = getTestData("0.2", "/testData/mirror/mirrorSourceRepo3"); |
| 56 |
sourceRepo4Location = getTestData("0.3", "/testData/mirror/mirrorSourceRepo4"); |
| 57 |
|
| 58 |
//create destination location |
| 59 |
destRepoLocation = new File(getTempFolder(), "BasicMirrorApplicationTest"); |
| 60 |
delete(destRepoLocation); |
| 61 |
} |
| 62 |
|
| 63 |
/* (non-Javadoc) |
| 64 |
* @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#tearDown() |
| 65 |
*/ |
| 66 |
protected void tearDown() throws Exception { |
| 67 |
//remove all the repositories |
| 68 |
getArtifactRepositoryManager().removeRepository(destRepoLocation.toURI()); |
| 69 |
getArtifactRepositoryManager().removeRepository(sourceRepoLocation.toURI()); |
| 70 |
getArtifactRepositoryManager().removeRepository(sourceRepo2Location.toURI()); |
| 71 |
getArtifactRepositoryManager().removeRepository(sourceRepo3Location.toURI()); |
| 72 |
getArtifactRepositoryManager().removeRepository(sourceRepo4Location.toURI()); |
| 73 |
//delete the destination location (no left over files for the next test) |
| 74 |
delete(destRepoLocation); |
| 75 |
super.tearDown(); |
| 76 |
} |
| 77 |
|
| 78 |
private void basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination, String destName) throws Exception { |
| 79 |
MirrorApplication app = new MirrorApplication(); |
| 80 |
|
| 81 |
if (destination != null) { |
| 82 |
RepositoryDescriptor dest = null; |
| 83 |
if (formatDestination != null && formatDestination) |
| 84 |
dest = createRepositoryDescriptor(destination, append, source, destName); |
| 85 |
else |
| 86 |
dest = createRepositoryDescriptor(destination, append, null, destName); |
| 87 |
app.addDestination(dest); |
| 88 |
} |
| 89 |
|
| 90 |
if (source != null) { |
| 91 |
RepositoryDescriptor src = createRepositoryDescriptor(source, null, null, null); |
| 92 |
app.addSource(src); |
| 93 |
} |
| 94 |
app.run(null); |
| 95 |
} |
| 96 |
|
| 97 |
private void basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination) throws Exception { |
| 98 |
basicRunMirrorApplication(message, source, destination, append, formatDestination, null); |
| 99 |
} |
| 100 |
|
| 101 |
private void basicRunMirrorApplication(String message, URI source, URI destination) throws Exception { |
| 102 |
basicRunMirrorApplication(message, source, destination, null, null, null); |
| 103 |
} |
| 104 |
|
| 105 |
private RepositoryDescriptor createRepositoryDescriptor(URI location, Boolean append, URI format, String name) { |
| 106 |
RepositoryDescriptor descriptor = new RepositoryDescriptor(); |
| 107 |
descriptor.setLocation(location); |
| 108 |
descriptor.setKind("artifact"); |
| 109 |
if (append != null) |
| 110 |
descriptor.setAppend(append); |
| 111 |
if (format != null) |
| 112 |
descriptor.setFormat(format); |
| 113 |
if (name != null) |
| 114 |
descriptor.setName(name); |
| 115 |
return descriptor; |
| 116 |
} |
| 117 |
|
| 118 |
private CompositeArtifactRepository getCompositeSourceRepo(MirrorApplication app) { |
| 119 |
try { |
| 120 |
Field repo = AbstractApplication.class.getDeclaredField("compositeArtifactRepository"); |
| 121 |
repo.setAccessible(true); |
| 122 |
return (CompositeArtifactRepository) repo.get(app); |
| 123 |
} catch (Exception e) { |
| 124 |
fail("Failed to obtain composite repo", e); |
| 125 |
return null; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* just a wrapper method for compatibility |
| 131 |
*/ |
| 132 |
private void runMirrorApplication(String message, File source, File destination, boolean append) { |
| 133 |
try { |
| 134 |
basicRunMirrorApplication(message, source.toURI(), destination.toURI(), append, false); |
| 135 |
} catch (Exception e) { |
| 136 |
fail(message, e); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Tests mirroring all artifacts in a repository to an empty repository |
| 142 |
* Source contains A, B |
| 143 |
* Target contains |
| 144 |
*/ |
| 145 |
private void artifactMirrorToEmpty(String message, boolean append, boolean format) { |
| 146 |
try { |
| 147 |
//destination repo is created blank |
| 148 |
basicRunMirrorApplication(message, sourceRepoLocation.toURI(), destRepoLocation.toURI(), append, format); |
| 149 |
} catch (Exception e) { |
| 150 |
fail(message, e); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries |
| 156 |
* Source contains A, B |
| 157 |
* Target contains C, D |
| 158 |
*/ |
| 159 |
private void artifactMirrorToPopulated(String message, boolean append) { |
| 160 |
//Setup: populate destination with non-duplicate artifacts |
| 161 |
runMirrorApplication(message + ".0", sourceRepo2Location, destRepoLocation, false); //value of append should not matter |
| 162 |
|
| 163 |
try { |
| 164 |
//Setup ensure setup completes successfully |
| 165 |
assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 166 |
} catch (ProvisionException e) { |
| 167 |
fail(message + ".2", e); |
| 168 |
} |
| 169 |
|
| 170 |
//mirror test data |
| 171 |
runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data |
| 176 |
* Source contains A, B |
| 177 |
* Target contains A, B |
| 178 |
*/ |
| 179 |
private void artifactMirrorToFullDuplicate(String message, boolean append) { |
| 180 |
//Setup: populate destination with duplicate artifacts |
| 181 |
runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); //value of append should not matter |
| 182 |
|
| 183 |
try { |
| 184 |
//Setup: verify contents |
| 185 |
assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 186 |
} catch (ProvisionException e) { |
| 187 |
fail(message + ".2", e); |
| 188 |
} |
| 189 |
|
| 190 |
//mirror test data |
| 191 |
runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data |
| 196 |
* Source contains A, B, C, D |
| 197 |
* Target contains A, B |
| 198 |
*/ |
| 199 |
private void artifactMirrorToPartialDuplicate(String message, boolean append) { |
| 200 |
//Setup: populate destination with duplicate artifacts |
| 201 |
runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); |
| 202 |
|
| 203 |
try { |
| 204 |
//Setup: verify contents |
| 205 |
assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 206 |
} catch (ProvisionException e) { |
| 207 |
fail(message + ".2", e); |
| 208 |
} |
| 209 |
|
| 210 |
//mirror test data |
| 211 |
runMirrorApplication(message + ".4", sourceRepo3Location, destRepoLocation, append); |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data |
| 216 |
* Source contains A, B |
| 217 |
* Target contains A, B, C, D |
| 218 |
*/ |
| 219 |
private void artifactMirrorToPopulatedWithFullDuplicate(String message, boolean append) { |
| 220 |
//Setup: populate destination with non-duplicate artifacts |
| 221 |
runMirrorApplication(message + ".0", sourceRepo3Location, destRepoLocation, false); //value of append should not matter |
| 222 |
|
| 223 |
try { |
| 224 |
//Setup: verify |
| 225 |
assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 226 |
} catch (ProvisionException e) { |
| 227 |
fail(message + ".2", e); |
| 228 |
} |
| 229 |
|
| 230 |
//mirror duplicate data |
| 231 |
runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data |
| 236 |
* Source contains A, B, C, D |
| 237 |
* Target contains A, B, E, F |
| 238 |
*/ |
| 239 |
private void artifactMirrorToPopulatedWithPartialDuplicate(String message, boolean append) { |
| 240 |
//Setup: populate destination with non-duplicate artifacts |
| 241 |
runMirrorApplication(message + ".0", sourceRepo2Location, destRepoLocation, false); //value of append should not matter |
| 242 |
|
| 243 |
try { |
| 244 |
//Setup: verify |
| 245 |
assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 246 |
} catch (ProvisionException e) { |
| 247 |
fail(message + ".2", e); |
| 248 |
} |
| 249 |
|
| 250 |
//Setup: populate destination with duplicate artifacts |
| 251 |
runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, true); |
| 252 |
|
| 253 |
try { |
| 254 |
//Setup: verify |
| 255 |
assertContains(message + ".5", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 256 |
assertContains(message + ".6", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 257 |
} catch (ProvisionException e) { |
| 258 |
fail(message + ".7", e); |
| 259 |
} |
| 260 |
|
| 261 |
//mirror duplicate data |
| 262 |
runMirrorApplication(message + ".9", sourceRepo3Location, destRepoLocation, append); |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* Tests mirroring all artifacts from an empty repository |
| 267 |
* Source contains |
| 268 |
*/ |
| 269 |
private File artifactMirrorEmpty(String message, boolean append) { |
| 270 |
//Setup: Create an empty repository |
| 271 |
File emptyRepository = new File(getTempFolder(), getUniqueString()); |
| 272 |
//Setup: remove repository if it exists |
| 273 |
getArtifactRepositoryManager().removeRepository(emptyRepository.toURI()); |
| 274 |
//Setup: delete any data that may be in the folder |
| 275 |
delete(emptyRepository); |
| 276 |
try { |
| 277 |
getArtifactRepositoryManager().createRepository(emptyRepository.toURI(), "Empty Repository", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 278 |
} catch (ProvisionException e) { |
| 279 |
fail(message + ".1", e); |
| 280 |
} |
| 281 |
|
| 282 |
runMirrorApplication(message + ".0", emptyRepository, destRepoLocation, append); |
| 283 |
return emptyRepository; //return the repository for use in verification |
| 284 |
} |
| 285 |
|
| 286 |
/** |
| 287 |
* Tests mirroring all artifacts from an empty repository |
| 288 |
* Source contains |
| 289 |
*/ |
| 290 |
private File artifactMirrorEmptyToPopulated(String message, boolean append) { |
| 291 |
//Setup: Populate the repository |
| 292 |
runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); |
| 293 |
|
| 294 |
return artifactMirrorEmpty(message + ".1", append); //create the empty repository, perform the mirror, pass the result back |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* Runs mirror app on source with missing artifact with "-ignoreErrors" |
| 299 |
*/ |
| 300 |
private void mirrorWithError(boolean verbose) { |
| 301 |
File errorSourceLocation = getTestData("loading error data", "testData/mirror/mirrorErrorSourceRepo"); |
| 302 |
//repo contains an artifact entry for a file that does not exist on disk. this should throw a file not found exception |
| 303 |
try { |
| 304 |
MirrorApplication app = new MirrorApplication(); |
| 305 |
app.addSource(createRepositoryDescriptor(errorSourceLocation.toURI(), null, null, null)); |
| 306 |
app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, null)); |
| 307 |
//Set ignoreErrors flag. Set verbose flag if verbose == true |
| 308 |
app.setVerbose(verbose); |
| 309 |
app.setIgnoreErrors(true); |
| 310 |
//run the mirror application |
| 311 |
app.run(null); |
| 312 |
} catch (Exception e) { |
| 313 |
fail("Running mirror application with errored source failed", e); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* ensures that all files with entries in the repo have corresponding files on disk. |
| 319 |
* Not Biconditional. |
| 320 |
*/ |
| 321 |
private void assertFileSizes(String message, SimpleArtifactRepository expected, SimpleArtifactRepository actual) { |
| 322 |
IArtifactKey[] expectedKeys = expected.getArtifactKeys(); |
| 323 |
|
| 324 |
for (int i = 0; i < expectedKeys.length; i++) { |
| 325 |
IArtifactDescriptor[] expectedDescriptors = expected.getArtifactDescriptors(expectedKeys[i]); |
| 326 |
IArtifactDescriptor[] actualDescriptors = actual.getArtifactDescriptors(expectedKeys[i]); |
| 327 |
|
| 328 |
if (expectedDescriptors == null || actualDescriptors == null) |
| 329 |
if (!(expectedDescriptors == null && actualDescriptors == null)) |
| 330 |
fail(message + " missing key " + expectedKeys[i]); |
| 331 |
|
| 332 |
top: for (int j = 0; j < expectedDescriptors.length; j++) { |
| 333 |
for (int k = 0; k < actualDescriptors.length; k++) { |
| 334 |
if (Arrays.equals(expectedDescriptors[j].getProcessingSteps(), actualDescriptors[k].getProcessingSteps())) { |
| 335 |
File expectedFile = expected.getArtifactFile(expectedDescriptors[j]); |
| 336 |
File actualFile = actual.getArtifactFile(actualDescriptors[k]); |
| 337 |
if (expectedFile == null || actualFile == null) |
| 338 |
fail(message + " descriptor mismatch"); |
| 339 |
if (!(expectedFile.exists() && actualFile.exists())) |
| 340 |
fail(message + " file does not exist"); |
| 341 |
assertTrue(expectedFile.length() == actualFile.length()); |
| 342 |
continue top; |
| 343 |
} |
| 344 |
} |
| 345 |
fail(message + "Missing expected descriptor" + expectedDescriptors[j]); |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
/** |
| 351 |
* Tests mirroring all artifacts in a repository to an empty repository |
| 352 |
* Source contains A, B |
| 353 |
* Target contains |
| 354 |
* Expected is A, B |
| 355 |
*/ |
| 356 |
public void testArtifactMirrorToEmpty() { |
| 357 |
artifactMirrorToEmpty("1.0", true, false); // run the test with append set to true |
| 358 |
|
| 359 |
try { |
| 360 |
//verify destination's content |
| 361 |
assertContentEquals("1.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 362 |
} catch (ProvisionException e) { |
| 363 |
fail("1.2", e); |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
/** |
| 368 |
* Tests mirroring all artifacts in a repository to an empty repository with "-writeMode clean" |
| 369 |
* Source contains A, B |
| 370 |
* Target contains |
| 371 |
* Expected is A, B |
| 372 |
*/ |
| 373 |
public void testArtifactMirrorToEmptyWithClean() { |
| 374 |
artifactMirrorToEmpty("2.0", false, false); |
| 375 |
|
| 376 |
try { |
| 377 |
//verify destination's content |
| 378 |
assertContentEquals("2.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 379 |
} catch (ProvisionException e) { |
| 380 |
fail("2.2", e); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
/** |
| 385 |
* Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data |
| 386 |
* Source contains A, B |
| 387 |
* Target contains A, B |
| 388 |
* Expected is A, B |
| 389 |
*/ |
| 390 |
public void testArtifactMirrorToFullDuplicate() { |
| 391 |
artifactMirrorToFullDuplicate("3.0", true); //run the test with append set to true |
| 392 |
|
| 393 |
try { |
| 394 |
//verify destination's content |
| 395 |
assertContentEquals("3.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 396 |
} catch (ProvisionException e) { |
| 397 |
fail("3.2", e); |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
/** |
| 402 |
* Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data with "-writeMode clean" |
| 403 |
* Source contains A, B |
| 404 |
* Target contains A, B |
| 405 |
* Expected is A, B |
| 406 |
*/ |
| 407 |
public void testArtifactMirrorToFullDuplicateWithClean() { |
| 408 |
artifactMirrorToFullDuplicate("4.0", false); |
| 409 |
|
| 410 |
try { |
| 411 |
//verify destination's content |
| 412 |
assertContentEquals("4.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 413 |
} catch (ProvisionException e) { |
| 414 |
fail("4.2", e); |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
/** |
| 419 |
* Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries |
| 420 |
* Source contains A, B |
| 421 |
* Target contains C, D |
| 422 |
* Expected is A, B, C, D |
| 423 |
*/ |
| 424 |
public void testArtifactMirrorToPopulated() { |
| 425 |
artifactMirrorToPopulated("5.0", true); //run the test with append set to true |
| 426 |
|
| 427 |
try { |
| 428 |
//verify destination's content |
| 429 |
assertContains("5.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 430 |
assertContains("5.2", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 431 |
//checks that the destination has the correct number of keys (no extras) |
| 432 |
assertEquals("5.3", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).getArtifactKeys().length + getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).getArtifactKeys().length, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); |
| 433 |
} catch (ProvisionException e) { |
| 434 |
fail("5.4", e); |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
/** |
| 439 |
* Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries with "-writeMode clean" |
| 440 |
* Source contains A, B |
| 441 |
* Target contains C, D |
| 442 |
* Expected is A, B |
| 443 |
*/ |
| 444 |
public void testArtifactMirrorToPopulatedWithClean() { |
| 445 |
artifactMirrorToPopulated("6.0", false); |
| 446 |
|
| 447 |
try { |
| 448 |
//verify destination's content |
| 449 |
assertContentEquals("6.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 450 |
} catch (ProvisionException e) { |
| 451 |
fail("6.2", e); |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
/** |
| 456 |
* Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data |
| 457 |
* Source contains A, B, C, D |
| 458 |
* Target contains A, B |
| 459 |
* Expected is A, B, C, D |
| 460 |
*/ |
| 461 |
public void testArtifactMirrorToPartialDuplicate() { |
| 462 |
artifactMirrorToPartialDuplicate("7.0", true); //run the test with append set to true |
| 463 |
|
| 464 |
try { |
| 465 |
//verify destination's content |
| 466 |
assertContentEquals("7.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 467 |
} catch (ProvisionException e) { |
| 468 |
fail("7.2", e); |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
/** |
| 473 |
* Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data with "-writeMode clean" |
| 474 |
* Source contains A, B, C, D |
| 475 |
* Target contains A, B |
| 476 |
* Expected is A, B, C, D |
| 477 |
*/ |
| 478 |
public void testArtifactMirrorToPartialDuplicateWithClean() { |
| 479 |
artifactMirrorToPartialDuplicate("8.0", false); |
| 480 |
|
| 481 |
try { |
| 482 |
//verify destination's content |
| 483 |
assertContentEquals("8.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 484 |
} catch (ProvisionException e) { |
| 485 |
fail("8.2", e); |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
/** |
| 490 |
* Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data |
| 491 |
* Source contains A, B |
| 492 |
* Target contains A, B, C, D |
| 493 |
* Expected is A, B, C, D |
| 494 |
*/ |
| 495 |
public void testArtifactMirrorToPopulatedWithFullDuplicate() { |
| 496 |
artifactMirrorToPopulatedWithFullDuplicate("9.0", true); //run the test with append set to true |
| 497 |
|
| 498 |
try { |
| 499 |
//verify destination's content |
| 500 |
assertContentEquals("9.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 501 |
} catch (ProvisionException e) { |
| 502 |
fail("9.2", e); |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data with "-writeMode clean" |
| 508 |
* Source contains A, B |
| 509 |
* Target contains A, B, C, D |
| 510 |
* Expected is A, B |
| 511 |
*/ |
| 512 |
public void testArtifactMirrorToPopulatedWithFullDuplicateWithClean() { |
| 513 |
artifactMirrorToPopulatedWithFullDuplicate("10.0", false); |
| 514 |
|
| 515 |
try { |
| 516 |
//verify destination's content |
| 517 |
assertContentEquals("10.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 518 |
} catch (ProvisionException e) { |
| 519 |
fail("10.2", e); |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
/** |
| 524 |
* Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data |
| 525 |
* Source contains A, B, C, D |
| 526 |
* Target contains A, B, E, F |
| 527 |
* Expected is A, B, C, D, E, F |
| 528 |
*/ |
| 529 |
public void testArtifactMirrorToPopulatedWithPartialDuplicate() { |
| 530 |
artifactMirrorToPopulatedWithPartialDuplicate("11.0", true); //run the test with append set to true |
| 531 |
|
| 532 |
try { |
| 533 |
//verify destination's content |
| 534 |
assertContains("11.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 535 |
assertContains("11.2", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 536 |
//checks that the destination has the correct number of keys (no extras) |
| 537 |
assertEquals("11.3", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).getArtifactKeys().length + getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null).getArtifactKeys().length, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); |
| 538 |
} catch (ProvisionException e) { |
| 539 |
fail("11.4", e); |
| 540 |
} |
| 541 |
} |
| 542 |
|
| 543 |
/** |
| 544 |
* Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data with "-writeMode clean" |
| 545 |
* Source contains A, B, C, D |
| 546 |
* Target contains A, B, E, F |
| 547 |
* Expected is A, B, C, D |
| 548 |
*/ |
| 549 |
public void testArtifactMirrorToPopulatedWithPartialDuplicateWithClean() { |
| 550 |
artifactMirrorToPopulatedWithPartialDuplicate("12.0", false); |
| 551 |
|
| 552 |
try { |
| 553 |
//verify destination's content |
| 554 |
assertContentEquals("12.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 555 |
} catch (ProvisionException e) { |
| 556 |
fail("12.2", e); |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
/** |
| 561 |
* Tests MirrorApplication's behaviour when given an invalid source repository |
| 562 |
*/ |
| 563 |
public void testArtifactMirrorFromInvalid() { |
| 564 |
File invalidRepository = new File(getTempFolder(), getUniqueString()); |
| 565 |
delete(invalidRepository); |
| 566 |
|
| 567 |
try { |
| 568 |
basicRunMirrorApplication("13.1", invalidRepository.toURI(), destRepoLocation.toURI(), true, false); |
| 569 |
//we expect a provision exception to be thrown. We should never get here. |
| 570 |
fail("13.0 ProvisionExpection not thrown"); |
| 571 |
} catch (ProvisionException e) { |
| 572 |
return; //correct type of exception has been thrown |
| 573 |
} catch (Exception e) { |
| 574 |
fail("13.2", e); |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
/** |
| 579 |
* Tests MirrorApplication's behaviour when given an invalid destination repository |
| 580 |
*/ |
| 581 |
public void testArtifactMirrorToInvalid() { |
| 582 |
try { |
| 583 |
//Setup: create a URI pointing to an unmodifiable place |
| 584 |
URI invalidDestRepository = new URI("http://foobar.com/abcdefg"); |
| 585 |
|
| 586 |
//run the application with the modifiable destination |
| 587 |
basicRunMirrorApplication("14.1", sourceRepoLocation.toURI(), invalidDestRepository, true, false); |
| 588 |
//we're expecting an UnsupportedOperationException so we should never get here |
| 589 |
fail("14.0 UnsupportedOperationException not thrown"); |
| 590 |
} catch (UnsupportedOperationException e) { |
| 591 |
return; //correct type of exception has been thrown |
| 592 |
} catch (Exception e) { |
| 593 |
fail("14.2", e); |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
/** |
| 598 |
* Tests MirrorApplication's behaviour when given both an invalid source and an invalid destination repository |
| 599 |
*/ |
| 600 |
public void testArtifactMirrorBothInvalid() { |
| 601 |
//Setup: create a file that is not a valid repository |
| 602 |
File invalidRepository = new File(getTempFolder(), getUniqueString()); |
| 603 |
//Setup: delete any leftover data |
| 604 |
delete(invalidRepository); |
| 605 |
|
| 606 |
try { |
| 607 |
//Setup: create a URI pointing to an unmodifiable place |
| 608 |
URI invalidDestRepository = new URI("http://foobar.com/abcdefg"); |
| 609 |
basicRunMirrorApplication("15.1", invalidRepository.toURI(), invalidDestRepository, true, false); |
| 610 |
//We expect the ProvisionException to be thrown |
| 611 |
fail("15.0 ProvisionException not thrown"); |
| 612 |
} catch (ProvisionException e) { |
| 613 |
return; //correct type of exception was thrown |
| 614 |
} catch (Exception e) { |
| 615 |
fail("15.2", e); |
| 616 |
} |
| 617 |
} |
| 618 |
|
| 619 |
/** |
| 620 |
* Tests mirroring an empty repository to another empty repository |
| 621 |
* Source contains |
| 622 |
* Target contains |
| 623 |
* Expected is |
| 624 |
*/ |
| 625 |
public void testArtifactMirrorEmptyToEmpty() { |
| 626 |
File emptyRepository = artifactMirrorEmpty("16.0", true); |
| 627 |
|
| 628 |
try { |
| 629 |
//verify destination's content |
| 630 |
assertContentEquals("16.1", getArtifactRepositoryManager().loadRepository(emptyRepository.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 631 |
} catch (ProvisionException e) { |
| 632 |
fail("16.2", e); |
| 633 |
} |
| 634 |
|
| 635 |
//remove the emptyRepository |
| 636 |
getArtifactRepositoryManager().removeRepository(emptyRepository.toURI()); |
| 637 |
//delete any left over data |
| 638 |
delete(emptyRepository); |
| 639 |
} |
| 640 |
|
| 641 |
/** |
| 642 |
* Tests mirroring an empty repository to a populated repository |
| 643 |
* Source contains |
| 644 |
* Target contains A, B |
| 645 |
* Expected is A, B |
| 646 |
*/ |
| 647 |
public void testArtifactMirrorEmptyToPopulated() { |
| 648 |
File emptyRepository = artifactMirrorEmptyToPopulated("17.0", true); |
| 649 |
|
| 650 |
try { |
| 651 |
//verify destination's content |
| 652 |
assertContains("17.1", getArtifactRepositoryManager().loadRepository(emptyRepository.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 653 |
assertContentEquals("17.2", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 654 |
} catch (ProvisionException e) { |
| 655 |
fail("17.3", e); |
| 656 |
} |
| 657 |
|
| 658 |
//remove the empty repository |
| 659 |
getArtifactRepositoryManager().removeRepository(emptyRepository.toURI()); |
| 660 |
//remove any leftover data |
| 661 |
delete(emptyRepository); |
| 662 |
} |
| 663 |
|
| 664 |
/** |
| 665 |
* Tests mirroring an empty repository to a populated repository with "-writeMode clean" |
| 666 |
* Source contains |
| 667 |
* Target contains A, B |
| 668 |
* Expected is |
| 669 |
*/ |
| 670 |
public void testArtifactMirrorEmptyToPopulatedWithClean() { |
| 671 |
File emptyRepository = artifactMirrorEmptyToPopulated("18.0", false); |
| 672 |
|
| 673 |
try { |
| 674 |
//verify destination's content |
| 675 |
assertContentEquals("18.1", getArtifactRepositoryManager().loadRepository(emptyRepository.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 676 |
} catch (ProvisionException e) { |
| 677 |
fail("18.2", e); |
| 678 |
} |
| 679 |
|
| 680 |
//remove the empty repository |
| 681 |
getArtifactRepositoryManager().removeRepository(emptyRepository.toURI()); |
| 682 |
//delete any leftover data |
| 683 |
delete(emptyRepository); |
| 684 |
} |
| 685 |
|
| 686 |
/** |
| 687 |
* Tests mirroring a repository to itself |
| 688 |
* Source contains A, B |
| 689 |
* Target contains A, B |
| 690 |
* Expected is A, B |
| 691 |
*/ |
| 692 |
public void testArtifactMirrorSourceIsDestination() { |
| 693 |
//Setup: Populate the repository |
| 694 |
runMirrorApplication("19.0", sourceRepoLocation, destRepoLocation, false); |
| 695 |
|
| 696 |
//run the application with the source and destination specified to the same place |
| 697 |
runMirrorApplication("19.1", destRepoLocation, destRepoLocation, true); |
| 698 |
|
| 699 |
try { |
| 700 |
//verify destination's content |
| 701 |
assertContentEquals("19.2", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 702 |
} catch (ProvisionException e) { |
| 703 |
fail("19.3", e); |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
/** |
| 708 |
* Tests mirroring a repository with a different version of the same package |
| 709 |
* Source contains A, B (v1.0.1) |
| 710 |
* Target contains A, B (v1.0.0) |
| 711 |
* Expected is A, B (v1.0.0) and A, B (v1.0.1) |
| 712 |
*/ |
| 713 |
public void testArtifactMirrorDifferentVersions() { |
| 714 |
//Setup: Populate the repository |
| 715 |
runMirrorApplication("20.0", sourceRepoLocation, destRepoLocation, false); |
| 716 |
|
| 717 |
//run the application with the source and destination specified to the same place |
| 718 |
runMirrorApplication("20.1", sourceRepo4Location, destRepoLocation, true); |
| 719 |
|
| 720 |
try { |
| 721 |
//verify destination's content |
| 722 |
assertContains("20.2", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 723 |
assertContains("20.3", getArtifactRepositoryManager().loadRepository(sourceRepo4Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 724 |
//checks that the destination has the correct number of keys (no extras) |
| 725 |
assertEquals("20.4", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).getArtifactKeys().length + getArtifactRepositoryManager().loadRepository(sourceRepo4Location.toURI(), null).getArtifactKeys().length, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); |
| 726 |
} catch (ProvisionException e) { |
| 727 |
fail("20.5", e); |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
/** |
| 732 |
* Tests how mirror application handles an unspecified source |
| 733 |
*/ |
| 734 |
public void testArtifactMirrorNullSource() { |
| 735 |
try { |
| 736 |
basicRunMirrorApplication("21.1", null, destRepoLocation.toURI()); |
| 737 |
//We expect the ProvisionException to be thrown |
| 738 |
fail("21.3 ProvisionException not thrown"); |
| 739 |
} catch (ProvisionException e) { |
| 740 |
return; //expected type of exception has been thrown |
| 741 |
} catch (Exception e) { |
| 742 |
fail("21.2", e); |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
/** |
| 747 |
* Tests how mirror application handles an unspecified destination |
| 748 |
*/ |
| 749 |
public void testArtifactMirrorNullDestination() { |
| 750 |
try { |
| 751 |
basicRunMirrorApplication("22.1", sourceRepoLocation.toURI(), null); |
| 752 |
//We expect the ProvisionException to be thrown |
| 753 |
fail("22.3 ProvisionException not thrown"); |
| 754 |
} catch (ProvisionException e) { |
| 755 |
return; //expected type of exception has been thrown |
| 756 |
} catch (Exception e) { |
| 757 |
fail("22.2", e); |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
/** |
| 762 |
* Tests how mirror application handles both an unspecified source and an unspecified destination |
| 763 |
*/ |
| 764 |
public void testArtifactMirrorNullBoth() { |
| 765 |
try { |
| 766 |
basicRunMirrorApplication("23.0", null, null); |
| 767 |
//We expect the ProvisionException to be thrown |
| 768 |
fail("23.2 ProvisionException not thrown"); |
| 769 |
} catch (ProvisionException e) { |
| 770 |
return; //expected type of exception has been thrown |
| 771 |
} catch (Exception e) { |
| 772 |
fail("23.1", e); |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
/** |
| 777 |
* Ensures that a repository created by the mirror application is a copy of the source |
| 778 |
*/ |
| 779 |
public void testNewArtifactRepoProperties() { |
| 780 |
//run mirror application with source not preexisting |
| 781 |
artifactMirrorToEmpty("24.0", true, true); |
| 782 |
|
| 783 |
try { |
| 784 |
IArtifactRepository sourceRepository = getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); |
| 785 |
IArtifactRepository destinationRepository = getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null); |
| 786 |
assertEquals("24.1", sourceRepository.getName(), destinationRepository.getName()); |
| 787 |
assertRepositoryProperties("24.2", sourceRepository.getProperties(), destinationRepository.getProperties()); |
| 788 |
} catch (ProvisionException e) { |
| 789 |
fail("24.3", e); |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
/** |
| 794 |
* Ensures that a repository created before the mirror application is run does not have its properties changed |
| 795 |
*/ |
| 796 |
public void testExistingArtifactRepoProperties() { |
| 797 |
//Setup: create the destination |
| 798 |
String name = "Destination Name"; |
| 799 |
Map properties = null; //default properties |
| 800 |
try { |
| 801 |
//create the repository and get the resulting properties |
| 802 |
properties = getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties).getProperties(); |
| 803 |
} catch (ProvisionException e) { |
| 804 |
fail("25.0", e); |
| 805 |
} |
| 806 |
|
| 807 |
//run the mirror application |
| 808 |
artifactMirrorToEmpty("25.2", true, false); |
| 809 |
|
| 810 |
try { |
| 811 |
IArtifactRepository repository = getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null); |
| 812 |
assertEquals("25.3", name, repository.getName()); |
| 813 |
assertRepositoryProperties("25.4", properties, repository.getProperties()); |
| 814 |
} catch (ProvisionException e) { |
| 815 |
fail("25.5", e); |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
/** |
| 820 |
* * Ensures that a repository created by the mirror application has specified name |
| 821 |
* For Bug 256909 |
| 822 |
*/ |
| 823 |
public void testNewArtifactRepoWithNewName() { |
| 824 |
String name = "Bug 256909 test - new"; |
| 825 |
try { |
| 826 |
basicRunMirrorApplication("Bug 256909 Test", sourceRepoLocation.toURI(), destRepoLocation.toURI(), true, false, name); |
| 827 |
} catch (MalformedURLException e) { |
| 828 |
fail("Error creating URLs for Source/Detination", e); |
| 829 |
} catch (Exception e) { |
| 830 |
fail("Error running mirror application", e); |
| 831 |
} |
| 832 |
|
| 833 |
try { |
| 834 |
assertEquals("Assert name was set correct", name, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getName()); |
| 835 |
} catch (ProvisionException e) { |
| 836 |
fail("Cannot obtain destination", e); |
| 837 |
} |
| 838 |
} |
| 839 |
|
| 840 |
/** |
| 841 |
* Ensures that an existing destination used by the mirror application is given specified name |
| 842 |
* For Bug 256909 |
| 843 |
*/ |
| 844 |
public void testExistingArtifactRepoWithNewName() { |
| 845 |
String oldName = "The original naem for Bug 256909 test - existing"; |
| 846 |
String newName = "Bug 256909 test - existing"; |
| 847 |
//Setup create the repository |
| 848 |
IArtifactRepository destinationRepo = null; |
| 849 |
try { |
| 850 |
destinationRepo = getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), oldName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 851 |
} catch (ProvisionException e) { |
| 852 |
fail("Error creating repo at destination", e); |
| 853 |
} |
| 854 |
assertEquals("Assert name is set correctly before mirror", oldName, destinationRepo.getName()); |
| 855 |
|
| 856 |
try { |
| 857 |
MirrorApplication app = new MirrorApplication(); |
| 858 |
app.addSource(createRepositoryDescriptor(sourceRepoLocation.toURI(), null, null, null)); |
| 859 |
app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, newName)); |
| 860 |
//run the mirror application |
| 861 |
app.run(null); |
| 862 |
|
| 863 |
} catch (Exception e) { |
| 864 |
fail("Error running mirror application", e); |
| 865 |
} |
| 866 |
|
| 867 |
try { |
| 868 |
assertEquals("Assert name is set correctly after mirror", newName, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getName()); |
| 869 |
} catch (ProvisionException e) { |
| 870 |
fail("Error loading destination", e); |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
/** |
| 875 |
* Verifies that the mirror application copies files (including packed files) correctly |
| 876 |
*/ |
| 877 |
public void testArtifactFileCopying() { |
| 878 |
//Setup: load the repository containing packed data |
| 879 |
File packedRepoLocation = getTestData("26.0", "/testData/mirror/mirrorPackedRepo"); |
| 880 |
|
| 881 |
try { |
| 882 |
basicRunMirrorApplication("26.1", packedRepoLocation.toURI(), destRepoLocation.toURI(), false, false); |
| 883 |
} catch (Exception e) { |
| 884 |
fail("26.3", e); |
| 885 |
} |
| 886 |
|
| 887 |
try { |
| 888 |
//Verify Contents |
| 889 |
assertContentEquals("26.4", getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 890 |
//Verify files on disk |
| 891 |
assertFileSizes("26.5", (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 892 |
} catch (ProvisionException e) { |
| 893 |
fail("26.6", e); |
| 894 |
} |
| 895 |
} |
| 896 |
|
| 897 |
/** |
| 898 |
* Verifies that the mirror application executes processing steps correctly |
| 899 |
*/ |
| 900 |
public void testArtifactProcessingSteps() { |
| 901 |
//Setup: load the repository containing packed data |
| 902 |
File packedRepoLocation = getTestData("27.0", "/testData/mirror/mirrorPackedRepo"); |
| 903 |
IArtifactRepository packedRepo = null; |
| 904 |
IArtifactRepository destinationRepo = null; |
| 905 |
|
| 906 |
try { |
| 907 |
packedRepo = getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null); |
| 908 |
destinationRepo = getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), "Test Repo", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 909 |
} catch (ProvisionException e1) { |
| 910 |
fail(""); |
| 911 |
} |
| 912 |
|
| 913 |
IArtifactKey[] keys = packedRepo.getArtifactKeys(); |
| 914 |
|
| 915 |
for (int i = 0; i < keys.length; i++) { |
| 916 |
IArtifactDescriptor[] srcDescriptors = packedRepo.getArtifactDescriptors(keys[i]); |
| 917 |
|
| 918 |
for (int j = 0; j < srcDescriptors.length; j++) { |
| 919 |
if (!(srcDescriptors[j].getProperty(IArtifactDescriptor.FORMAT) == null) && srcDescriptors[j].getProperty(IArtifactDescriptor.FORMAT).equals("packed")) { |
| 920 |
//if we have a packed artifact |
| 921 |
IArtifactDescriptor newDescriptor = new ArtifactDescriptor(keys[i]); |
| 922 |
Map properties = new OrderedProperties(); |
| 923 |
properties.putAll(srcDescriptors[j].getProperties()); |
| 924 |
properties.remove(IArtifactDescriptor.FORMAT); |
| 925 |
((ArtifactDescriptor) newDescriptor).addProperties(properties); |
| 926 |
//create appropriate descriptor |
| 927 |
try { |
| 928 |
OutputStream repositoryStream = null; |
| 929 |
try { |
| 930 |
//System.out.println("Mirroring: " + srcDescriptors[j].getArtifactKey() + " (Descriptor: " + srcDescriptors[j] + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 931 |
repositoryStream = destinationRepo.getOutputStream(newDescriptor); |
| 932 |
if (repositoryStream == null) |
| 933 |
return; |
| 934 |
// TODO Is that ok to ignore the result? |
| 935 |
//TODO MAKE THIS WORK PROPERLY |
| 936 |
packedRepo.getArtifact(srcDescriptors[j], repositoryStream, new NullProgressMonitor()); |
| 937 |
} finally { |
| 938 |
if (repositoryStream != null) |
| 939 |
repositoryStream.close(); |
| 940 |
} |
| 941 |
} catch (ProvisionException e) { |
| 942 |
fail("27.1", e); |
| 943 |
} catch (IOException e) { |
| 944 |
fail("27.2", e); |
| 945 |
} |
| 946 |
//corresponding key should now be in the destination |
| 947 |
IArtifactDescriptor[] destDescriptors = destinationRepo.getArtifactDescriptors(keys[i]); |
| 948 |
boolean canonicalFound = false; |
| 949 |
for (int l = 0; !canonicalFound && (l < destDescriptors.length); l++) { |
| 950 |
//No processing steps mean item is canonical |
| 951 |
if (destDescriptors[l].getProcessingSteps().length == 0) |
| 952 |
canonicalFound = true; |
| 953 |
} |
| 954 |
if (!canonicalFound) |
| 955 |
fail("27.3 no canonical found for " + keys[i].toString()); |
| 956 |
|
| 957 |
//ensure the canonical matches that in the expected |
| 958 |
assertFileSizes("27.3", (SimpleArtifactRepository) destinationRepo, (SimpleArtifactRepository) packedRepo); |
| 959 |
} |
| 960 |
} |
| 961 |
} |
| 962 |
} |
| 963 |
|
| 964 |
//for Bug 235683 |
| 965 |
public void testMirrorCompressedSource() { |
| 966 |
File compressedSource = getTestData("0", "/testData/mirror/mirrorCompressedRepo"); |
| 967 |
|
| 968 |
//Setup: get the artifacts.jar file |
| 969 |
File compressedArtifactsXML = new File(compressedSource.getAbsoluteFile() + "/artifacts.jar"); |
| 970 |
//Setup: make sure artifacts.jar exists |
| 971 |
assertTrue("1", compressedArtifactsXML.exists()); |
| 972 |
|
| 973 |
try { |
| 974 |
basicRunMirrorApplication("2", compressedSource.toURI(), destRepoLocation.toURI(), false, false); |
| 975 |
} catch (MalformedURLException e) { |
| 976 |
fail("3", e); |
| 977 |
} catch (Exception e) { |
| 978 |
fail("4", e); |
| 979 |
} |
| 980 |
|
| 981 |
//get the artifacts.jar file |
| 982 |
File destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.jar"); |
| 983 |
//make sure artifacts.jar exists |
| 984 |
assertTrue("5", destArtifactsXML.exists()); |
| 985 |
} |
| 986 |
|
| 987 |
//for Bug 235683 |
| 988 |
public void testMirrorCompressedSourcetoUncompressedDestination() { |
| 989 |
File compressedSource = getTestData("0", "/testData/mirror/mirrorCompressedRepo"); |
| 990 |
|
| 991 |
//Setup: get the artifacts.jar file |
| 992 |
File compressedArtifactsXML = new File(compressedSource.getAbsoluteFile() + "/artifacts.jar"); |
| 993 |
//Setup: make sure artifacts.jar exists |
| 994 |
assertTrue("1", compressedArtifactsXML.exists()); |
| 995 |
|
| 996 |
//Setup: create the destination |
| 997 |
try { |
| 998 |
String name = "Destination Name " + destRepoLocation; |
| 999 |
getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 1000 |
} catch (ProvisionException e) { |
| 1001 |
fail("2", e); |
| 1002 |
} |
| 1003 |
|
| 1004 |
assertTrue("2.1", new File(destRepoLocation, "artifacts.xml").exists()); |
| 1005 |
try { |
| 1006 |
basicRunMirrorApplication("3", compressedSource.toURI(), destRepoLocation.toURI(), false, false); |
| 1007 |
} catch (MalformedURLException e) { |
| 1008 |
fail("4", e); |
| 1009 |
} catch (Exception e) { |
| 1010 |
fail("5", e); |
| 1011 |
} |
| 1012 |
|
| 1013 |
//get the artifacts.jar file |
| 1014 |
File destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.jar"); |
| 1015 |
//make sure artifacts.jar does not exist |
| 1016 |
assertFalse("6", destArtifactsXML.exists()); |
| 1017 |
//get the artifacts.xml file |
| 1018 |
destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.xml"); |
| 1019 |
//make sure artifacts.xml exists |
| 1020 |
assertTrue("7", destArtifactsXML.exists()); |
| 1021 |
} |
| 1022 |
|
| 1023 |
//for Bug 235683 |
| 1024 |
public void testMirrorUncompressedSourceToCompressedDestination() { |
| 1025 |
File uncompressedSource = getTestData("0", "/testData/mirror/mirrorPackedRepo"); |
| 1026 |
|
| 1027 |
//Setup: get the artifacts.xml file |
| 1028 |
File artifactsXML = new File(uncompressedSource.getAbsoluteFile() + "/artifacts.xml"); |
| 1029 |
//Setup: make sure artifacts.xml exists |
| 1030 |
assertTrue("1", artifactsXML.exists()); |
| 1031 |
|
| 1032 |
//Setup: create the destination |
| 1033 |
try { |
| 1034 |
String name = "Destination Name " + destRepoLocation; |
| 1035 |
Map property = new HashMap(); |
| 1036 |
property.put(IRepository.PROP_COMPRESSED, "true"); |
| 1037 |
getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, property); |
| 1038 |
} catch (ProvisionException e) { |
| 1039 |
fail("2", e); |
| 1040 |
} |
| 1041 |
|
| 1042 |
assertTrue("2.1", new File(destRepoLocation, "artifacts.jar").exists()); |
| 1043 |
try { |
| 1044 |
basicRunMirrorApplication("3", uncompressedSource.toURI(), destRepoLocation.toURI(), false, false); |
| 1045 |
} catch (MalformedURLException e) { |
| 1046 |
fail("4", e); |
| 1047 |
} catch (Exception e) { |
| 1048 |
fail("5", e); |
| 1049 |
} |
| 1050 |
|
| 1051 |
//get the artifacts.jar file |
| 1052 |
File destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.jar"); |
| 1053 |
//make sure artifacts.jar does exist |
| 1054 |
assertTrue("6", destArtifactsXML.exists()); |
| 1055 |
//get the artifacts.xml file |
| 1056 |
destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.xml"); |
| 1057 |
//make sure artifacts.xml does not exist |
| 1058 |
assertFalse("7", destArtifactsXML.exists()); |
| 1059 |
} |
| 1060 |
|
| 1061 |
public void testMirrorApplicationWithCompositeSource() { |
| 1062 |
//Setup Make composite repository |
| 1063 |
File repoLocation = new File(getTempFolder(), "CompositeArtifactMirrorTest"); |
| 1064 |
AbstractProvisioningTest.delete(repoLocation); |
| 1065 |
IArtifactRepository repo = null; |
| 1066 |
try { |
| 1067 |
repo = getArtifactRepositoryManager().createRepository(repoLocation.toURI(), "artifact name", IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null); |
| 1068 |
} catch (ProvisionException e) { |
| 1069 |
fail("Could not create repository"); |
| 1070 |
} |
| 1071 |
//ensure proper type of repository has been created |
| 1072 |
if (!(repo instanceof CompositeArtifactRepository)) |
| 1073 |
fail("Repository is not a CompositeArtifactRepository"); |
| 1074 |
//Populate source |
| 1075 |
File child1 = getTestData("1", "/testData/mirror/mirrorSourceRepo1 with space"); |
| 1076 |
File child2 = getTestData("2", "/testData/mirror/mirrorSourceRepo2"); |
| 1077 |
((CompositeArtifactRepository) repo).addChild(child1.toURI()); |
| 1078 |
((CompositeArtifactRepository) repo).addChild(child2.toURI()); |
| 1079 |
|
| 1080 |
runMirrorApplication("Mirroring from Composite Source", repoLocation, destRepoLocation, false); |
| 1081 |
|
| 1082 |
try { |
| 1083 |
assertContentEquals("Verifying contents", repo, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 1084 |
|
| 1085 |
//Verify that result is the same as mirroring from the 2 repositories separately |
| 1086 |
assertContains("3", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 1087 |
assertContains("4", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 1088 |
//checks that the destination has the correct number of keys (no extras) |
| 1089 |
assertEquals("5", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).getArtifactKeys().length + getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).getArtifactKeys().length, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); |
| 1090 |
} catch (ProvisionException e) { |
| 1091 |
fail("Could not load destination", e); |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
//for Bug 250527 |
| 1096 |
public void testIgnoreErrorsArgument() { |
| 1097 |
//Error prints to stderr, redirect that to a file |
| 1098 |
PrintStream oldErr = System.err; |
| 1099 |
PrintStream newErr = null; |
| 1100 |
try { |
| 1101 |
destRepoLocation.mkdir(); |
| 1102 |
newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err"))); |
| 1103 |
} catch (FileNotFoundException e) { |
| 1104 |
fail("Error redirecting outputs", e); |
| 1105 |
} |
| 1106 |
System.setErr(newErr); |
| 1107 |
|
| 1108 |
//run test without verbose |
| 1109 |
mirrorWithError(false); |
| 1110 |
|
| 1111 |
System.setErr(oldErr); |
| 1112 |
newErr.close(); |
| 1113 |
|
| 1114 |
try { |
| 1115 |
assertEquals("Verifying correct number of Keys", 1, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); |
| 1116 |
//Because only 1 of the artifacts exists on disk, the number of artifacts in the destination should only be 1. |
| 1117 |
//Order in which mirror application mirrors artifacts is random. |
| 1118 |
} catch (ProvisionException e) { |
| 1119 |
fail("Error laoding destiantion repo", e); |
| 1120 |
} |
| 1121 |
} |
| 1122 |
|
| 1123 |
public void testCompareUsingMD5Comparator() { |
| 1124 |
//Setup create descriptors with different md5 values |
| 1125 |
IArtifactKey dupKey = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3")); |
| 1126 |
File artifact1 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space/artifacts.xml"); |
| 1127 |
File artifact2 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo2/artifacts.xml"); |
| 1128 |
IArtifactDescriptor descriptor1 = PublisherHelper.createArtifactDescriptor(dupKey, artifact1); |
| 1129 |
IArtifactDescriptor descriptor2 = PublisherHelper.createArtifactDescriptor(dupKey, artifact2); |
| 1130 |
|
| 1131 |
assertEquals("Ensuring Descriptors are the same", descriptor1, descriptor2); |
| 1132 |
assertNotSame("Ensuring MD5 values are different", descriptor1.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); |
| 1133 |
|
| 1134 |
//Setup make repositories |
| 1135 |
File repo1Location = getTestFolder(getUniqueString()); |
| 1136 |
File repo2Location = getTestFolder(getUniqueString()); |
| 1137 |
IArtifactRepository repo1 = null; |
| 1138 |
IArtifactRepository repo2 = null; |
| 1139 |
try { |
| 1140 |
repo1 = getArtifactRepositoryManager().createRepository(repo1Location.toURI(), "Repo 1", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 1141 |
repo1.addDescriptor(descriptor1); |
| 1142 |
repo2 = getArtifactRepositoryManager().createRepository(repo2Location.toURI(), "Repo 2", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 1143 |
repo2.addDescriptor(descriptor2); |
| 1144 |
} catch (ProvisionException e) { |
| 1145 |
fail("Error creating repositories", e); |
| 1146 |
} |
| 1147 |
|
| 1148 |
//Comparator prints to stderr, redirect that to a file |
| 1149 |
PrintStream oldErr = System.err; |
| 1150 |
PrintStream newErr = null; |
| 1151 |
PrintStream oldOut = System.out; |
| 1152 |
PrintStream newOut = null; |
| 1153 |
try { |
| 1154 |
newErr = new PrintStream(new FileOutputStream(new File(repo2Location, "sys.err"))); |
| 1155 |
newOut = new PrintStream(new FileOutputStream(new File(repo2Location, "sys.out"))); |
| 1156 |
} catch (FileNotFoundException e) { |
| 1157 |
fail("Error redirecting outputs", e); |
| 1158 |
} |
| 1159 |
System.setErr(newErr); |
| 1160 |
System.setOut(newOut); |
| 1161 |
MirrorApplication app = null; |
| 1162 |
try { |
| 1163 |
app = new MirrorApplication(); |
| 1164 |
app.addSource(createRepositoryDescriptor(repo1Location.toURI(), null, null, null)); |
| 1165 |
app.addDestination(createRepositoryDescriptor(repo2Location.toURI(), null, null, null)); |
| 1166 |
app.setVerbose(true); |
| 1167 |
//Set compare flag. |
| 1168 |
app.setCompare(true); |
| 1169 |
//run the mirror application |
| 1170 |
app.run(null); |
| 1171 |
} catch (Exception e) { |
| 1172 |
fail("Running mirror application with duplicate descriptors with different md5 values failed", e); |
| 1173 |
} |
| 1174 |
System.setErr(oldErr); |
| 1175 |
newErr.close(); |
| 1176 |
System.setOut(oldOut); |
| 1177 |
newOut.close(); |
| 1178 |
|
| 1179 |
IArtifactDescriptor[] destDescriptors = repo2.getArtifactDescriptors(descriptor2.getArtifactKey()); |
| 1180 |
assertEquals("Ensuring destination has correct number of descriptors", 1, destDescriptors.length); |
| 1181 |
assertEquals("Ensuring proper descriptor exists in destination", descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), destDescriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); |
| 1182 |
String msg = NLS.bind(Messages.warning_differentMD5, new Object[] {getCompositeSourceRepo(app), repo2, descriptor1}); |
| 1183 |
try { |
| 1184 |
assertLogContainsLine(TestActivator.getLogFile(), msg); |
| 1185 |
} catch (Exception e) { |
| 1186 |
fail("error verifying output", e); |
| 1187 |
} |
| 1188 |
} |
| 1189 |
|
| 1190 |
public void testBaselineCompareUsingMD5Comparator() { |
| 1191 |
//Setup create descriptors with different md5 values |
| 1192 |
IArtifactKey dupKey = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3")); |
| 1193 |
File artifact1 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space/content.xml"); |
| 1194 |
File artifact2 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo2/content.xml"); |
| 1195 |
|
| 1196 |
//Setup Copy the file to the baseline |
| 1197 |
File repoLocation = getTestFolder(getUniqueString()); |
| 1198 |
File baselineLocation = getTestFolder(getUniqueString()); |
| 1199 |
File baselineBinaryDirectory = new File(baselineLocation, "binary"); |
| 1200 |
baselineBinaryDirectory.mkdir(); |
| 1201 |
File baselineContentLocation = new File(baselineBinaryDirectory, "testKeyId_1.2.3"); |
| 1202 |
AbstractProvisioningTest.copy("Copying File to baseline", artifact2, baselineContentLocation); |
| 1203 |
|
| 1204 |
IArtifactDescriptor descriptor1 = PublisherHelper.createArtifactDescriptor(dupKey, artifact1); |
| 1205 |
IArtifactDescriptor descriptor2 = PublisherHelper.createArtifactDescriptor(dupKey, baselineContentLocation); |
| 1206 |
|
| 1207 |
assertEquals("Ensuring Descriptors are the same", descriptor1, descriptor2); |
| 1208 |
assertNotSame("Ensuring MD5 values are different", descriptor1.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); |
| 1209 |
|
| 1210 |
//Setup make repositories |
| 1211 |
IArtifactRepository repo = null; |
| 1212 |
IArtifactRepository baseline = null; |
| 1213 |
try { |
| 1214 |
repo = getArtifactRepositoryManager().createRepository(repoLocation.toURI(), "Repo 1", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 1215 |
repo.addDescriptor(descriptor1); |
| 1216 |
baseline = getArtifactRepositoryManager().createRepository(baselineLocation.toURI(), "Repo 2", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 1217 |
baseline.addDescriptor(descriptor2); |
| 1218 |
} catch (ProvisionException e) { |
| 1219 |
fail("Error creating repositories", e); |
| 1220 |
} |
| 1221 |
|
| 1222 |
//Comparator prints to stderr, redirect that to a file |
| 1223 |
PrintStream oldErr = System.err; |
| 1224 |
PrintStream newErr = null; |
| 1225 |
PrintStream oldOut = System.out; |
| 1226 |
PrintStream newOut = null; |
| 1227 |
try { |
| 1228 |
destRepoLocation.mkdir(); |
| 1229 |
newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err"))); |
| 1230 |
newOut = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.out"))); |
| 1231 |
} catch (FileNotFoundException e) { |
| 1232 |
fail("Error redirecting outputs", e); |
| 1233 |
} |
| 1234 |
System.setErr(newErr); |
| 1235 |
System.setOut(newOut); |
| 1236 |
MirrorApplication app = null; |
| 1237 |
try { |
| 1238 |
app = new MirrorApplication(); |
| 1239 |
app.addSource(createRepositoryDescriptor(repoLocation.toURI(), null, null, null)); |
| 1240 |
app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, null)); |
| 1241 |
//Set baseline |
| 1242 |
app.setBaseline(baselineLocation.toURI()); |
| 1243 |
app.setVerbose(true); |
| 1244 |
//Set compare flag. |
| 1245 |
app.setCompare(true); |
| 1246 |
//run the mirror application |
| 1247 |
app.run(null); |
| 1248 |
} catch (Exception e) { |
| 1249 |
fail("Running mirror application with baseline compare", e); |
| 1250 |
} |
| 1251 |
System.setErr(oldErr); |
| 1252 |
newErr.close(); |
| 1253 |
System.setOut(oldOut); |
| 1254 |
newOut.close(); |
| 1255 |
|
| 1256 |
IArtifactRepository destination = null; |
| 1257 |
try { |
| 1258 |
destination = getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null); |
| 1259 |
} catch (ProvisionException e) { |
| 1260 |
fail("Error loading destination", e); |
| 1261 |
} |
| 1262 |
|
| 1263 |
IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor2.getArtifactKey()); |
| 1264 |
assertEquals("Ensuring destination has correct number of descriptors", 1, destDescriptors.length); |
| 1265 |
assertEquals("Ensuring destination contains the descriptor from the baseline", descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), destDescriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); |
| 1266 |
String msg = NLS.bind(Messages.warning_differentMD5, new Object[] {baseline, getCompositeSourceRepo(app), descriptor1}); |
| 1267 |
try { |
| 1268 |
assertLogContainsLine(TestActivator.getLogFile(), msg); |
| 1269 |
} catch (Exception e) { |
| 1270 |
fail("error verifying output", e); |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
//for Bug 259111 |
| 1275 |
public void testDownloadRetry() { |
| 1276 |
//repository that is known to force a retry |
| 1277 |
class TestRetryArtifactRepository extends SimpleArtifactRepository { |
| 1278 |
public boolean firstAttempt = true; |
| 1279 |
IArtifactRepository source; |
| 1280 |
|
| 1281 |
public TestRetryArtifactRepository(String repositoryName, URI location, URI srcLocation, Map properties, IArtifactRepositoryManager manager) { |
| 1282 |
super(repositoryName, location, properties); |
| 1283 |
|
| 1284 |
//initialize |
| 1285 |
try { |
| 1286 |
source = manager.loadRepository(srcLocation, null); |
| 1287 |
} catch (ProvisionException e) { |
| 1288 |
fail("Unable to load source for wrapping", e); |
| 1289 |
} |
| 1290 |
manager.removeRepository(srcLocation); |
| 1291 |
} |
| 1292 |
|
| 1293 |
public synchronized IArtifactKey[] getArtifactKeys() { |
| 1294 |
return source.getArtifactKeys(); |
| 1295 |
} |
| 1296 |
|
| 1297 |
public synchronized IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) { |
| 1298 |
return source.getArtifactDescriptors(key); |
| 1299 |
} |
| 1300 |
|
| 1301 |
public IStatus getRawArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { |
| 1302 |
if (firstAttempt) { |
| 1303 |
firstAttempt = false; |
| 1304 |
return new Status(IStatus.ERROR, Activator.ID, IArtifactRepository.CODE_RETRY, "Forcing Retry", new ProvisionException("Forcing retry")); |
| 1305 |
} |
| 1306 |
|
| 1307 |
return source.getRawArtifact(descriptor, destination, monitor); |
| 1308 |
} |
| 1309 |
|
| 1310 |
public synchronized boolean contains(IArtifactDescriptor descriptor) { |
| 1311 |
return source.contains(descriptor); |
| 1312 |
} |
| 1313 |
} |
| 1314 |
|
| 1315 |
//set up test repository |
| 1316 |
File retryRepoLoaction = new File(getTempFolder(), "259111 Repo"); |
| 1317 |
IArtifactRepository retryRepo = new TestRetryArtifactRepository("Test Repo", retryRepoLoaction.toURI(), sourceRepoLocation.toURI(), null, getArtifactRepositoryManager()); |
| 1318 |
((ArtifactRepositoryManager) getArtifactRepositoryManager()).addRepository(retryRepo); |
| 1319 |
|
| 1320 |
try { |
| 1321 |
basicRunMirrorApplication("Forcing Retry", retryRepo.getLocation(), destRepoLocation.toURI()); |
| 1322 |
} catch (MalformedURLException e) { |
| 1323 |
fail("Error creating arguments", e); |
| 1324 |
} catch (Exception e) { |
| 1325 |
fail("Error while running Mirror Application and forcing retry", e); |
| 1326 |
} |
| 1327 |
|
| 1328 |
//ensure error was resulted |
| 1329 |
assertFalse(((TestRetryArtifactRepository) retryRepo).firstAttempt); |
| 1330 |
try { |
| 1331 |
//verify destination's content |
| 1332 |
assertContentEquals("Verifying content", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 1333 |
} catch (ProvisionException e) { |
| 1334 |
fail("Failure while verifying destination", e); |
| 1335 |
} |
| 1336 |
} |
| 1337 |
|
| 1338 |
//for Bug 259112 |
| 1339 |
public void testErrorLoggingNoVerbose() { |
| 1340 |
//initialize log file |
| 1341 |
FrameworkLog log = (FrameworkLog) ServiceHelper.getService(Activator.getContext(), FrameworkLog.class.getName()); |
| 1342 |
assertNotNull("Assert log file is not null", log); |
| 1343 |
assertTrue("Clearing log file", log.getFile().delete()); |
| 1344 |
|
| 1345 |
//Comparator prints to stderr, redirect that to a file |
| 1346 |
PrintStream oldErr = System.err; |
| 1347 |
PrintStream newErr = null; |
| 1348 |
try { |
| 1349 |
destRepoLocation.mkdir(); |
| 1350 |
newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err"))); |
| 1351 |
} catch (FileNotFoundException e) { |
| 1352 |
fail("Error redirecting outputs", e); |
| 1353 |
} |
| 1354 |
System.setErr(newErr); |
| 1355 |
|
| 1356 |
//run test without verbose resulting in error |
| 1357 |
mirrorWithError(false); |
| 1358 |
|
| 1359 |
System.setErr(oldErr); |
| 1360 |
newErr.close(); |
| 1361 |
|
| 1362 |
//verify log |
| 1363 |
try { |
| 1364 |
String[] parts = new String[] {"java.io.FileNotFoundException: ", "helloworld_1.0.0.jar"}; |
| 1365 |
assertLogContainsLine(log.getFile(), parts); |
| 1366 |
} catch (Exception e) { |
| 1367 |
fail("error verifying output", e); |
| 1368 |
} |
| 1369 |
|
| 1370 |
//run without verbose |
| 1371 |
artifactMirrorToFullDuplicate("Generating INFO entries", true); |
| 1372 |
|
| 1373 |
IArtifactRepository sourceRepository = null; |
| 1374 |
try { |
| 1375 |
sourceRepository = getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); |
| 1376 |
} catch (ProvisionException e) { |
| 1377 |
fail("Error loading source repository for verification", e); |
| 1378 |
} |
| 1379 |
|
| 1380 |
try { |
| 1381 |
//Mirroring full duplicate, so any key will do. |
| 1382 |
IArtifactDescriptor[] descriptors = sourceRepository.getArtifactDescriptors(sourceRepository.getArtifactKeys()[0]); |
| 1383 |
//Mirroring full duplicate, so any descriptor will do. |
| 1384 |
String message = NLS.bind(org.eclipse.equinox.internal.p2.artifact.repository.Messages.mirror_alreadyExists, descriptors[0], destRepoLocation.toURI()); |
| 1385 |
assertLogDoesNotContainLine(log.getFile(), message); |
| 1386 |
} catch (Exception e) { |
| 1387 |
fail("Error verifying log", e); |
| 1388 |
} |
| 1389 |
} |
| 1390 |
|
| 1391 |
//for Bug 259112 |
| 1392 |
public void testErrorLoggingWithVerbose() { |
| 1393 |
//initialize log file |
| 1394 |
FrameworkLog log = (FrameworkLog) ServiceHelper.getService(Activator.getContext(), FrameworkLog.class.getName()); |
| 1395 |
assertNotNull("Assert log file is not null", log); |
| 1396 |
assertTrue("Clearing log file", log.getFile().exists() && log.getFile().delete()); |
| 1397 |
|
| 1398 |
//Comparator prints to stdout, redirect that to a file |
| 1399 |
PrintStream oldOut = System.out; |
| 1400 |
PrintStream newOut = null; |
| 1401 |
PrintStream oldErr = System.err; |
| 1402 |
PrintStream newErr = null; |
| 1403 |
try { |
| 1404 |
destRepoLocation.mkdir(); |
| 1405 |
newOut = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.out"))); |
| 1406 |
newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err"))); |
| 1407 |
} catch (FileNotFoundException e) { |
| 1408 |
fail("Error redirecting output", e); |
| 1409 |
} |
| 1410 |
System.setOut(newOut); |
| 1411 |
System.setErr(newErr); |
| 1412 |
|
| 1413 |
//run test with verbose, results in error |
| 1414 |
mirrorWithError(true); |
| 1415 |
|
| 1416 |
//verify log |
| 1417 |
try { |
| 1418 |
String[] parts = new String[] {"java.io.FileNotFoundException: ", "helloworld_1.0.0.jar"}; |
| 1419 |
assertLogContainsLine(log.getFile(), parts); |
| 1420 |
} catch (Exception e) { |
| 1421 |
fail("error verifying output", e); |
| 1422 |
} |
| 1423 |
|
| 1424 |
//run with verbose |
| 1425 |
//populate destination with duplicate artifacts. We assume this works |
| 1426 |
runMirrorApplication("Initializing Destiantion", sourceRepoLocation, destRepoLocation, false); //value of append should not matter |
| 1427 |
|
| 1428 |
try { |
| 1429 |
MirrorApplication app = new MirrorApplication(); |
| 1430 |
app.addSource(createRepositoryDescriptor(sourceRepoLocation.toURI(), null, null, null)); |
| 1431 |
app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, null)); |
| 1432 |
//set the arguments with verbose |
| 1433 |
app.setVerbose(true); |
| 1434 |
//run the mirror application |
| 1435 |
app.run(null); |
| 1436 |
} catch (Exception e) { |
| 1437 |
fail("Error running mirror application to generate INFO items", e); |
| 1438 |
} |
| 1439 |
|
| 1440 |
System.setOut(oldOut); |
| 1441 |
newOut.close(); |
| 1442 |
System.setErr(oldErr); |
| 1443 |
newErr.close(); |
| 1444 |
|
| 1445 |
IArtifactRepository sourceRepository = null; |
| 1446 |
try { |
| 1447 |
sourceRepository = getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); |
| 1448 |
} catch (ProvisionException e) { |
| 1449 |
fail("Error loading source repository for verification", e); |
| 1450 |
} |
| 1451 |
|
| 1452 |
try { |
| 1453 |
//Mirroring full duplicate, so any key will do. |
| 1454 |
IArtifactDescriptor[] descriptors = sourceRepository.getArtifactDescriptors(sourceRepository.getArtifactKeys()[0]); |
| 1455 |
//Mirroring full duplicate, so any descriptor will do. |
| 1456 |
String message = NLS.bind(org.eclipse.equinox.internal.p2.artifact.repository.Messages.mirror_alreadyExists, descriptors[0], destRepoLocation.toURI()); |
| 1457 |
assertLogContainsLine(log.getFile(), message); |
| 1458 |
} catch (Exception e) { |
| 1459 |
fail("Error verifying log", e); |
| 1460 |
} |
| 1461 |
} |
| 1462 |
|
| 1463 |
/** |
| 1464 |
* Test how the mirror application handles a repository specified as a local path |
| 1465 |
*/ |
| 1466 |
public void testArtifactMirrorNonURIDest() { |
| 1467 |
try { |
| 1468 |
basicRunMirrorApplication("Mirroring", sourceRepoLocation.toURI(), destRepoLocation.toURI()); |
| 1469 |
assertContentEquals("2.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); |
| 1470 |
} catch (Exception e) { |
| 1471 |
fail("Error mirroring", e); |
| 1472 |
} |
| 1473 |
} |
| 1474 |
} |