Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c4a7da3626ba0d37a476553047088e7d9f73ece2 (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
/*****************************************************************************
 * Copyright (c) 2015 CEA LIST.
 *
 * 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:
 *  Thomas Daniellou (CEA LIST) - Initial API and implementation
 *****************************************************************************/
package org.eclipse.papyrus.adl4eclipse.tests.testcases;

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

import java.util.List;

import org.eclipse.papyrus.adl4eclipse.org.ADL4Eclipse_Stereotypes;
import org.eclipse.papyrus.adl4eclipse.tests.AbstractADLTest;
import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.PackageableElement;
import org.eclipse.uml2.uml.Stereotype;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * This test case creates two Feature projects (the main feature and an empty feature).
 * The empty feature project will be included in the Feature project.
 * After the projects creation, the main feature will be reversed.
 *
 * Expected Model Explorer after the reverse:
 *
 * - model
 *		- Features
 *			- Feature (FEATURE_WITH_INCLUDES_PROJECT_NAME)
 *			- Feature (EMPTY_FEATURE_PROJECT_NAME)
 *
 */
public class TestFeatureWithIncludes extends AbstractADLTest {

	@Before
	public void initializeWorkspace() {
		try {
			initModel();

			// Create an empty feature
			createReversibleFeature(EMPTY_FEATURE_PROJECT_NAME);

			// Create a feature with included features
			createReversibleFeature(FEATURE_WITH_INCLUDES_PROJECT_NAME);
		} catch (Exception e) {
			Assert.fail(e.getMessage());
		}

		executeReverse(SIMPLE_REVERSE_DEPTH);
	}

	@Test
	public void testTwoChildren() {
		List<PackageableElement> packageableElements = rootModel.getPackagedElements();

		// Two children: "Architecture" and "Platform" packages
		assertEquals("The root model should have 2 packaged elements", 2, packageableElements.size());

		assertTrue("The reversed project should be a Component", packageableElements.get(0) instanceof Component);
		assertTrue("The reversed project should be a Component", packageableElements.get(1) instanceof Component);
	}

	@Test
	public void testFeatureExists() {
		PackageableElement feature = rootModel.getPackagedElement(FEATURE_WITH_INCLUDES_PROJECT_NAME);

		assertNotNull("The modeled feature should exist", feature);
		assertTrue("The element in the UML model should be a Component", feature instanceof Component);
		assertEquals("The feature should have one applied stereotype", 1, feature.getAppliedStereotypes().size());

		Stereotype featureStereotype = feature.getApplicableStereotype(ADL4Eclipse_Stereotypes.FEATURE_STEREOTYPE);

		assertNotNull("The Feature stereotype should be applied to the feature component", featureStereotype);
	}

	@Test
	public void testIncludedFeatureExists() {
		PackageableElement includedFeature = rootModel.getPackagedElement(FEATURE_WITH_INCLUDES_PROJECT_NAME);

		assertNotNull("The modeled included feature should exist", includedFeature);
		assertTrue("The included feature element in the UML model should be a Component", includedFeature instanceof Component);
		assertEquals("The feature should have one applied stereotype", 1, includedFeature.getAppliedStereotypes().size());

		Stereotype featureStereotype = includedFeature.getApplicableStereotype(ADL4Eclipse_Stereotypes.FEATURE_STEREOTYPE);

		assertNotNull("The Feature stereotype should be applied to the included feature component", featureStereotype);
	}

	@Test
	public void testFeatureStereotype() {
		PackageableElement feature = rootModel.getPackagedElement(FEATURE_WITH_INCLUDES_PROJECT_NAME);
		Stereotype featureStereotype = feature.getApplicableStereotype(ADL4Eclipse_Stereotypes.FEATURE_STEREOTYPE);

		// Plug-ins
		Object plugins = feature.getValue(featureStereotype, ADL4Eclipse_Stereotypes.FEATURE_PLUGINS_ATT);
		assertEquals("The plug-in list size should be equals to 0", 0, ((List<?>) plugins).size());

		// Included features
		Object includedFeatures = feature.getValue(featureStereotype, ADL4Eclipse_Stereotypes.FEATURE_FEATURE_DEPENDENCIES_ATT);
		assertEquals("The included feature list size should be equals to 0", 0, ((List<?>) includedFeatures).size());

		// ImportedFeatures
		Object importedFeatures = feature.getValue(featureStereotype, ADL4Eclipse_Stereotypes.FEATURE_INCLUDED_FEATURES_ATT);
		assertEquals("The imported feature list size should be equals to 1", 1, ((List<?>) importedFeatures).size());
	}

	@Test
	public void testIncludedFeatureStereotype() {
		PackageableElement includedFeature = rootModel.getPackagedElement(EMPTY_FEATURE_PROJECT_NAME);
		Stereotype featureStereotype = includedFeature.getApplicableStereotype(ADL4Eclipse_Stereotypes.FEATURE_STEREOTYPE);

		Object version = includedFeature.getValue(featureStereotype, "version");
		assertEquals("The imported feature version should correspond", "1.0.0.qualifier", version);

		Object label = includedFeature.getValue(featureStereotype, "label");
		assertEquals("The imported feature label should correspond", EMPTY_FEATURE_PROJECT_NAME, label);

		// Plug-ins
		Object plugins = includedFeature.getValue(featureStereotype, ADL4Eclipse_Stereotypes.FEATURE_PLUGINS_ATT);
		assertEquals("The plug-in list size should be equals to 0", 0, ((List<?>) plugins).size());

		// Included features
		Object includedFeatures = includedFeature.getValue(featureStereotype, ADL4Eclipse_Stereotypes.FEATURE_FEATURE_DEPENDENCIES_ATT);
		assertEquals("The included feature list size should be equals to 0", 0, ((List<?>) includedFeatures).size());

		// ImportedFeatures
		Object importedFeatures = includedFeature.getValue(featureStereotype, ADL4Eclipse_Stereotypes.FEATURE_INCLUDED_FEATURES_ATT);
		assertEquals("The imported feature list size should be equals to 0", 0, ((List<?>) importedFeatures).size());
	}
}

Back to the top