Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d637a41c0e5fe1d2cf8b02ec6d587d8b2b952485 (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
/*****************************************************************************
 * Copyright (c) 2015 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.uml.profile.elementtypesconfigurations.generator.tests;

import static org.eclipse.papyrus.junit.matchers.MoreMatchers.isEmpty;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;

import org.eclipse.papyrus.infra.elementtypesconfigurations.IconEntry;
import org.eclipse.papyrus.infra.elementtypesconfigurations.SpecializationTypeConfiguration;
import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
import org.eclipse.papyrus.junit.utils.rules.PluginResource;
import org.eclipse.papyrus.uml.tools.elementtypesconfigurations.applystereotypeadviceconfiguration.ApplyStereotypeAdviceConfiguration;
import org.eclipse.papyrus.uml.tools.elementtypesconfigurations.stereotypeapplicationmatcherconfiguration.StereotypeApplicationMatcherConfiguration;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.edit.UMLEditPlugin;
import org.eclipse.xtext.xbase.lib.Pair;
import org.junit.ClassRule;
import org.junit.Test;

/**
 * Test cases for element types generation for UML profiles that have nested packages and profiles.
 */
@PluginResource("/resources/nesting.profile.uml")
public class ProfilesWithPackageNestingTest extends AbstractPapyrusTest {

	@ClassRule
	public static final ModelGenFixture fixture = new ModelGenFixture();

	public ProfilesWithPackageNestingTest() {
		super();
	}

	@Test
	public void elementTypesGenerated() {
		Pair<Stereotype, Class> s11Class = fixture.getMetaclassExtension("S1_1", "Class");
		Pair<Stereotype, Class> s21Class = fixture.getMetaclassExtension("S2_1", "Class");
		Pair<Stereotype, Class> s12Generalization = fixture.getMetaclassExtension("S1_2", "Generalization");
		Pair<Stereotype, Class> s22Generalization = fixture.getMetaclassExtension("S2_2", "Generalization");
		fixture.assertSpecializationType(s11Class);
		fixture.assertSpecializationType(s21Class);
		fixture.assertSpecializationType(s12Generalization);
		fixture.assertSpecializationType(s22Generalization);
	}

	@Test
	public void iconGenerated() {
		Pair<Stereotype, Class> s11Class = fixture.getMetaclassExtension("S1_1", "Class");
		Pair<Stereotype, Class> s21Class = fixture.getMetaclassExtension("S2_1", "Class");
		Pair<Stereotype, Class> s12Generalization = fixture.getMetaclassExtension("S1_2", "Generalization");
		Pair<Stereotype, Class> s22Generalization = fixture.getMetaclassExtension("S2_2", "Generalization");

		SpecializationTypeConfiguration type = fixture.assertSpecializationType(s11Class);
		IconEntry icon = type.getIconEntry();
		assertThat(icon.getBundleId(), is(UMLEditPlugin.getPlugin().getSymbolicName()));
		assertThat(icon.getIconPath(), containsString("obj16/Class.gif"));

		type = fixture.assertSpecializationType(s21Class);
		icon = type.getIconEntry();
		assertThat(icon.getBundleId(), is(UMLEditPlugin.getPlugin().getSymbolicName()));
		assertThat(icon.getIconPath(), containsString("obj16/Class.gif"));

		type = fixture.assertSpecializationType(s12Generalization);
		icon = type.getIconEntry();
		assertThat(icon.getBundleId(), is(UMLEditPlugin.getPlugin().getSymbolicName()));
		assertThat(icon.getIconPath(), containsString("obj16/Generalization.gif"));

		type = fixture.assertSpecializationType(s22Generalization);
		icon = type.getIconEntry();
		assertThat(icon.getBundleId(), is(UMLEditPlugin.getPlugin().getSymbolicName()));
		assertThat(icon.getIconPath(), containsString("obj16/Generalization.gif"));
	}

	@Test
	public void stereotypeMatcherGenerated() {
		Pair<Stereotype, Class> s11Class = fixture.getMetaclassExtension("S1_1", "Class");
		Pair<Stereotype, Class> s21Class = fixture.getMetaclassExtension("S2_1", "Class");
		Pair<Stereotype, Class> s12Generalization = fixture.getMetaclassExtension("S1_2", "Generalization");
		Pair<Stereotype, Class> s22Generalization = fixture.getMetaclassExtension("S2_2", "Generalization");

		SpecializationTypeConfiguration type = fixture.assertSpecializationType(s11Class);
		StereotypeApplicationMatcherConfiguration matcher = fixture.assertStereotypeMatcher(type);
		assertThat(matcher.getStereotypesQualifiedNames(), hasItem("root::nestedProfile::S1_1"));

		type = fixture.assertSpecializationType(s21Class);
		matcher = fixture.assertStereotypeMatcher(type);
		assertThat(matcher.getStereotypesQualifiedNames(), hasItem("root::nestedPackage::S2_1"));

		type = fixture.assertSpecializationType(s12Generalization);
		matcher = fixture.assertStereotypeMatcher(type);
		assertThat(matcher.getStereotypesQualifiedNames(), hasItem("root::nestedProfile::S1_2"));

		type = fixture.assertSpecializationType(s22Generalization);
		matcher = fixture.assertStereotypeMatcher(type);
		assertThat(matcher.getStereotypesQualifiedNames(), hasItem("root::nestedPackage::S2_2"));
	}

	@Test
	public void stereotypeAdviceGenerated() {
		Pair<Stereotype, Class> s11Class = fixture.getMetaclassExtension("S1_1", "Class");
		Pair<Stereotype, Class> s21Class = fixture.getMetaclassExtension("S2_1", "Class");
		Pair<Stereotype, Class> s12Generalization = fixture.getMetaclassExtension("S1_2", "Generalization");
		Pair<Stereotype, Class> s22Generalization = fixture.getMetaclassExtension("S2_2", "Generalization");

		ApplyStereotypeAdviceConfiguration advice = fixture.assertApplyStereotypeAdvice(s11Class);
		assertThat(advice.getTarget(), is(fixture.getElementTypeConfiguration(s11Class)));
		assertThat(advice.getStereotypesToApply(), not(isEmpty()));
		assertThat(advice.getStereotypesToApply().get(0).getRequiredProfiles(), hasItem("root::nestedProfile"));
		assertThat(advice.getStereotypesToApply().get(0).getStereotypeQualifiedName(), is("root::nestedProfile::S1_1"));

		advice = fixture.assertApplyStereotypeAdvice(s12Generalization);
		assertThat(advice.getTarget(), is(fixture.getElementTypeConfiguration(s12Generalization)));
		assertThat(advice.getStereotypesToApply(), not(isEmpty()));
		assertThat(advice.getStereotypesToApply().get(0).getRequiredProfiles(), hasItem("root::nestedProfile"));
		assertThat(advice.getStereotypesToApply().get(0).getStereotypeQualifiedName(), is("root::nestedProfile::S1_2"));

		advice = fixture.assertApplyStereotypeAdvice(s21Class);
		assertThat(advice.getTarget(), is(fixture.getElementTypeConfiguration(s21Class)));
		assertThat(advice.getStereotypesToApply(), not(isEmpty()));
		assertThat(advice.getStereotypesToApply().get(0).getRequiredProfiles(), hasItem("root"));
		assertThat(advice.getStereotypesToApply().get(0).getStereotypeQualifiedName(), is("root::nestedPackage::S2_1"));

		advice = fixture.assertApplyStereotypeAdvice(s22Generalization);
		assertThat(advice.getTarget(), is(fixture.getElementTypeConfiguration(s22Generalization)));
		assertThat(advice.getStereotypesToApply(), not(isEmpty()));
		assertThat(advice.getStereotypesToApply().get(0).getRequiredProfiles(), hasItem("root"));
		assertThat(advice.getStereotypesToApply().get(0).getStereotypeQualifiedName(), is("root::nestedPackage::S2_2"));
	}
}

Back to the top