Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 47de1e8318cd41ab524b804783d086937c806d21 (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
/*****************************************************************************
 * Copyright (c) 2016 Christian W. Damus 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:
 *   Christian W. Damus - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.infra.emf.resource;

import java.util.Arrays;

import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Package;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * Tests for the {@link ShardResourceLocator} class. These tests are run both
 * with the full cross-reference index and with the partial on-demand index that
 * only looks for shard parent relationships.
 */
@RunWith(Parameterized.class)
public class ShardResourceLocatorTest extends AbstractCrossReferenceIndexTest {

	/**
	 * Initializes me.
	 * 
	 * @param onDemand
	 *            whether to force the on-demand cross-reference index
	 * @param description
	 *            the description of the test conditions
	 */
	public ShardResourceLocatorTest(boolean onDemand, String description) {
		super(onDemand);
	}

	@Test
	@ProjectResource("package1/packageA/foo.uml")
	public void shardLoadsContainersAndDoesntLoseStereotypes() {
		Class foo = (Class) initialResources.get(0).getContents().get(0);

		// The parent chain of Foo is loaded
		requireLoaded("root.uml");
		requireLoaded("package1.uml");
		requireLoaded("package1/packageA.uml");

		// Stereotype applications were not lost
		requireEClass(foo);
		requireEPackage(foo.getNearestPackage());
		requireEPackage(foo.getNearestPackage().getNestingPackage());
	}

	@Test
	@ProjectResource("referencing.uml")
	public void proxyResolutionLoadsShardFromTheTop() {
		Package referencing = (Package) initialResources.get(0).getContents().get(0);
		Class subclass = (Class) referencing.getNestedPackage("package1")
				.getNestedPackage("packageA").getOwnedType("Subclass");

		// Get its general
		Class superclass = (Class) subclass.getGeneral("Bar");

		// The parent chain of Bar is loaded
		requireLoaded("root.uml");
		requireLoaded("package2.uml");
		requireLoaded("package2/packageB.uml");

		// Stereotype applications were not lost
		requireEClass(superclass);
		requireEPackage(superclass.getNearestPackage());
		requireEPackage(superclass.getNearestPackage().getNestingPackage());
	}

	//
	// Test framework
	//

	@Parameters(name = "{index}: {1}")
	public static Iterable<Object[]> data() {
		return Arrays.asList(new Object[][] {
				{ false, "full index" },
				{ true, "on-demand index" },
		});
	}

	@BeforeClass
	public static void createProjectContents() {
		createProjectContents("resources/shards");
	}
}

Back to the top