Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7cd9190fe6c1b020448f0ac39c1f7d781aa452c1 (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
/*******************************************************************************
 * Copyright (c) 2016 Obeo.
 * 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:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.framework;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.compare.conflict.DefaultConflictDetector;
import org.eclipse.emf.compare.conflict.MatchBasedConflictDetector;
import org.eclipse.emf.compare.diff.DefaultDiffEngine;
import org.eclipse.emf.compare.equi.DefaultEquiEngine;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.ConflictDetectors;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.DiffEngines;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.DisabledMatchEngines;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.DisabledPostProcessors;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.EqEngines;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.ReqEngines;
import org.eclipse.emf.compare.ide.ui.tests.framework.annotations.ResolutionStrategies;
import org.eclipse.emf.compare.req.DefaultReqEngine;
import org.junit.Assert;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.ParentRunner;
import org.junit.runners.model.InitializationError;

/**
 * EMFCompare specific runners must extends this class.
 * 
 * @author <a href="mailto:mathieu.cartaud@obeo.fr">Mathieu Cartaud</a>
 */
public abstract class AbstractCompareTestRunner extends ParentRunner<Runner> {

	/** The list of all runners. */
	protected final List<Runner> runners;

	/** Default list of resolution strategies used if the @ResolutionStrategies annotation is not used. */
	private final ResolutionStrategyID[] defaultResolutionStrategies = new ResolutionStrategyID[] {
			ResolutionStrategyID.WORKSPACE, };

	/** Default list of match engines disabled if the @MatchEngines annotation is not used. */
	private final Class<?>[] defaultDisabledMatchEngines = new Class<?>[] {};

	/** Default list of diff engines used if the @DiffEngines annotation is not used. */
	private final Class<?>[] defaultDiffEngines = new Class<?>[] {DefaultDiffEngine.class };

	/** Default list of eq engines used if the @EqEngines annotation is not used. */
	private final Class<?>[] defaultEqEngines = new Class<?>[] {DefaultEquiEngine.class };

	/** Default list of req engines used if the @ReqEngines annotation is not used. */
	private final Class<?>[] defaultReqEngines = new Class<?>[] {DefaultReqEngine.class };

	/** Default list of conflict detector used if the @ConflictEngines annotation is not used. */
	private final Class<?>[] defaultConflictDetectors = new Class<?>[] {DefaultConflictDetector.class,
			MatchBasedConflictDetector.class, };

	/** Default list of resolution strategies disabled if the @PostProcessors annotation is not used. */
	private final Class<?>[] defaultDisabledPostProcessors = new Class<?>[] {};

	/**
	 * The constructor.
	 * 
	 * @param testClass
	 *            The given test class
	 * @throws InitializationError
	 *             If the test cannot be created
	 */
	public AbstractCompareTestRunner(Class<?> testClass) throws InitializationError {
		super(testClass);

		runners = new ArrayList<Runner>();
		prepareRunnersForTests();
	}

	/**
	 * Create a runner for each configuration. The configurations are a matrix of all association
	 * possibilities between match, diff, eq, req and conflict engines.
	 */
	private void prepareRunnersForTests() {
		ResolutionStrategies rStrategies = getTestClass().getAnnotation(ResolutionStrategies.class);
		final ResolutionStrategyID[] resolutionStrategies;
		if (rStrategies == null) {
			resolutionStrategies = defaultResolutionStrategies;
		} else {
			resolutionStrategies = rStrategies.value();
		}

		DisabledMatchEngines mEngines = getTestClass().getAnnotation(DisabledMatchEngines.class);
		final Class<?>[] disabledMatchEngines;
		if (mEngines == null) {
			disabledMatchEngines = defaultDisabledMatchEngines;
		} else {
			disabledMatchEngines = mEngines.value();
		}

		DiffEngines dEngines = getTestClass().getAnnotation(DiffEngines.class);
		final Class<?>[] diffEngines;
		if (dEngines == null) {
			diffEngines = defaultDiffEngines;
		} else {
			diffEngines = dEngines.value();
		}

		EqEngines eEngines = getTestClass().getAnnotation(EqEngines.class);
		final Class<?>[] eqEngines;
		if (eEngines == null) {
			eqEngines = defaultEqEngines;
		} else {
			eqEngines = eEngines.value();
		}

		ReqEngines rEngines = getTestClass().getAnnotation(ReqEngines.class);
		final Class<?>[] reqEngines;
		if (rEngines == null) {
			reqEngines = defaultReqEngines;
		} else {
			reqEngines = rEngines.value();
		}

		ConflictDetectors cEngines = getTestClass().getAnnotation(ConflictDetectors.class);
		final Class<?>[] conflictDetectors;
		if (cEngines == null) {
			conflictDetectors = defaultConflictDetectors;
		} else {
			conflictDetectors = cEngines.value();
		}

		DisabledPostProcessors pProcessors = getTestClass().getAnnotation(DisabledPostProcessors.class);
		final Class<?>[] disabledPostProcessors;
		if (pProcessors == null) {
			disabledPostProcessors = defaultDisabledPostProcessors;
		} else {
			disabledPostProcessors = pProcessors.value();
		}

		// CHECKSTYLE:OFF those embedded fors are necessary to create all the test possibilities
		for (ResolutionStrategyID resolutionStrategy : resolutionStrategies) {
			for (Class<?> diffEngine : diffEngines) {
				for (Class<?> eqEngine : eqEngines) {
					for (Class<?> reqEngine : reqEngines) {
						for (Class<?> conflictDetector : conflictDetectors) {
							// CHECKSTYLE:ON
							try {
								EMFCompareTestConfiguration configuration = new EMFCompareTestConfiguration(
										disabledMatchEngines, diffEngine, eqEngine, reqEngine,
										conflictDetector, disabledPostProcessors);
								createRunner(getTestClass().getJavaClass(), resolutionStrategy,
										configuration);
							} catch (InitializationError e) {
								e.printStackTrace();
								Assert.fail(e.getMessage());
							}
						}
					}
				}
			}
		}
	}

	/**
	 * Create the specific runner for the given parameters.
	 * 
	 * @param testClass
	 *            The class to test
	 * @param resolutionStrategy
	 *            The resolution strategy used for this runner
	 * @param configuration
	 *            EMFCompare configurations for the test
	 * @throws InitializationError
	 *             If the creation of the runner goes wrong
	 */
	public abstract void createRunner(Class<?> testClass, ResolutionStrategyID resolutionStrategy,
			EMFCompareTestConfiguration configuration) throws InitializationError;

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.junit.runners.BlockJUnit4ClassRunner#getChildren()
	 */
	@Override
	protected List<Runner> getChildren() {
		return runners;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.junit.runners.ParentRunner#describeChild(java.lang.Object)
	 */
	@Override
	protected Description describeChild(Runner child) {
		return child.getDescription();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.junit.runners.ParentRunner#runChild(java.lang.Object,
	 *      org.junit.runner.notification.RunNotifier)
	 */
	@Override
	protected void runChild(Runner child, RunNotifier notifier) {
		child.run(notifier);
	}

}

Back to the top