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

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 5-11 Link Here
5
Bundle-Vendor: %providerName
5
Bundle-Vendor: %providerName
6
Bundle-Localization: plugin
6
Bundle-Localization: plugin
7
Bundle-Version: 1.0.100.qualifier
7
Bundle-Version: 1.0.100.qualifier
8
Export-Package: org.eclipse.equinox.internal.p2.metadata.repository;
8
Export-Package: org.eclipse.equinox.internal.p2.metadata.mirror,
9
 org.eclipse.equinox.internal.p2.metadata.repository;
9
  x-friends:="org.eclipse.equinox.p2.engine,
10
  x-friends:="org.eclipse.equinox.p2.engine,
10
   org.eclipse.equinox.p2.metadata.generator,
11
   org.eclipse.equinox.p2.metadata.generator,
11
   org.eclipse.equinox.p2.reconciler.dropins,
12
   org.eclipse.equinox.p2.reconciler.dropins,
(-)src/org/eclipse/equinox/internal/p2/metadata/mirror/MirrorApplication.java (+5 lines)
Lines 31-36 Link Here
31
	private IMetadataRepository source;
31
	private IMetadataRepository source;
32
	private IMetadataRepository destination;
32
	private IMetadataRepository destination;
33
	private boolean transitive = false;
33
	private boolean transitive = false;
34
	private boolean append = false;
34
35
35
	/**
36
	/**
36
	 * Convert a list of tokens into an array. The list separator has to be
37
	 * Convert a list of tokens into an array. The list separator has to be
Lines 71-76 Link Here
71
			IMetadataRepository repository = repoManager.loadRepository(destinationLocation, null);
72
			IMetadataRepository repository = repoManager.loadRepository(destinationLocation, null);
72
			if (!repository.isModifiable())
73
			if (!repository.isModifiable())
73
				throw new IllegalArgumentException("Metadata repository not modifiable: " + destinationLocation); //$NON-NLS-1$
74
				throw new IllegalArgumentException("Metadata repository not modifiable: " + destinationLocation); //$NON-NLS-1$
75
			if (!append)
76
				repository.removeAll();
74
			return repository;
77
			return repository;
75
		} catch (ProvisionException e) {
78
		} catch (ProvisionException e) {
76
			//fall through and create repo
79
			//fall through and create repo
Lines 87-92 Link Here
87
		if (args == null)
90
		if (args == null)
88
			return;
91
			return;
89
		for (int i = 0; i < args.length; i++) {
92
		for (int i = 0; i < args.length; i++) {
93
			if (args[i].equalsIgnoreCase("-append"))
94
				append = true;
90
			// check for args with parameters. If we are at the last argument or 
95
			// check for args with parameters. If we are at the last argument or 
91
			// if the next one has a '-' as the first character, then we can't have 
96
			// if the next one has a '-' as the first character, then we can't have 
92
			// an arg with a param so continue.
97
			// an arg with a param so continue.
(-)src/org/eclipse/equinox/p2/tests/AutomatedTests.java (+1 lines)
Lines 39-44 Link Here
39
		suite.addTest(org.eclipse.equinox.p2.tests.simpleconfigurator.SimpleConfiguratorTests.suite());
39
		suite.addTest(org.eclipse.equinox.p2.tests.simpleconfigurator.SimpleConfiguratorTests.suite());
40
		suite.addTest(org.eclipse.equinox.p2.tests.updatesite.AllTests.suite());
40
		suite.addTest(org.eclipse.equinox.p2.tests.updatesite.AllTests.suite());
41
		suite.addTest(org.eclipse.equinox.p2.tests.touchpoint.eclipse.AllTests.suite());
41
		suite.addTest(org.eclipse.equinox.p2.tests.touchpoint.eclipse.AllTests.suite());
42
		suite.addTest(org.eclipse.equinox.p2.tests.mirror.AllTests.suite());
42
		suite.addTest(org.eclipse.equinox.p2.tests.full.AllTests.suite());
43
		suite.addTest(org.eclipse.equinox.p2.tests.full.AllTests.suite());
43
		// disable the reconciler tests until after 3.5 M2 and we get the setup issues sorted out
44
		// disable the reconciler tests until after 3.5 M2 and we get the setup issues sorted out
44
		// suite.addTest(org.eclipse.equinox.p2.tests.reconciler.dropins.AllTests.suite());
45
		// suite.addTest(org.eclipse.equinox.p2.tests.reconciler.dropins.AllTests.suite());
(-)src/org/eclipse/equinox/p2/tests/AbstractProvisioningTest.java (-2 / +77 lines)
Lines 17-24 Link Here
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.core.helpers.URLUtil;
18
import org.eclipse.equinox.internal.p2.core.helpers.URLUtil;
19
import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
19
import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
20
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
20
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*;
21
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
22
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
21
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
23
import org.eclipse.equinox.internal.provisional.p2.director.*;
22
import org.eclipse.equinox.internal.provisional.p2.director.*;
24
import org.eclipse.equinox.internal.provisional.p2.engine.*;
23
import org.eclipse.equinox.internal.provisional.p2.engine.*;
Lines 1007-1010 Link Here
1007
		if (set.size() > 0)
1006
		if (set.size() > 0)
1008
			fail("Unexpected element '" + set.iterator().next() + "'");
1007
			fail("Unexpected element '" + set.iterator().next() + "'");
1009
	}
1008
	}
1009
1010
	/*
1011
	 * Compare 2 copyright objects and fail if they are not considered equal.
1012
	 */
1013
	protected static void assertEquals(String message, Copyright cpyrt1, Copyright cpyrt2) {
1014
		if (cpyrt1 == cpyrt2)
1015
			return;
1016
		if (cpyrt1 == null || cpyrt2 == null) {
1017
			fail();
1018
		}
1019
1020
		assertEquals(message, cpyrt1.getBody(), cpyrt2.getBody());
1021
		assertEquals(message, cpyrt1.getURL().toExternalForm(), cpyrt2.getURL().toExternalForm());
1022
	}
1023
1024
	/**
1025
	 * matches all descriptors from source in the destination
1026
	 * Note: NOT BICONDITIONAL! assertContains(A, B) is NOT the same as assertContains(B, A)
1027
	 */
1028
	protected void assertContains(String message, IArtifactRepository sourceRepo, IArtifactRepository destinationRepo) {
1029
		IArtifactKey[] sourceKeys = sourceRepo.getArtifactKeys();
1030
1031
		for (int i = 0; i < sourceKeys.length; i++) {
1032
			IArtifactDescriptor[] destinationDescriptors = destinationRepo.getArtifactDescriptors(sourceKeys[i]);
1033
			if (destinationDescriptors == null || destinationDescriptors.length == 0)
1034
				fail(message + ": unmatched key: " + sourceKeys[i].toString());
1035
			//this implicitly verifies the keys are present
1036
1037
			IArtifactDescriptor[] sourceDescriptors = sourceRepo.getArtifactDescriptors(sourceKeys[i]);
1038
			assertEquals(message, sourceDescriptors, destinationDescriptors);
1039
		}
1040
	}
1041
1042
	/**
1043
	 * Ensures 2 repositories are equal by ensure all items in repo1 are contained
1044
	 * in repo2 and all items in repo2 are in repo1
1045
	 */
1046
	protected void assertContentEquals(String message, IArtifactRepository repo1, IArtifactRepository repo2) {
1047
		assertContains(message, repo1, repo2);
1048
		assertContains(message, repo2, repo1);
1049
	}
1050
1051
	/**
1052
	 * matches all metadata from source in the destination
1053
	 * Note: NOT BICONDITIONAL! assertContains(A, B) is NOT the same as assertContains(B, A)
1054
	 */
1055
	protected void assertContains(String message, IMetadataRepository sourceRepo, IMetadataRepository destinationRepo) {
1056
		Collector sourceCollector = sourceRepo.query(InstallableUnitQuery.ANY, new Collector(), null);
1057
		Iterator it = sourceCollector.iterator();
1058
1059
		while (it.hasNext()) {
1060
			IInstallableUnit sourceIU = (IInstallableUnit) it.next();
1061
			Collector destinationCollector = destinationRepo.query(new InstallableUnitQuery(sourceIU.getId(), sourceIU.getVersion()), new Collector(), null);
1062
			assertEquals(message, 1, destinationCollector.size());
1063
			assertEquals(sourceIU, (IInstallableUnit) destinationCollector.iterator().next());
1064
		}
1065
	}
1066
1067
	/**
1068
	 * Ensures 2 repositories are equal by ensure all items in repo1 are contained
1069
	 * in repo2 and all items in repo2 are in repo1
1070
	 */
1071
	protected void assertContentEquals(String message, IMetadataRepository repo1, IMetadataRepository repo2) {
1072
		assertContains(message, repo1, repo2);
1073
		assertContains(message, repo2, repo1);
1074
	}
1075
1076
	protected static boolean isEqual(IInstallableUnit iu1, IInstallableUnit iu2) {
1077
		try {
1078
			assertEquals(iu1, iu2);
1079
		} catch (AssertionFailedError e) {
1080
			return false;
1081
		}
1082
1083
		return true;
1084
	}
1010
}
1085
}
(-)META-INF/MANIFEST.MF (+2 lines)
Lines 60-65 Link Here
60
 org.eclipse.equinox.common,
60
 org.eclipse.equinox.common,
61
 org.junit,
61
 org.junit,
62
 org.eclipse.core.runtime;bundle-version="3.4.0",
62
 org.eclipse.core.runtime;bundle-version="3.4.0",
63
 org.eclipse.equinox.p2.artifact.repository;bundle-version="1.0.100",
64
 org.eclipse.equinox.p2.metadata.repository;bundle-version="1.0.100",
63
 org.sat4j.core;bundle-version="2.0.0",
65
 org.sat4j.core;bundle-version="2.0.0",
64
 org.sat4j.pb;bundle-version="2.0.0"
66
 org.sat4j.pb;bundle-version="2.0.0"
65
Bundle-ActivationPolicy: lazy
67
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/equinox/p2/tests/mirror/ArtifactMirrorApplicationTest.java (+452 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
	/**
131
	 * Tests mirroring all artifacts in a repository to an empty repository
132
	 * @throws Exception 
133
	 * Source contains A, B
134
	 * Target contains
135
	 */
136
	private void artifactMirrorToEmpty(boolean append) throws Exception {
137
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append); //do not append
138
139
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
140
		removeRepositories();
141
142
		loadRepositories();
143
	}
144
145
	/**
146
	 * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries
147
	 * @throws Exception
148
	 * Source contains A, B
149
	 * Target contains C, D
150
	 */
151
	private void artifactMirrorToPopulated(boolean append) throws Exception {
152
		//Setup: populate destination with non-duplicate artifacts
153
		runMirrorApplication(sourceRepo2Location, destRepoLocation, false); //value of append does not matter
154
155
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
156
		removeRepositories();
157
158
		loadRepositories();
159
160
		//Setup ensure setup completes successfully
161
		assertContentEquals("", srcRepo2, destRepo);
162
163
		//mirror test data
164
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
165
166
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
167
		removeRepositories();
168
169
		loadRepositories();
170
	}
171
172
	/**
173
	 * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data
174
	 * @throws Exception
175
	 * Source contains A, B
176
	 * Target contains A, B
177
	 */
178
	private void artifactMirrorToFullDuplicate(boolean append) throws Exception {
179
		//Setup: populate destination with duplicate artifacts
180
		runMirrorApplication(sourceRepoLocation, destRepoLocation, false); //value of append does not matter
181
182
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
183
		removeRepositories();
184
185
		loadRepositories();
186
187
		//Setup: verify contents
188
		assertContentEquals("", srcRepo, destRepo);
189
190
		//mirror test data
191
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
192
193
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
194
		removeRepositories();
195
196
		loadRepositories();
197
	}
198
199
	/**
200
	 * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data
201
	 * @throws Exception 
202
	 * Source contains A, B, C, D
203
	 * Target contains  A, B
204
	 */
205
	private void artifactMirrorToPartialDuplicate(boolean append) throws Exception {
206
		//Setup: populate destination with duplicate artifacts
207
		runMirrorApplication(sourceRepoLocation, destRepoLocation, false); //value of append does not matter
208
209
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
210
		removeRepositories();
211
212
		loadRepositories();
213
214
		//Setup: verify contents
215
		assertContentEquals("", srcRepo, destRepo);
216
217
		//mirror test data
218
		runMirrorApplication(sourceRepo3Location, destRepoLocation, append);
219
220
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
221
		removeRepositories();
222
223
		loadRepositories();
224
	}
225
226
	/**
227
	 * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data
228
	 * @throws Exception 
229
	 * Source contains A, B
230
	 * Target contains A, B, C, D
231
	 */
232
	private void artifactMirrorToPopulatedWithFullDuplicate(boolean append) throws Exception {
233
		//Setup: populate destination with non-duplicate artifacts
234
		runMirrorApplication(sourceRepo3Location, destRepoLocation, false); //value of append does not matter
235
236
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
237
		removeRepositories();
238
239
		loadRepositories();
240
241
		//Setup: verify
242
		assertContentEquals("", srcRepo3, destRepo);
243
244
		//mirror duplicate data
245
		runMirrorApplication(sourceRepoLocation, destRepoLocation, append);
246
247
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
248
		removeRepositories();
249
250
		loadRepositories();
251
	}
252
253
	/**
254
	 * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data
255
	 * @throws Exception 
256
	 * Source contains A, B, C, D
257
	 * Target contains A, B, E, F
258
	 */
259
	private void artifactMirrorToPopulatedWithPartialDuplicate(boolean append) throws Exception {
260
		//Setup: populate destination with non-duplicate artifacts
261
		runMirrorApplication(sourceRepo2Location, destRepoLocation, false); //value of append does not matter
262
263
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
264
		removeRepositories();
265
266
		loadRepositories();
267
268
		//Setup: verify
269
		assertContentEquals("", srcRepo2, destRepo);
270
271
		//Setup: populate destination with duplicate artifacts
272
		runMirrorApplication(sourceRepoLocation, destRepoLocation, true);
273
274
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
275
		removeRepositories();
276
277
		loadRepositories();
278
279
		//Setup: verify
280
		assertContains("", srcRepo, destRepo);
281
		assertContains("", srcRepo2, destRepo);
282
283
		//mirror duplicate data
284
		runMirrorApplication(sourceRepo3Location, destRepoLocation, append);
285
286
		//TODO replace with test to ensure repositories are closed once bug 247664 is fixed
287
		removeRepositories();
288
289
		loadRepositories();
290
	}
291
292
	/**
293
	 * Tests mirroring all artifacts in a repository to an empty repository with "-append"
294
	 * @throws Exception 
295
	 * Source contains A, B
296
	 * Target contains
297
	 * Expected is A, B
298
	 */
299
	public void testArtifactMirrorToEmptyWithAppend() throws Exception {
300
		artifactMirrorToEmpty(true);
301
302
		destRepo = getArtifactRepositoryManager().loadRepository(destRepoLocation.toURL(), null);
303
		assertContentEquals("", srcRepo, destRepo);
304
	}
305
306
	/**
307
	 * Tests mirroring all artifacts in a repository to an empty repository without "-append"
308
	 * @throws Exception 
309
	 * Source contains A, B
310
	 * Target contains
311
	 * Expected is A, B
312
	 */
313
	public void testArtifactMirrorToEmptyWithoutAppend() throws Exception {
314
		artifactMirrorToEmpty(false);
315
316
		assertContentEquals("", srcRepo, destRepo);
317
	}
318
319
	/**
320
	 * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data with "-append"
321
	 * @throws Exception
322
	 * Source contains A, B
323
	 * Target contains A, B
324
	 * Expected is A, B
325
	 */
326
	public void testArtifactMirrorToFullDuplicateWithAppend() throws Exception {
327
		artifactMirrorToFullDuplicate(true);
328
329
		assertContentEquals("", srcRepo, destRepo);
330
	}
331
332
	/**
333
	 * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data wihtout "-append"
334
	 * @throws Exception
335
	 * Source contains A, B
336
	 * Target contains A, B
337
	 * Expected is A, B
338
	 */
339
	public void testArtifactMirrorToFullDuplicateWithoutAppend() throws Exception {
340
		artifactMirrorToFullDuplicate(false);
341
342
		assertContentEquals("", srcRepo, destRepo);
343
	}
344
345
	/**
346
	 * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries with "-append"
347
	 * @throws Exception
348
	 * Source contains A, B
349
	 * Target contains C, D
350
	 * Expected is A, B, C, D
351
	 */
352
	public void testArtifactMirrorToPopulatedWithAppend() throws Exception {
353
		artifactMirrorToPopulated(true);
354
355
		assertContains("", srcRepo, destRepo);
356
		assertContains("", srcRepo2, destRepo);
357
		assertEquals(srcRepo.getArtifactKeys().length + srcRepo2.getArtifactKeys().length, destRepo.getArtifactKeys().length);
358
	}
359
360
	/**
361
	 * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries without "-append"
362
	 * @throws Exception
363
	 * Source contains A, B
364
	 * Target contains C, D
365
	 * Expected is A, B
366
	 */
367
	public void testArtifactMirrorToPopulatedWithoutAppend() throws Exception {
368
		artifactMirrorToPopulated(false);
369
370
		assertContentEquals("", srcRepo, destRepo);
371
	}
372
373
	/**
374
	 * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data
375
	 * @throws Exception 
376
	 * Source contains A, B, C, D
377
	 * Target contains  A, B
378
	 * Expected is A, B, C, D
379
	 */
380
	public void testArtifactMirrorToPartialDuplicateWithAppend() throws Exception {
381
		artifactMirrorToPartialDuplicate(true);
382
383
		assertContentEquals("", srcRepo3, destRepo);
384
	}
385
386
	/**
387
	 * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data
388
	 * @throws Exception 
389
	 * Source contains A, B, C, D
390
	 * Target contains  A, B
391
	 * Expected is A, B, C, D
392
	 */
393
	public void testArtifactMirrorToPartialDuplicateWithoutAppend() throws Exception {
394
		artifactMirrorToPartialDuplicate(false);
395
396
		assertContentEquals("", srcRepo3, destRepo);
397
	}
398
399
	/**
400
	 * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data with "-append"
401
	 * @throws Exception 
402
	 * Source contains A, B
403
	 * Target contains A, B, C, D
404
	 * Expected is A, B, C, D
405
	 */
406
	public void testArtifactMirrorToPopulatedWithFullDuplicateWithAppend() throws Exception {
407
		artifactMirrorToPopulatedWithFullDuplicate(true);
408
409
		assertContentEquals("", srcRepo3, destRepo);
410
	}
411
412
	/**
413
	 * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data without "-append"
414
	 * @throws Exception 
415
	 * Source contains A, B
416
	 * Target contains A, B, C, D
417
	 * Expected is A, B
418
	 */
419
	public void testArtifactMirrorToPopulatedWithFullDuplicateWithoutAppend() throws Exception {
420
		artifactMirrorToPopulatedWithFullDuplicate(false);
421
422
		assertContentEquals("", srcRepo, destRepo);
423
	}
424
425
	/**
426
	 * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data with "-append"
427
	 * @throws Exception 
428
	 * Source contains A, B, C, D
429
	 * Target contains A, B, E, F
430
	 * Expected is A, B, C, D, E, F
431
	 */
432
	public void testArtifactMirrorToPopulatedWithPartialDuplicateWithAppend() throws Exception {
433
		artifactMirrorToPopulatedWithPartialDuplicate(true);
434
435
		assertContains("", srcRepo3, destRepo);
436
		assertContains("", srcRepo2, destRepo);
437
		assertEquals(srcRepo2.getArtifactKeys().length + srcRepo3.getArtifactKeys().length, destRepo.getArtifactKeys().length);
438
	}
439
440
	/**
441
	 * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data without "-append"
442
	 * @throws Exception 
443
	 * Source contains A, B, C, D
444
	 * Target contains A, B, E, F
445
	 * Expected is A, B, C, D
446
	 */
447
	public void testArtifactMirrorToPopulatedWithPartialDuplicateWithoutAppend() throws Exception {
448
		artifactMirrorToPopulatedWithPartialDuplicate(false);
449
450
		assertContentEquals("", srcRepo3, destRepo);
451
	}
452
}
(-)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
}
(-)src/org/eclipse/equinox/internal/p2/artifact/mirror/MirrorApplication.java (-2 / +4 lines)
Lines 29-35 Link Here
29
	private URL destinationLocation;
29
	private URL destinationLocation;
30
	private IArtifactRepository source;
30
	private IArtifactRepository source;
31
	private IArtifactRepository destination;
31
	private IArtifactRepository destination;
32
	private boolean append;
32
	private boolean append = false;
33
	private boolean raw = false;
33
	private boolean raw = false;
34
34
35
	public Object start(IApplicationContext context) throws Exception {
35
	public Object start(IApplicationContext context) throws Exception {
Lines 79-86 Link Here
79
			return;
79
			return;
80
		for (int i = 0; i < args.length; i++) {
80
		for (int i = 0; i < args.length; i++) {
81
			// check for args without parameters (i.e., a flag arg)
81
			// check for args without parameters (i.e., a flag arg)
82
			if (args[i].equals("-raw"))
82
			if (args[i].equalsIgnoreCase("-raw"))
83
				raw = true;
83
				raw = true;
84
			if (args[i].equalsIgnoreCase("-append"))
85
				append = true;
84
86
85
			// check for args with parameters. If we are at the last argument or 
87
			// check for args with parameters. If we are at the last argument or 
86
			// if the next one has a '-' as the first character, then we can't have 
88
			// if the next one has a '-' as the first character, then we can't have 

Return to bug 248144