View | Details | Raw Unified | Return to bug 248144 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/p2/tests/AutomatedTests.java (+1 lines)
Lines 36-41 Link Here
36
		suite.addTest(org.eclipse.equinox.p2.tests.updatesite.AllTests.suite());
36
		suite.addTest(org.eclipse.equinox.p2.tests.updatesite.AllTests.suite());
37
		suite.addTest(org.eclipse.equinox.p2.tests.extensionlocation.AllTests.suite());
37
		suite.addTest(org.eclipse.equinox.p2.tests.extensionlocation.AllTests.suite());
38
		suite.addTest(org.eclipse.equinox.p2.tests.touchpoint.eclipse.AllTests.suite());
38
		suite.addTest(org.eclipse.equinox.p2.tests.touchpoint.eclipse.AllTests.suite());
39
		suite.addTest(org.eclipse.equinox.p2.tests.mirror.AllTests.suite());
39
		// disable the reconciler tests until after 3.5 M2 and we get the setup issues sorted out
40
		// disable the reconciler tests until after 3.5 M2 and we get the setup issues sorted out
40
		// suite.addTest(org.eclipse.equinox.p2.tests.reconciler.dropins.AllTests.suite());
41
		// suite.addTest(org.eclipse.equinox.p2.tests.reconciler.dropins.AllTests.suite());
41
		return suite;
42
		return suite;
(-)src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java (+79 lines)
Lines 16-21 Link Here
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
17
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
18
import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
18
import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
19
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
20
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
19
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
21
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
20
import org.eclipse.equinox.internal.provisional.p2.director.*;
22
import org.eclipse.equinox.internal.provisional.p2.director.*;
21
import org.eclipse.equinox.internal.provisional.p2.engine.*;
23
import org.eclipse.equinox.internal.provisional.p2.engine.*;
Lines 924-927 Link Here
924
		if (set.size() > 0)
926
		if (set.size() > 0)
925
			fail("Unexpected element '" + set.iterator().next() + "'");
927
			fail("Unexpected element '" + set.iterator().next() + "'");
926
	}
928
	}
929
930
	protected static void assertEquals(Copyright cpyrt1, Copyright cpyrt2) {
931
		if (cpyrt1 == cpyrt2)
932
			return;
933
		if (cpyrt1 == null || cpyrt2 == null) {
934
			fail();
935
		}
936
937
		assertEquals(cpyrt1.getBody(), cpyrt2.getBody());
938
		assertEquals(cpyrt1.getURL().toExternalForm(), cpyrt2.getURL().toExternalForm());
939
	}
940
941
	/**
942
	 * matches all descriptors from source in the destination
943
	 * Note: NOT BICONDITIONAL! assertContains(A, B) is NOT the same as assertContains(B, A)
944
	 */
945
	protected void assertContains(String message, IArtifactRepository sourceRepo, IArtifactRepository destinationRepo) {
946
		IArtifactKey[] sourceKeys = sourceRepo.getArtifactKeys();
947
948
		for (int i = 0; i < sourceKeys.length; i++) {
949
			IArtifactDescriptor[] destinationDescriptors = destinationRepo.getArtifactDescriptors(sourceKeys[i]);
950
			if (destinationDescriptors == null || destinationDescriptors.length == 0)
951
				fail(message + ": unmatched key: " + sourceKeys[i].toString());
952
			//this implicitly verifies the keys are present
953
954
			IArtifactDescriptor[] sourceDescriptors = sourceRepo.getArtifactDescriptors(sourceKeys[i]);
955
			assertEquals(message, sourceDescriptors, destinationDescriptors);
956
		}
957
	}
958
959
	/**
960
	 * Ensures 2 repositories are equal by ensure all items in repo1 are contained
961
	 * in repo2 and all items in repo2 are in repo1
962
	 */
963
	protected void assertContentEquals(String message, IArtifactRepository repo1, IArtifactRepository repo2) {
964
		assertContains(message, repo1, repo2);
965
		assertContains(message, repo2, repo1);
966
	}
967
968
	/**
969
	 * matches all metadata from source in the destination
970
	 * Note: NOT BICONDITIONAL! assertContains(A, B) is NOT the same as assertContains(B, A)
971
	 */
972
	protected void assertContains(String message, IMetadataRepository sourceRepo, IMetadataRepository destinationRepo) {
973
		Collector sourceCollector = sourceRepo.query(InstallableUnitQuery.ANY, new Collector(), null);
974
		Iterator it = sourceCollector.iterator();
975
976
		while (it.hasNext()) {
977
			IInstallableUnit sourceIU = (IInstallableUnit) it.next();
978
			Collector destinationCollector = destinationRepo.query(new InstallableUnitQuery(sourceIU.getId(), sourceIU.getVersion()), new Collector(), null);
979
			if (destinationCollector.size() <= 0)
980
				fail("IU not found.");
981
			if (destinationCollector.size() > 1)
982
				fail("More than one IU found.");
983
984
			assertEquals(sourceIU, (IInstallableUnit) destinationCollector.iterator().next());
985
		}
986
	}
987
988
	/**
989
	 * Ensures 2 repositories are equal by ensure all items in repo1 are contained
990
	 * in repo2 and all items in repo2 are in repo1
991
	 */
992
	protected void assertContentEquals(String message, IMetadataRepository repo1, IMetadataRepository repo2) {
993
		assertContains(message, repo1, repo2);
994
		assertContains(message, repo2, repo1);
995
	}
996
997
	protected static boolean isEqual(IInstallableUnit iu1, IInstallableUnit iu2) {
998
		try {
999
			assertEquals(iu1, iu2);
1000
		} catch (AssertionFailedError e) {
1001
			return false;
1002
		}
1003
1004
		return true;
1005
	}
927
}
1006
}
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 58-64 Link Here
58
 org.eclipse.equinox.frameworkadmin,
58
 org.eclipse.equinox.frameworkadmin,
59
 org.eclipse.equinox.common,
59
 org.eclipse.equinox.common,
60
 org.junit,
60
 org.junit,
61
 org.eclipse.core.runtime;bundle-version="3.4.100"
61
 org.eclipse.core.runtime;bundle-version="3.4",
62
 org.eclipse.equinox.p2.artifact.repository;bundle-version="1.0.100",
63
 org.eclipse.equinox.p2.metadata.repository;bundle-version="1.0.100"
62
Bundle-ActivationPolicy: lazy
64
Bundle-ActivationPolicy: lazy
63
Eclipse-RegisterBuddy: org.eclipse.equinox.p2.artifact.repository
65
Eclipse-RegisterBuddy: org.eclipse.equinox.p2.artifact.repository
64
Bundle-RequiredExecutionEnvironment: J2SE-1.4
66
Bundle-RequiredExecutionEnvironment: J2SE-1.4
(-)src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java (+455 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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
 *     Code 9 - ongoing development
11
 *******************************************************************************/
12
package org.eclipse.equinox.p2.tests.mirror;
13
14
import java.io.File;
15
import java.net.MalformedURLException;
16
import java.util.HashMap;
17
import java.util.Map;
18
import org.eclipse.equinox.app.IApplicationContext;
19
import org.eclipse.equinox.internal.p2.artifact.mirror.MirrorApplication;
20
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
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.p2.tests.AbstractProvisioningTest;
24
import org.eclipse.equinox.p2.tests.TestActivator;
25
import org.osgi.framework.Bundle;
26
27
/**
28
 * Test API of the basic mirror application functionality's implementation.
29
 */
30
public class ArtifactMirrorApplicationTest extends AbstractProvisioningTest {
31
	protected File destRepoLocation;
32
	protected File sourceRepoLocation; //helloworldfeature
33
	protected File sourceRepo2Location; //anotherfeature
34
	protected File sourceRepo3Location; //helloworldfeature + yetanotherfeature
35
	protected IArtifactRepository destRepo;
36
	protected IArtifactRepository srcRepo;
37
	protected IArtifactRepository srcRepo2;
38
	protected IArtifactRepository srcRepo3;
39
40
	private IArtifactRepositoryManager getArtifactRepositoryManager() {
41
		return (IArtifactRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IArtifactRepositoryManager.class.getName());
42
	}
43
44
	protected void setUp() throws Exception {
45
		super.setUp();
46
		String tempDir = System.getProperty("java.io.tmpdir");
47
		sourceRepoLocation = getTestData("1.0", "/testData/mirror/mirrorSourceRepo1");
48
		sourceRepo2Location = getTestData("2.0", "/testData/mirror/mirrorSourceRepo2");
49
		sourceRepo3Location = getTestData("3.0", "/testData/mirror/mirrorSourceRepo3");
50
		destRepoLocation = new File(tempDir, "BasicMirrorApplicationTest");
51
		AbstractProvisioningTest.delete(destRepoLocation);
52
	}
53
54
	protected void tearDown() throws Exception {
55
		removeRepositories();
56
		delete(destRepoLocation);
57
		super.tearDown();
58
	}
59
60
	/**
61
	 * runs default mirror. source is the source repo, destination is the destination repo
62
	 */
63
	private void runMirrorApplication(final File source, final File destination, final boolean append) throws Exception {
64
		MirrorApplication application = new MirrorApplication();
65
		application.start(new IApplicationContext() {
66
67
			public void applicationRunning() {
68
			}
69
70
			public Map getArguments() {
71
				Map arguments = new HashMap();
72
73
				try {
74
					arguments.put("application.args", new String[] {"-source", source.toURL().toExternalForm(), "-destination", destination.toURL().toExternalForm(), append ? "-append" : ""});
75
76
				} catch (MalformedURLException e) {
77
					fail("invalid URL for source or target repo");
78
				}
79
80
				return arguments;
81
			}
82
83
			public String getBrandingApplication() {
84
				return null;
85
			}
86
87
			public Bundle getBrandingBundle() {
88
				return null;
89
			}
90
91
			public String getBrandingDescription() {
92
				return null;
93
			}
94
95
			public String getBrandingId() {
96
				return null;
97
			}
98
99
			public String getBrandingName() {
100
				return null;
101
			}
102
103
			public String getBrandingProperty(String key) {
104
				return null;
105
			}
106
		});
107
	}
108
109
	/**
110
	 * Removes all repositories in one go
111
	 */
112
	private void removeRepositories() throws Exception {
113
		getArtifactRepositoryManager().removeRepository(destRepoLocation.toURL());
114
		getArtifactRepositoryManager().removeRepository(sourceRepoLocation.toURL());
115
		getArtifactRepositoryManager().removeRepository(sourceRepo2Location.toURL());
116
		getArtifactRepositoryManager().removeRepository(sourceRepo3Location.toURL());
117
	}
118
119
	/**
120
	 * Loads all repositories in one go
121
	 * @throws Exception
122
	 */
123
	private void loadRepositories() throws Exception {
124
		destRepo = getArtifactRepositoryManager().loadRepository(destRepoLocation.toURL(), null);
125
		srcRepo = getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null);
126
		srcRepo2 = getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURL(), null);
127
		srcRepo3 = getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURL(), null);
128
	}
129
130
	private void assertNumberOfKeys(int expected, IArtifactRepository repo) {
131
		assertEquals(expected, repo.getArtifactKeys().length);
132
	}
133
134
	/**
135
	 * Tests mirroring all artifacts in a repository to an empty repository
136
	 * @throws Exception 
137
	 * Source contains A, B
138
	 * Target contains
139
	 */
140
	private void artifactMirrorToEmpty(boolean append) throws Exception {
141
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append); //do not append
142
143
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
144
		removeRepositories();
145
146
		loadRepositories();
147
	}
148
149
	/**
150
	 * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries
151
	 * @throws Exception
152
	 * Source contains A, B
153
	 * Target contains C, D
154
	 */
155
	private void artifactMirrorToPopulated(boolean append) throws Exception {
156
		//Setup: populate destination with non-duplicate artifacts
157
		runMirrorApplication(sourceRepo2Location, destRepoLocation, false); //value of append does not matter
158
159
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
160
		removeRepositories();
161
162
		loadRepositories();
163
164
		//Setup ensure setup completes successfully
165
		assertContentEquals("", srcRepo2, destRepo);
166
167
		//mirror test data
168
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
169
170
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
171
		removeRepositories();
172
173
		loadRepositories();
174
	}
175
176
	/**
177
	 * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data
178
	 * @throws Exception
179
	 * Source contains A, B
180
	 * Target contains A, B
181
	 */
182
	private void artifactMirrorToFullDuplicate(boolean append) throws Exception {
183
		//Setup: populate destination with duplicate artifacts
184
		runMirrorApplication(sourceRepoLocation, destRepoLocation, false); //value of append does not matter
185
186
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
187
		removeRepositories();
188
189
		loadRepositories();
190
191
		//Setup: verify contents
192
		assertContentEquals("", srcRepo, destRepo);
193
194
		//mirror test data
195
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
196
197
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
198
		removeRepositories();
199
200
		loadRepositories();
201
	}
202
203
	/**
204
	 * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data
205
	 * @throws Exception 
206
	 * Source contains A, B, C, D
207
	 * Target contains  A, B
208
	 */
209
	private void artifactMirrorToPartialDuplicate(boolean append) throws Exception {
210
		//Setup: populate destination with duplicate artifacts
211
		runMirrorApplication(sourceRepoLocation, destRepoLocation, false); //value of append does not matter
212
213
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
214
		removeRepositories();
215
216
		loadRepositories();
217
218
		//Setup: verify contents
219
		assertContentEquals("", srcRepo, destRepo);
220
221
		//mirror test data
222
		runMirrorApplication(sourceRepo3Location, destRepoLocation, append);
223
224
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
225
		removeRepositories();
226
227
		loadRepositories();
228
	}
229
230
	/**
231
	 * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data
232
	 * @throws Exception 
233
	 * Source contains A, B
234
	 * Target contains A, B, C, D
235
	 */
236
	private void artifactMirrorToPopulatedWithFullDuplicate(boolean append) throws Exception {
237
		//Setup: populate destination with non-duplicate artifacts
238
		runMirrorApplication(sourceRepo3Location, destRepoLocation, false); //value of append does not matter
239
240
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
241
		removeRepositories();
242
243
		loadRepositories();
244
245
		//Setup: verify
246
		assertContentEquals("", srcRepo3, destRepo);
247
248
		//mirror duplicate data
249
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
250
251
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
252
		removeRepositories();
253
254
		loadRepositories();
255
	}
256
257
	/**
258
	 * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data
259
	 * @throws Exception 
260
	 * Source contains A, B, C, D
261
	 * Target contains A, B, E, F
262
	 */
263
	private void artifactMirrorToPopulatedWithPartialDuplicate(boolean append) throws Exception {
264
		//Setup: populate destination with non-duplicate artifacts
265
		runMirrorApplication(sourceRepo2Location, destRepoLocation, false); //value of append does not matter
266
267
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
268
		removeRepositories();
269
270
		loadRepositories();
271
272
		//Setup: verify
273
		assertContentEquals("", srcRepo2, destRepo);
274
275
		//Setup: populate destination with duplicate artifacts
276
		runMirrorApplication(sourceRepoLocation, destRepoLocation, true);
277
278
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
279
		removeRepositories();
280
281
		loadRepositories();
282
283
		//Setup: verify
284
		assertContains("", srcRepo, destRepo);
285
		assertContains("", srcRepo2, destRepo);
286
287
		//mirror duplicate data
288
		runMirrorApplication(sourceRepo3Location, destRepoLocation, append);
289
290
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
291
		removeRepositories();
292
293
		loadRepositories();
294
	}
295
296
	/**
297
	 * Tests mirroring all artifacts in a repository to an empty repository with "-append"
298
	 * @throws Exception 
299
	 * Source contains A, B
300
	 * Target contains
301
	 * Expected is A, B
302
	 */
303
	public void testArtifactMirrorToEmptyWithAppend() throws Exception {
304
		artifactMirrorToEmpty(true);
305
306
		assertContentEquals("", srcRepo, destRepo);
307
	}
308
309
	/**
310
	 * Tests mirroring all artifacts in a repository to an empty repository without "-append"
311
	 * @throws Exception 
312
	 * Source contains A, B
313
	 * Target contains
314
	 * Expected is A, B
315
	 */
316
	public void testArtifactMirrorToEmptyWithoutAppend() throws Exception {
317
		artifactMirrorToEmpty(false);
318
319
		assertContentEquals("", srcRepo, destRepo);
320
	}
321
322
	/**
323
	 * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data with "-append"
324
	 * @throws Exception
325
	 * Source contains A, B
326
	 * Target contains A, B
327
	 * Expected is A, B
328
	 */
329
	public void testArtifactMirrorToFullDuplicateWithAppend() throws Exception {
330
		artifactMirrorToFullDuplicate(true);
331
332
		assertContentEquals("", srcRepo, destRepo);
333
	}
334
335
	/**
336
	 * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data wihtout "-append"
337
	 * @throws Exception
338
	 * Source contains A, B
339
	 * Target contains A, B
340
	 * Expected is A, B
341
	 */
342
	public void testArtifactMirrorToFullDuplicateWithoutAppend() throws Exception {
343
		artifactMirrorToFullDuplicate(false);
344
345
		assertContentEquals("", srcRepo, destRepo);
346
	}
347
348
	/**
349
	 * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries with "-append"
350
	 * @throws Exception
351
	 * Source contains A, B
352
	 * Target contains C, D
353
	 * Expected is A, B, C, D
354
	 */
355
	public void testArtifactMirrorToPopulatedWithAppend() throws Exception {
356
		artifactMirrorToPopulated(true);
357
358
		assertContains("", srcRepo, destRepo);
359
		assertContains("", srcRepo2, destRepo);
360
		assertNumberOfKeys(srcRepo.getArtifactKeys().length + srcRepo2.getArtifactKeys().length, destRepo);
361
	}
362
363
	/**
364
	 * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries without "-append"
365
	 * @throws Exception
366
	 * Source contains A, B
367
	 * Target contains C, D
368
	 * Expected is A, B
369
	 */
370
	public void testArtifactMirrorToPopulatedWithoutAppend() throws Exception {
371
		artifactMirrorToPopulated(false);
372
373
		assertContentEquals("", srcRepo, destRepo);
374
	}
375
376
	/**
377
	 * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data
378
	 * @throws Exception 
379
	 * Source contains A, B, C, D
380
	 * Target contains  A, B
381
	 * Expected is A, B, C, D
382
	 */
383
	public void testArtifactMirrorToPartialDuplicateWithAppend() throws Exception {
384
		artifactMirrorToPartialDuplicate(true);
385
386
		assertContentEquals("", srcRepo3, destRepo);
387
	}
388
389
	/**
390
	 * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data
391
	 * @throws Exception 
392
	 * Source contains A, B, C, D
393
	 * Target contains  A, B
394
	 * Expected is A, B, C, D
395
	 */
396
	public void testArtifactMirrorToPartialDuplicateWithoutAppend() throws Exception {
397
		artifactMirrorToPartialDuplicate(false);
398
399
		assertContentEquals("", srcRepo3, destRepo);
400
	}
401
402
	/**
403
	 * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data with "-append"
404
	 * @throws Exception 
405
	 * Source contains A, B
406
	 * Target contains A, B, C, D
407
	 * Expected is A, B, C, D
408
	 */
409
	public void testArtifactMirrorToPopulatedWithFullDuplicateWithAppend() throws Exception {
410
		artifactMirrorToPopulatedWithFullDuplicate(true);
411
412
		assertContentEquals("", srcRepo3, destRepo);
413
	}
414
415
	/**
416
	 * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data without "-append"
417
	 * @throws Exception 
418
	 * Source contains A, B
419
	 * Target contains A, B, C, D
420
	 * Expected is A, B
421
	 */
422
	public void testArtifactMirrorToPopulatedWithFullDuplicateWithoutAppend() throws Exception {
423
		artifactMirrorToPopulatedWithFullDuplicate(false);
424
425
		assertContentEquals("", srcRepo, destRepo);
426
	}
427
428
	/**
429
	 * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data with "-append"
430
	 * @throws Exception 
431
	 * Source contains A, B, C, D
432
	 * Target contains A, B, E, F
433
	 * Expected is A, B, C, D, E, F
434
	 */
435
	public void testArtifactMirrorToPopulatedWithPartialDuplicateWithAppend() throws Exception {
436
		artifactMirrorToPopulatedWithPartialDuplicate(true);
437
438
		assertContains("", srcRepo3, destRepo);
439
		assertContains("", srcRepo2, destRepo);
440
		assertNumberOfKeys(srcRepo2.getArtifactKeys().length + srcRepo3.getArtifactKeys().length, destRepo);
441
	}
442
443
	/**
444
	 * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data without "-append"
445
	 * @throws Exception 
446
	 * Source contains A, B, C, D
447
	 * Target contains A, B, E, F
448
	 * Expected is A, B, C, D
449
	 */
450
	public void testArtifactMirrorToPopulatedWithPartialDuplicateWithoutAppend() throws Exception {
451
		artifactMirrorToPopulatedWithPartialDuplicate(false);
452
453
		assertContentEquals("", srcRepo3, destRepo);
454
	}
455
}
(-)src/org/eclipse/equinox/p2/tests/mirror/AllTests.java (+27 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 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 junit.framework.*;
14
15
/**
16
 * Performs all automated mirror application 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(ArtifactMirrorApplicationTest.class);
23
		suite.addTestSuite(MetadataMirrorApplicationTest.class);
24
		return suite;
25
	}
26
27
}
(-)src/org/eclipse/equinox/p2/tests/mirror/MetadataMirrorApplicationTest.java (+475 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 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
 *     Code 9 - ongoing development
11
 *******************************************************************************/
12
package org.eclipse.equinox.p2.tests.mirror;
13
14
import java.io.File;
15
import java.net.MalformedURLException;
16
import java.util.HashMap;
17
import java.util.Map;
18
import org.eclipse.equinox.app.IApplicationContext;
19
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
20
import org.eclipse.equinox.internal.p2.metadata.mirror.MirrorApplication;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
25
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
26
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
27
import org.eclipse.equinox.p2.tests.TestActivator;
28
import org.osgi.framework.Bundle;
29
30
/**
31
 * Test API of the basic mirror application functionality's implementation.
32
 */
33
public class MetadataMirrorApplicationTest extends AbstractProvisioningTest {
34
	protected File destRepoLocation;
35
	protected File sourceRepoLocation; //helloworldfeature
36
	protected File sourceRepo2Location; //anotherfeature
37
	protected File sourceRepo3Location; //helloworldfeature + yetanotherfeature
38
	protected IMetadataRepository destRepo;
39
	protected IMetadataRepository srcRepo;
40
	protected IMetadataRepository srcRepo2;
41
	protected IMetadataRepository srcRepo3;
42
43
	private IMetadataRepositoryManager getMetadataRepositoryManager() {
44
		return (IMetadataRepositoryManager) ServiceHelper.getService(TestActivator.getContext(), IMetadataRepositoryManager.class.getName());
45
	}
46
47
	protected void setUp() throws Exception {
48
		super.setUp();
49
		String tempDir = System.getProperty("java.io.tmpdir");
50
		sourceRepoLocation = getTestData("1.0", "/testData/mirror/mirrorSourceRepo1");
51
		sourceRepo2Location = getTestData("2.0", "/testData/mirror/mirrorSourceRepo2");
52
		sourceRepo3Location = getTestData("3.0", "/testData/mirror/mirrorSourceRepo3");
53
		destRepoLocation = new File(tempDir, "BasicMirrorApplicationTest");
54
		AbstractProvisioningTest.delete(destRepoLocation);
55
	}
56
57
	protected void tearDown() throws Exception {
58
		removeRepositories();
59
		delete(destRepoLocation);
60
		super.tearDown();
61
	}
62
63
	/**
64
	 * runs default mirror. source is the source repo, destination is the destination repo
65
	 */
66
	private void runMirrorApplication(final File source, final File destination, final boolean append) throws Exception {
67
		MirrorApplication application = new MirrorApplication();
68
		application.start(new IApplicationContext() {
69
70
			public void applicationRunning() {
71
			}
72
73
			public Map getArguments() {
74
				Map arguments = new HashMap();
75
76
				try {
77
					arguments.put("application.args", new String[] {"-source", source.toURL().toExternalForm(), "-destination", destination.toURL().toExternalForm(), append ? "-append" : ""});
78
79
				} catch (MalformedURLException e) {
80
					fail("invalid URL for source or target repo");
81
				}
82
83
				return arguments;
84
			}
85
86
			public String getBrandingApplication() {
87
				return null;
88
			}
89
90
			public Bundle getBrandingBundle() {
91
				return null;
92
			}
93
94
			public String getBrandingDescription() {
95
				return null;
96
			}
97
98
			public String getBrandingId() {
99
				return null;
100
			}
101
102
			public String getBrandingName() {
103
				return null;
104
			}
105
106
			public String getBrandingProperty(String key) {
107
				return null;
108
			}
109
		});
110
	}
111
112
	/**
113
	 * Removes all repositories in one go
114
	 */
115
	private void removeRepositories() throws Exception {
116
		getMetadataRepositoryManager().removeRepository(destRepoLocation.toURL());
117
		getMetadataRepositoryManager().removeRepository(sourceRepoLocation.toURL());
118
		getMetadataRepositoryManager().removeRepository(sourceRepo2Location.toURL());
119
		getMetadataRepositoryManager().removeRepository(sourceRepo3Location.toURL());
120
	}
121
122
	/**
123
	 * Loads all repositories in one go
124
	 * @throws Exception
125
	 */
126
	private void loadRepositories() throws Exception {
127
		destRepo = getMetadataRepositoryManager().loadRepository(destRepoLocation.toURL(), null);
128
		srcRepo = getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURL(), null);
129
		srcRepo2 = getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURL(), null);
130
		srcRepo3 = getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURL(), null);
131
	}
132
133
	private int getNumUnique(Collector c1, Collector c2) {
134
		Object[] repo1 = c1.toCollection().toArray();
135
		Object[] repo2 = c2.toCollection().toArray();
136
137
		int numKeys = repo1.length + repo2.length;
138
139
		for (int i = 0; i < repo1.length; i++) {
140
			for (int j = 0; j < repo2.length; j++) {
141
				if (isEqual((IInstallableUnit) repo1[i], (IInstallableUnit) repo2[j]))
142
					numKeys--;
143
			}
144
		}
145
146
		return numKeys;
147
	}
148
149
	private void assertNumberOfKeys(int expected, IMetadataRepository repo) {
150
		assertEquals(expected, repo.query(InstallableUnitQuery.ANY, new Collector(), null).size());
151
	}
152
153
	/**
154
	 * Tests mirroring all metadata in a repository to an empty repository
155
	 * @throws Exception 
156
	 * Source contains A, B
157
	 * Target contains
158
	 */
159
	private void metadataMirrorToEmpty(boolean append) throws Exception {
160
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append); //do not append
161
162
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
163
		removeRepositories();
164
165
		loadRepositories();
166
	}
167
168
	/**
169
	 * Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries
170
	 * @throws Exception
171
	 * Source contains A, B
172
	 * Target contains C, D
173
	 */
174
	private void metadataMirrorToPopulated(boolean append) throws Exception {
175
		//Setup: populate destination with non-duplicate metadata
176
		runMirrorApplication(sourceRepo2Location, destRepoLocation, false); //value of append does not matter
177
178
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
179
		removeRepositories();
180
181
		loadRepositories();
182
183
		//Setup ensure setup completes successfully
184
		assertContentEquals("", srcRepo2, destRepo);
185
186
		//mirror test data
187
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
188
189
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
190
		removeRepositories();
191
192
		loadRepositories();
193
	}
194
195
	/**
196
	 * Tests mirroring all metadata in a repository to a repository populated with exact duplicate data
197
	 * @throws Exception
198
	 * Source contains A, B
199
	 * Target contains A, B
200
	 */
201
	private void metadataMirrorToFullDuplicate(boolean append) throws Exception {
202
		//Setup: populate destination with duplicate metadata
203
		runMirrorApplication(sourceRepoLocation, destRepoLocation, false); //value of append does not matter
204
205
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
206
		removeRepositories();
207
208
		loadRepositories();
209
210
		//Setup: verify contents
211
		assertContentEquals("", srcRepo, destRepo);
212
213
		//mirror test data
214
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
215
216
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
217
		removeRepositories();
218
219
		loadRepositories();
220
	}
221
222
	/**
223
	 * Tests mirroring all metadata in a repository to a repository populated with partially duplicate data
224
	 * @throws Exception 
225
	 * Source contains A, B, C, D
226
	 * Target contains  A, B
227
	 */
228
	private void metadataMirrorToPartialDuplicate(boolean append) throws Exception {
229
		//Setup: populate destination with duplicate metadata
230
		runMirrorApplication(sourceRepoLocation, destRepoLocation, false); //value of append does not matter
231
232
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
233
		removeRepositories();
234
235
		loadRepositories();
236
237
		//Setup: verify contents
238
		assertContentEquals("", srcRepo, destRepo);
239
240
		//mirror test data
241
		runMirrorApplication(sourceRepo3Location, destRepoLocation, append);
242
243
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
244
		removeRepositories();
245
246
		loadRepositories();
247
	}
248
249
	/**
250
	 * Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data
251
	 * @throws Exception 
252
	 * Source contains A, B
253
	 * Target contains A, B, C, D
254
	 */
255
	private void metadataMirrorToPopulatedWithFullDuplicate(boolean append) throws Exception {
256
		//Setup: populate destination with non-duplicate metadata
257
		runMirrorApplication(sourceRepo3Location, destRepoLocation, false); //value of append does not matter
258
259
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
260
		removeRepositories();
261
262
		loadRepositories();
263
264
		//Setup: verify
265
		assertContentEquals("", srcRepo3, destRepo);
266
267
		//mirror duplicate data
268
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
269
270
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
271
		removeRepositories();
272
273
		loadRepositories();
274
	}
275
276
	/**
277
	 * Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data
278
	 * @throws Exception 
279
	 * Source contains A, B, C, D
280
	 * Target contains A, B, E, F
281
	 */
282
	private void metadataMirrorToPopulatedWithPartialDuplicate(boolean append) throws Exception {
283
		//Setup: populate destination with non-duplicate metadata
284
		runMirrorApplication(sourceRepo2Location, destRepoLocation, false); //value of append does not matter
285
286
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
287
		removeRepositories();
288
289
		loadRepositories();
290
291
		//Setup: verify
292
		assertContentEquals("", srcRepo2, destRepo);
293
294
		//Setup: populate destination with duplicate metadata
295
		runMirrorApplication(sourceRepoLocation, destRepoLocation, true);
296
297
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
298
		removeRepositories();
299
300
		loadRepositories();
301
302
		//Setup: verify
303
		assertContains("", srcRepo, destRepo);
304
		assertContains("", srcRepo2, destRepo);
305
306
		//mirror duplicate data
307
		runMirrorApplication(sourceRepo3Location, destRepoLocation, append);
308
309
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
310
		removeRepositories();
311
312
		loadRepositories();
313
	}
314
315
	/**
316
	 * Tests mirroring all metadata in a repository to an empty repository with "-append"
317
	 * @throws Exception 
318
	 * Source contains A, B
319
	 * Target contains
320
	 * Expected is A, B
321
	 */
322
	public void testMetadataMirrorToEmptyWithAppend() throws Exception {
323
		metadataMirrorToEmpty(true);
324
325
		assertContentEquals("", srcRepo, destRepo);
326
	}
327
328
	/**
329
	 * Tests mirroring all metadata in a repository to an empty repository without "-append"
330
	 * @throws Exception 
331
	 * Source contains A, B
332
	 * Target contains
333
	 * Expected is A, B
334
	 */
335
	public void testMetadataMirrorToEmptyWithoutAppend() throws Exception {
336
		metadataMirrorToEmpty(false);
337
338
		assertContentEquals("", srcRepo, destRepo);
339
	}
340
341
	/**
342
	 * Tests mirroring all metadata in a repository to a repository populated with exact duplicate data with "-append"
343
	 * @throws Exception
344
	 * Source contains A, B
345
	 * Target contains A, B
346
	 * Expected is A, B
347
	 */
348
	public void testMetadataMirrorToFullDuplicateWithAppend() throws Exception {
349
		metadataMirrorToFullDuplicate(true);
350
351
		assertContentEquals("", srcRepo, destRepo);
352
	}
353
354
	/**
355
	 * Tests mirroring all metadata in a repository to a repository populated with exact duplicate data wihtout "-append"
356
	 * @throws Exception
357
	 * Source contains A, B
358
	 * Target contains A, B
359
	 * Expected is A, B
360
	 */
361
	public void testMetadataMirrorToFullDuplicateWithoutAppend() throws Exception {
362
		metadataMirrorToFullDuplicate(false);
363
364
		assertContentEquals("", srcRepo, destRepo);
365
	}
366
367
	/**
368
	 * Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries with "-append"
369
	 * @throws Exception
370
	 * Source contains A, B
371
	 * Target contains C, D
372
	 * Expected is A, B, C, D
373
	 */
374
	public void testMetadataMirrorToPopulatedWithAppend() throws Exception {
375
		metadataMirrorToPopulated(true);
376
377
		assertContains("", srcRepo, destRepo);
378
		assertContains("", srcRepo2, destRepo);
379
		assertNumberOfKeys(getNumUnique(srcRepo.query(InstallableUnitQuery.ANY, new Collector(), null), srcRepo2.query(InstallableUnitQuery.ANY, new Collector(), null)), destRepo);
380
	}
381
382
	/**
383
	 * Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries without "-append"
384
	 * @throws Exception
385
	 * Source contains A, B
386
	 * Target contains C, D
387
	 * Expected is A, B
388
	 */
389
	public void testMetadataMirrorToPopulatedWithoutAppend() throws Exception {
390
		metadataMirrorToPopulated(false);
391
392
		assertContentEquals("", srcRepo, destRepo);
393
	}
394
395
	/**
396
	 * Tests mirroring all metadata in a repository to a repository populated with partially duplicate data
397
	 * @throws Exception 
398
	 * Source contains A, B, C, D
399
	 * Target contains  A, B
400
	 * Expected is A, B, C, D
401
	 */
402
	public void testMetadataMirrorToPartialDuplicateWithAppend() throws Exception {
403
		metadataMirrorToPartialDuplicate(true);
404
405
		assertContentEquals("", srcRepo3, destRepo);
406
	}
407
408
	/**
409
	 * Tests mirroring all metadata in a repository to a repository populated with partially duplicate data
410
	 * @throws Exception 
411
	 * Source contains A, B, C, D
412
	 * Target contains  A, B
413
	 * Expected is A, B, C, D
414
	 */
415
	public void testMetadataMirrorToPartialDuplicateWithoutAppend() throws Exception {
416
		metadataMirrorToPartialDuplicate(false);
417
418
		assertContentEquals("", srcRepo3, destRepo);
419
	}
420
421
	/**
422
	 * Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data with "-append"
423
	 * @throws Exception 
424
	 * Source contains A, B
425
	 * Target contains A, B, C, D
426
	 * Expected is A, B, C, D
427
	 */
428
	public void testMetadataMirrorToPopulatedWithFullDuplicateWithAppend() throws Exception {
429
		metadataMirrorToPopulatedWithFullDuplicate(true);
430
431
		assertContentEquals("", srcRepo3, destRepo);
432
	}
433
434
	/**
435
	 * Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data without "-append"
436
	 * @throws Exception 
437
	 * Source contains A, B
438
	 * Target contains A, B, C, D
439
	 * Expected is A, B
440
	 */
441
	public void testMetadataMirrorToPopulatedWithFullDuplicateWithoutAppend() throws Exception {
442
		metadataMirrorToPopulatedWithFullDuplicate(false);
443
444
		assertContentEquals("", srcRepo, destRepo);
445
	}
446
447
	/**
448
	 * Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data with "-append"
449
	 * @throws Exception 
450
	 * Source contains A, B, C, D
451
	 * Target contains A, B, E, F
452
	 * Expected is A, B, C, D, E, F
453
	 */
454
	public void testMetadataMirrorToPopulatedWithPartialDuplicateWithAppend() throws Exception {
455
		metadataMirrorToPopulatedWithPartialDuplicate(true);
456
457
		assertContains("", srcRepo3, destRepo);
458
		assertContains("", srcRepo2, destRepo);
459
		assertNumberOfKeys(getNumUnique(srcRepo2.query(InstallableUnitQuery.ANY, new Collector(), null), srcRepo3.query(InstallableUnitQuery.ANY, new Collector(), null)), destRepo);
460
	}
461
462
	/**
463
	 * Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data without "-append"
464
	 * @throws Exception 
465
	 * Source contains A, B, C, D
466
	 * Target contains A, B, E, F
467
	 * Expected is A, B, C, D
468
	 */
469
	public void testMetadataMirrorToPopulatedWithPartialDuplicateWithoutAppend() throws Exception {
470
		metadataMirrorToPopulatedWithPartialDuplicate(false);
471
472
		assertContentEquals("", srcRepo3, destRepo);
473
	}
474
475
}

Return to bug 248144