Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 265550 | Differences between
and this patch

Collapse All | Expand All

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

Return to bug 265550