Skip to main content
summaryrefslogtreecommitdiffstats
blob: 82f5878d51c85109c074f09ea2683a94e1ba61e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*******************************************************************************
 * Copyright (c) 2013 Ericsson AB and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Ericsson AB - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.sharedinstall;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdateScheduler;
import org.eclipse.equinox.p2.engine.IEngine;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.tests.*;

public class NeedsMigration extends AbstractProvisioningTest {
	@IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 1 \n")
	public IInstallableUnit sdk1;

	@IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 2 \n")
	public IInstallableUnit sdk2;

	@IUDescription(content = "package: egit \n" + "singleton: true\n" + "version: 1 \n")
	public IInstallableUnit egit1;

	@IUDescription(content = "package: egit \n" + "singleton: true\n" + "version: 2 \n")
	public IInstallableUnit egit2;

	@IUDescription(content = "package: cdt \n" + "singleton: true\n" + "version: 1 \n")
	public IInstallableUnit cdt1;

	@IUDescription(content = "package: eppPackage \n" + "singleton: true\n" + "version: 1 \n" + "depends: sdk = 1, egit =1")
	public IInstallableUnit eppPackage;

	private IPlanner planner;
	private IEngine engine;
	private AutomaticUpdateScheduler scheduler;
	private Method needsMigrationMethod;

	@Override
	protected void setUp() throws Exception {
		IULoader.loadIUs(this);
		planner = createPlanner();
		engine = createEngine();
		scheduler = new AutomaticUpdateScheduler();
		createTestMetdataRepository(new IInstallableUnit[] {sdk1, sdk2, egit1, egit2, cdt1, eppPackage});
		needsMigrationMethod = scheduler.getClass().getDeclaredMethod("needsMigration", IProfile.class, IProfile.class);
		needsMigrationMethod.setAccessible(true);
	}

	public void testEmptyUserProfile() {
		IProfile previousUserProfile = createProfile("previous" + getName());
		IProfile currentBaseProfile = createProfile("current" + getName());
		assertOK(install(currentBaseProfile, new IInstallableUnit[] {sdk1}, true, planner, engine));

		//The user version and the base version are the same
		assertFalse(needsMigration(previousUserProfile, currentBaseProfile));
	}

	public void testSameVersions() {
		IProfile previousUserProfile = createProfile("previous" + getName());
		IProfile currentBaseProfile = createProfile("current" + getName());
		assertOK(install(previousUserProfile, new IInstallableUnit[] {sdk1}, true, planner, engine));
		assertOK(install(currentBaseProfile, new IInstallableUnit[] {sdk1}, true, planner, engine));

		//The user version and the base version are the same
		assertFalse(needsMigration(previousUserProfile, currentBaseProfile));
	}

	public void testDifferentVersions() {
		IProfile previousUserProfile = createProfile("previous" + getName());
		IProfile currentBaseProfile = createProfile("current" + getName());
		assertOK(installAsRoots(previousUserProfile, new IInstallableUnit[] {sdk1}, true, planner, engine));
		assertOK(installAsRoots(currentBaseProfile, new IInstallableUnit[] {sdk2}, true, planner, engine));

		//The user version is older than the base version
		assertFalse(needsMigration(previousUserProfile, currentBaseProfile));
	}

	public void testUserProfileNewerThanBaseVersion() {
		IProfile previousUserProfile = createProfile("previous" + getName());
		IProfile currentBaseProfile = createProfile("current" + getName());
		assertOK(installAsRoots(previousUserProfile, new IInstallableUnit[] {sdk2, egit2}, true, planner, engine));
		assertOK(installAsRoots(currentBaseProfile, new IInstallableUnit[] {sdk2, egit1}, true, planner, engine));

		//The user version is higher than what the base has
		assertTrue(needsMigration(previousUserProfile, currentBaseProfile));
	}

	public void testBaseEncompassWhatUserHas() {
		IProfile previousUserProfile = createProfile("previous" + getName());
		IProfile currentBaseProfile = createProfile("current" + getName());
		assertOK(installAsRoots(previousUserProfile, new IInstallableUnit[] {sdk1, egit1}, true, planner, engine));
		assertOK(installAsRoots(currentBaseProfile, new IInstallableUnit[] {eppPackage, sdk1, egit1}, true, planner, engine));

		//All the elements that are in the user profile are included in the base
		assertFalse(needsMigration(previousUserProfile, currentBaseProfile));
	}

	public void testBaseEncompassSomePartsOfWhatUserHas() {
		IProfile previousUserProfile = createProfile("previous" + getName());
		IProfile currentBaseProfile = createProfile("current" + getName());
		assertOK(installAsRoots(previousUserProfile, new IInstallableUnit[] {sdk1, egit1, cdt1}, true, planner, engine));
		assertOK(installAsRoots(currentBaseProfile, new IInstallableUnit[] {eppPackage, egit1}, true, planner, engine));

		//Not all the elements that are in the user profile are included in the base
		assertTrue(needsMigration(previousUserProfile, currentBaseProfile));
	}

	private boolean needsMigration(IProfile previousUserProfile, IProfile currentBaseProfile) {
		try {
			return (Boolean) needsMigrationMethod.invoke(scheduler, previousUserProfile, currentBaseProfile);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		} catch (IllegalArgumentException e) {
			throw new RuntimeException(e);
		} catch (InvocationTargetException e) {
			throw new RuntimeException(e);
		}
	}
}

Back to the top