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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*******************************************************************************
* Copyright (c) 2007, 2008 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.p2.tests.engine;
import org.eclipse.equinox.p2.metadata.Version;
import java.util.Map;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.engine.PhaseSet;
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory;
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.engine.spi.Touchpoint;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.eclipse.equinox.p2.tests.TestActivator;
import org.eclipse.equinox.p2.tests.engine.PhaseTest.TestPhaseSet;
import org.osgi.framework.ServiceReference;
/**
* Simple test of the engine API.
*/
public class TouchpointTest extends AbstractProvisioningTest {
static volatile TestTouchpoint testTouchpoint;
abstract static class TestTouchpoint extends Touchpoint {
int completeOperand;
int completePhase;
int initializeOperand;
int initializePhase;
public TestTouchpoint() {
testTouchpoint = this;
}
public IStatus completeOperand(IProfile profile, Operand operand, Map parameters) {
completeOperand++;
return super.completeOperand(profile, operand, parameters);
}
public IStatus completePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) {
completePhase++;
return super.completePhase(monitor, profile, phaseId, touchpointParameters);
}
public IStatus initializeOperand(IProfile profile, Operand operand, Map parameters) {
initializeOperand++;
return super.initializeOperand(profile, operand, parameters);
}
public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map touchpointParameters) {
initializePhase++;
return super.initializePhase(monitor, profile, phaseId, touchpointParameters);
}
public void resetCounters() {
completeOperand = 0;
completePhase = 0;
initializeOperand = 0;
initializePhase = 0;
}
}
public static class OperandTestTouchpoint extends TestTouchpoint {
public IStatus completeOperand(IProfile profile, Operand operand, Map parameters) {
assertEquals(1, initializeOperand);
assertEquals(0, completeOperand);
super.completeOperand(profile, operand, parameters);
assertEquals(1, initializeOperand);
assertEquals(1, completeOperand);
return null;
}
public IStatus initializeOperand(IProfile profile, Operand operand, Map parameters) {
assertEquals(0, initializeOperand);
assertEquals(0, completeOperand);
assertTrue(parameters.containsKey("TestPhase.initializeOperand"));
super.initializeOperand(profile, operand, parameters);
assertEquals(1, initializeOperand);
assertEquals(0, completeOperand);
return null;
}
public String qualifyAction(String actionId) {
return "operandtest." + actionId;
}
}
public static class PhaseTestTouchpoint extends TestTouchpoint {
public IStatus completePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map parameters) {
assertEquals(1, initializePhase);
assertEquals(0, completePhase);
super.completePhase(monitor, profile, phaseId, parameters);
assertEquals(1, initializePhase);
assertEquals(1, completePhase);
return null;
}
public IStatus initializePhase(IProgressMonitor monitor, IProfile profile, String phaseId, Map parameters) {
assertEquals(0, initializePhase);
assertEquals(0, completePhase);
assertTrue(parameters.containsKey("TestPhase.initializePhase"));
super.initializePhase(monitor, profile, phaseId, parameters);
assertEquals(1, initializePhase);
assertEquals(0, completePhase);
return null;
}
public String qualifyAction(String actionId) {
return "phasetest." + actionId;
}
}
private ServiceReference engineRef;
private IEngine engine;
public TouchpointTest(String name) {
super(name);
}
public TouchpointTest() {
super("");
}
protected void setUp() throws Exception {
engineRef = TestActivator.getContext().getServiceReference(IEngine.SERVICE_NAME);
engine = (IEngine) TestActivator.getContext().getService(engineRef);
}
protected void tearDown() throws Exception {
engine = null;
TestActivator.getContext().ungetService(engineRef);
}
public void testInitCompleteOperand() {
if (testTouchpoint != null)
testTouchpoint.resetCounters();
PhaseSet phaseSet = new TestPhaseSet();
IProfile profile = createProfile("testProfile");
final InstallableUnitOperand[] operands = new InstallableUnitOperand[] {new InstallableUnitOperand(null, createTestIU("operandTest"))};
engine.perform(engine.createCustomPlan(profile, operands, null), phaseSet, new NullProgressMonitor());
assertEquals(1, testTouchpoint.initializeOperand);
assertEquals(1, testTouchpoint.completeOperand);
}
public void testInitCompletePhase() {
if (testTouchpoint != null)
testTouchpoint.resetCounters();
PhaseSet phaseSet = new TestPhaseSet();
IProfile profile = createProfile("testProfile");
final InstallableUnitOperand[] operands = new InstallableUnitOperand[] {new InstallableUnitOperand(null, createTestIU("phaseTest"))};
engine.perform(engine.createCustomPlan(profile, operands, null), phaseSet, new NullProgressMonitor());
assertEquals(1, testTouchpoint.initializePhase);
assertEquals(1, testTouchpoint.completePhase);
}
private IInstallableUnit createTestIU(String touchpointName) {
InstallableUnitDescription description = new MetadataFactory.InstallableUnitDescription();
description.setId("org.eclipse.test");
description.setVersion(Version.create("1.0.0"));
description.setTouchpointType(MetadataFactory.createTouchpointType(touchpointName, Version.create("1.0.0")));
IInstallableUnit unit = MetadataFactory.createInstallableUnit(description);
return createResolvedIU(unit);
}
}
|