Skip to main content
summaryrefslogtreecommitdiffstats
blob: b180e705a96a6480674b95030dd35384d6d23946 (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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*******************************************************************************
 * Copyright (c) 2015 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.logical.resolver;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
import org.eclipse.emf.compare.ide.ui.internal.logical.ComparisonScopeBuilder;
import org.eclipse.emf.compare.ide.ui.internal.logical.IdenticalResourceMinimizer;
import org.eclipse.emf.compare.ide.ui.internal.logical.StorageTypedElement;
import org.eclipse.emf.compare.ide.ui.internal.logical.StreamAccessorStorage;
import org.eclipse.emf.compare.ide.ui.internal.logical.resolver.ThreadedModelResolver;
import org.eclipse.emf.compare.ide.ui.internal.util.PlatformElementUtil;
import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
import org.eclipse.emf.compare.internal.utils.ReadOnlyGraph;
import org.junit.Test;
import org.osgi.framework.Bundle;

@SuppressWarnings({"restriction", "nls" })
public class ThreadedModelResolverGraphTest {

	private static String LEFT = "left";

	private static String RIGHT = "right";

	private static String SEP = File.separator;

	private static String URI_SEP = "/";

	private static String PLATFORM_RESOURCE = "platform:" + URI_SEP + "resource";

	private ReadOnlyGraph<URI> initGraph(String projectName) throws IOException, CoreException {
		Bundle bundle = Platform.getBundle("org.eclipse.emf.compare.ide.ui.tests");
		URL entry = bundle.getEntry("src" + SEP + "org" + SEP + "eclipse" + SEP + "emf" + SEP + "compare"
				+ SEP + "ide" + SEP + "ui" + SEP + "tests" + SEP + "structuremergeviewer" + SEP
				+ "notloadedfragment" + SEP + "data" + SEP + projectName + SEP + ".project");
		URL fileURL = FileLocator.toFileURL(entry);
		IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(
				new Path(fileURL.getPath()));
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
		if (!project.exists()) {
			project.create(description, new NullProgressMonitor());
			project.open(new NullProgressMonitor());
		}

		final IFile leftFile = project.getFile(new Path("left" + SEP + "R1.ecore"));
		final IFile rightFile = project.getFile(new Path("right" + SEP + "R1.ecore"));
		final ITypedElement left = new StorageTypedElement(leftFile, leftFile.getFullPath().toOSString());
		final ITypedElement right = new StorageTypedElement(rightFile, rightFile.getFullPath().toOSString());

		IStorage leftStorage = PlatformElementUtil.findFile(left);
		if (leftStorage == null) {
			leftStorage = StreamAccessorStorage.fromTypedElement(left);
		}
		final IModelResolver resolver = EMFCompareIDEUIPlugin.getDefault().getModelResolverRegistry()
				.getBestResolverFor(leftStorage);

		assertTrue(resolver instanceof ThreadedModelResolver);

		final ComparisonScopeBuilder scopeBuilder = new ComparisonScopeBuilder(resolver,
				new IdenticalResourceMinimizer(), null);
		scopeBuilder.build(left, right, null, new NullProgressMonitor());

		return ((ThreadedModelResolver)resolver).getDependencyGraph();
	}

	@Test
	public void testCase0_GetParentData() throws IOException, CoreException {
		String projectName = "case0";
		final ReadOnlyGraph<URI> graph = initGraph(projectName);
		// Left
		String leftPath = projectName + URI_SEP + LEFT + URI_SEP;
		URI parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + URI_SEP + "R1.ecore",
				false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		// Right
		String rightPath = projectName + URI_SEP + RIGHT + URI_SEP;
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
	}

	@Test
	public void testCase1_GetParentData() throws IOException, CoreException {
		String projectName = "case1";
		final ReadOnlyGraph<URI> graph = initGraph(projectName);
		// Left
		String leftPath = projectName + URI_SEP + LEFT + URI_SEP;
		URI parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R2.ecore#_B", parentData.toString());
		// Right
		String rightPath = projectName + URI_SEP + RIGHT + URI_SEP;
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R2.ecore#_B", parentData.toString());
	}

	@Test
	public void testCase2_GetParentData() throws IOException, CoreException {
		String projectName = "case2";
		final ReadOnlyGraph<URI> graph = initGraph(projectName);
		// Left
		String leftPath = projectName + URI_SEP + LEFT + URI_SEP;
		URI parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R2.ecore#_B", parentData.toString());
		// Right
		String rightPath = projectName + URI_SEP + RIGHT + URI_SEP;
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R2.ecore#_B", parentData.toString());
	}

	@Test
	public void testCase3_GetParentData() throws IOException, CoreException {
		String projectName = "case3";
		final ReadOnlyGraph<URI> graph = initGraph(projectName);
		// Left
		String leftPath = projectName + URI_SEP + LEFT + URI_SEP;
		URI parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R2.ecore#_B", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R4.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R3.ecore#_D", parentData.toString());
		// Right
		String rightPath = projectName + URI_SEP + RIGHT + URI_SEP;
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R2.ecore#_B", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R4.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R3.ecore#_D", parentData.toString());
	}

	@Test
	public void testCase4_GetParentData() throws IOException, CoreException {
		String projectName = "case4";
		final ReadOnlyGraph<URI> graph = initGraph(projectName);
		// Left
		String leftPath = projectName + URI_SEP + LEFT + URI_SEP;
		URI parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		// Right
		String rightPath = projectName + URI_SEP + RIGHT + URI_SEP;
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
	}

	@Test
	public void testCase5_GetParentData() throws IOException, CoreException {
		String projectName = "case5";
		final ReadOnlyGraph<URI> graph = initGraph(projectName);
		// Left
		String leftPath = projectName + URI_SEP + LEFT + URI_SEP;
		URI parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R4.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R2.ecore#_B", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R5.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R3.ecore#_C", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R6.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R4.ecore#_D", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R7.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R5.ecore#_E", parentData.toString());
		// Right
		String rightPath = projectName + URI_SEP + RIGHT + URI_SEP;
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R4.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R2.ecore#_B", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R5.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R3.ecore#_C", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R6.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R4.ecore#_D", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R7.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R5.ecore#_E", parentData.toString());
	}

	@Test
	public void testCase6_GetParentData() throws IOException, CoreException {
		String projectName = "case6";
		final ReadOnlyGraph<URI> graph = initGraph(projectName);
		// Left
		String leftPath = projectName + URI_SEP + LEFT + URI_SEP;
		URI parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R4.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R2.ecore#_B", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R5.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R4.ecore#_D", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R6.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R4.ecore#_D", parentData.toString());
		// Right
		String rightPath = projectName + URI_SEP + RIGHT + URI_SEP;
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R4.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R2.ecore#_B", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R5.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R4.ecore#_D", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R6.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R4.ecore#_D", parentData.toString());
	}

	@Test
	public void testCase7_GetParentData() throws IOException, CoreException {
		String projectName = "case7";
		final ReadOnlyGraph<URI> graph = initGraph(projectName);
		// Left
		String leftPath = projectName + URI_SEP + LEFT + URI_SEP;
		URI parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R4.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R2.ecore#_B", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R5.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R4.ecore#_D", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(leftPath + "R6.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + leftPath + "R4.ecore#_D", parentData.toString());
		// Right
		String rightPath = projectName + URI_SEP + RIGHT + URI_SEP;
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R1.ecore", false));
		assertNull(parentData);
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R2.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R3.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R1.ecore#_A", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R4.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R2.ecore#_B", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R5.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R4.ecore#_D", parentData.toString());
		parentData = graph.getParentData(URI.createPlatformResourceURI(rightPath + "R6.ecore", false));
		assertEquals(PLATFORM_RESOURCE + URI_SEP + rightPath + "R4.ecore#_D", parentData.toString());
	}
}

Back to the top