aboutsummaryrefslogtreecommitdiffstats
blob: b28e1f2073808409440e5c0ad656e5c301ca867f (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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*******************************************************************************
 * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tests.stepper;

import java.util.Map;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
import org.eclipse.tcf.te.runtime.stepper.StepperManager;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IStep;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepGroup;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepGroupable;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepper;
import org.eclipse.tcf.te.tests.CoreTestCase;

/**
 * Stepper engine test cases.
 */
public class StepperTestCase extends CoreTestCase {

	protected static class TestStepContext implements IStepContext {

		@Override
		public Object getAdapter(Class adapter) {
			return null;
		}

		@Override
		public String getId() {
			return "org.eclipse.tcf.te.tests.stepper.TestStepContext"; //$NON-NLS-1$
		}

		@Override
		public String getName() {
			return "TestStepContext"; //$NON-NLS-1$
		}

		@Override
		public Object getContextObject() {
			return this;
		}

		@Override
		public String getInfo(IPropertiesContainer data) {
			return getName();
		}

	}

	/**
	 * Provides a test suite to the caller which combines all single
	 * test bundled within this category.
	 *
	 * @return Test suite containing all test for this test category.
	 */
	public static Test getTestSuite() {
		TestSuite testSuite = new TestSuite("Test stepper engine"); //$NON-NLS-1$

		// add ourself to the test suite
		testSuite.addTestSuite(StepperTestCase.class);

		return testSuite;
	}

	/**
	 * Test the stepper extension point mechanism.
	 */
	public void testStepperContributions() {
		assertNotNull("Unexpected return value 'null'.", StepperManager.getInstance()); //$NON-NLS-1$
		assertNotNull("Unexpected return value 'null'.", StepperManager.getInstance().getStepperExtManager()); //$NON-NLS-1$

		// Lookup the default single-context stepper contributions
		boolean singleContext = false;

		IStepper[] steppers = StepperManager.getInstance().getStepperExtManager().getStepper(false);
		for (IStepper stepper : steppers) {
			if (stepper.getId().equals("org.eclipse.tcf.te.runtime.stepper")) { //$NON-NLS-1$
				singleContext = true;
			}
			if (singleContext) {
				break;
			}
		}
		assertTrue("Default single context stepper contribution not found.", singleContext); //$NON-NLS-1$
	}

	/**
	 * Test the steps extension point mechanism.
	 */
	public void testStepContributions() {
		assertNotNull("Unexpected return value 'null'.", StepperManager.getInstance()); //$NON-NLS-1$
		assertNotNull("Unexpected return value 'null'.", StepperManager.getInstance().getStepExtManager()); //$NON-NLS-1$

		IStep[] steps = StepperManager.getInstance().getStepExtManager().getSteps(false);
		int testStepCount = 0;

		for (IStep step : steps) {
			if (step.getId().startsWith("org.eclipse.tcf.te.tests.stepper.step")) { //$NON-NLS-1$
				testStepCount++;
			} else {
				continue;
			}

			if (step.getId().endsWith(".step1")) { //$NON-NLS-1$
				assertEquals("Unexpected step label found.", "Test Step 1", step.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "", step.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertTrue("Unexpected step class type found.", step instanceof TestStep); //$NON-NLS-1$
				assertEquals("Unexpected number of dependencies found.", 0, step.getDependencies().length); //$NON-NLS-1$
			}

			if (step.getId().endsWith(".step2")) { //$NON-NLS-1$
				assertEquals("Unexpected step label found.", "Test Step 2", step.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "", step.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertTrue("Unexpected step class type found.", step instanceof ParameterizedTestStep); //$NON-NLS-1$

				Map<?,?> params = ((ParameterizedTestStep)step).params;
				assertNotNull("Unexpected value 'null'.", params); //$NON-NLS-1$
				assertEquals("Unexpected number of parameter found.", 1, params.keySet().size()); //$NON-NLS-1$
				assertTrue("Missing expected key 'param1'.", params.containsKey("param1")); //$NON-NLS-1$ //$NON-NLS-2$
				assertTrue("Missing expected value 'value1'.", params.containsValue("value1")); //$NON-NLS-1$ //$NON-NLS-2$

				assertEquals("Unexpected number of dependencies found.", 0, step.getDependencies().length); //$NON-NLS-1$
			}

			if (step.getId().endsWith(".step3")) { //$NON-NLS-1$
				assertEquals("Unexpected step label found.", "Test Step 3", step.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "Just another test step", step.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertTrue("Unexpected step class type found.", step instanceof TestStep); //$NON-NLS-1$
				assertEquals("Unexpected number of dependencies found.", 0, step.getDependencies().length); //$NON-NLS-1$
			}

			if (step.getId().endsWith(".step4")) { //$NON-NLS-1$
				assertEquals("Unexpected step label found.", "Test Step 4", step.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "", step.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertTrue("Unexpected step class type found.", step instanceof TestStep); //$NON-NLS-1$
				assertEquals("Unexpected number of dependencies found.", 1, step.getDependencies().length); //$NON-NLS-1$
			}

			if (step.getId().endsWith(".step5")) { //$NON-NLS-1$
				assertEquals("Unexpected step label found.", "Test Step 5", step.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "", step.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertTrue("Unexpected step class type found.", step instanceof TestStep); //$NON-NLS-1$
				assertEquals("Unexpected number of dependencies found.", 0, step.getDependencies().length); //$NON-NLS-1$
			}
		}

		assertEquals("Unexpected number of test steps found.", 5, testStepCount); //$NON-NLS-1$
	}

	/**
	 * Test the step group extension point mechanism.
	 */
	public void testStepGroupContributions() {
		assertNotNull("Unexpected return value 'null'.", StepperManager.getInstance()); //$NON-NLS-1$
		assertNotNull("Unexpected return value 'null'.", StepperManager.getInstance().getStepGroupExtManager()); //$NON-NLS-1$

		IStepGroup[] stepGroups = StepperManager.getInstance().getStepGroupExtManager().getStepGroups(false);
		int testStepGroupCount = 0;

		for (IStepGroup stepGroup : stepGroups) {
			if (stepGroup.getId().startsWith("org.eclipse.tcf.te.tests.stepper.stepGroup")) { //$NON-NLS-1$
				testStepGroupCount++;
			} else {
				continue;
			}

			Throwable error = null;
			String message = null;
			IStepGroupable[] steps = null;

			if (stepGroup.getId().endsWith(".stepGroup1")) { //$NON-NLS-1$
				assertEquals("Unexpected step group label found.", "Test Step Group 1", stepGroup.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "", stepGroup.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertFalse("Step group is locked but should not.", stepGroup.isLocked()); //$NON-NLS-1$
				assertNull("Unexpected non-null value.", stepGroup.getStepGroupIterator()); //$NON-NLS-1$

				try {
					steps = stepGroup.getSteps(new TestStepContext());
				} catch (CoreException e) {
					error = e;
					message = e.getLocalizedMessage();
				}
				assertNull("Failed to determine steps from step group. Possible cause: " + message, error); //$NON-NLS-1$
				assertNotNull("Unexpected return value 'null'.", steps); //$NON-NLS-1$
				assertEquals("Unexpected number of steps returned.", 0, steps.length); //$NON-NLS-1$
			}

			if (stepGroup.getId().endsWith(".stepGroup2")) { //$NON-NLS-1$
				assertEquals("Unexpected step group label found.", "Test Step Group 2", stepGroup.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "Just a step group description", stepGroup.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertTrue("Step group is not locked but should.", stepGroup.isLocked()); //$NON-NLS-1$
				assertNull("Unexpected non-null value.", stepGroup.getStepGroupIterator()); //$NON-NLS-1$

				error = null; message = null; steps = null;
				try {
					steps = stepGroup.getSteps(new TestStepContext());
				} catch (CoreException e) {
					error = e;
					message = e.getLocalizedMessage();
				}
				assertNull("Failed to determine steps from step group. Possible cause: " + message, error); //$NON-NLS-1$
				assertNotNull("Unexpected return value 'null'.", steps); //$NON-NLS-1$
				assertEquals("Unexpected number of steps returned.", 0, steps.length); //$NON-NLS-1$
			}

			if (stepGroup.getId().endsWith(".stepGroup3")) { //$NON-NLS-1$
				assertEquals("Unexpected step group label found.", "Test Step Group 3", stepGroup.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "", stepGroup.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertFalse("Step group is locked but should not.", stepGroup.isLocked()); //$NON-NLS-1$
				assertNull("Unexpected non-null value.", stepGroup.getStepGroupIterator()); //$NON-NLS-1$

				error = null; message = null; steps = null;
				try {
					steps = stepGroup.getSteps(new TestStepContext());
				} catch (CoreException e) {
					error = e;
					message = e.getLocalizedMessage();
				}
				assertNull("Failed to determine steps from step group. Possible cause: " + message, error); //$NON-NLS-1$
				assertNotNull("Unexpected return value 'null'.", steps); //$NON-NLS-1$
				assertEquals("Unexpected number of steps returned.", 4, steps.length); //$NON-NLS-1$

				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step1", steps[0].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step2", steps[1].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step3", steps[2].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step4", steps[3].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
			}


			if (stepGroup.getId().endsWith(".stepGroup4")) { //$NON-NLS-1$
				assertEquals("Unexpected step group label found.", "Test Step Group 4", stepGroup.getLabel()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step description found.", "", stepGroup.getDescription()); //$NON-NLS-1$ //$NON-NLS-2$
				assertFalse("Step group is locked but should not.", stepGroup.isLocked()); //$NON-NLS-1$
				assertNull("Unexpected non-null value.", stepGroup.getStepGroupIterator()); //$NON-NLS-1$

				error = null; message = null; steps = null;
				try {
					steps = stepGroup.getSteps(new TestStepContext());
				} catch (CoreException e) {
					error = e;
					message = e.getLocalizedMessage();
				}
				assertNull("Failed to determine steps from step group. Possible cause: " + message, error); //$NON-NLS-1$
				assertNotNull("Unexpected return value 'null'.", steps); //$NON-NLS-1$
				assertEquals("Unexpected number of steps returned.", 5, steps.length); //$NON-NLS-1$

				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step1", steps[0].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step2", steps[1].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step3", steps[2].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step4", steps[3].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$

				error = null; message = null; steps = null;
				try {
					steps = stepGroup.getSteps(new TestStepContext());
				} catch (CoreException e) {
					error = e;
					message = e.getLocalizedMessage();
				}
				assertNull("Failed to determine steps from step group. Possible cause: " + message, error); //$NON-NLS-1$
				assertNotNull("Unexpected return value 'null'.", steps); //$NON-NLS-1$
				assertEquals("Unexpected number of steps returned.", 5, steps.length); //$NON-NLS-1$

				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step1", steps[0].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step2", steps[1].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step3", steps[2].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step4", steps[3].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
				assertEquals("Unexpected step order.", "org.eclipse.tcf.te.tests.stepper.step5", steps[4].getExtension().getId()); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}

		assertEquals("Unexpected number of test step groups found.", 4, testStepGroupCount); //$NON-NLS-1$
	}
}