Skip to content

Commit 847deb7

Browse files
committed
ST6RI-901 Created Junit tests to check object and subobject constraints.
- checkFeatureObjectSpecialization and checkFeatureSubobjectSpecialization for an OccurrenceUsage with a Structure type. - checkFeatureSubobjectSpecialization for a composite PortUsage explicitly typed by a PortDefinition.
1 parent 433a859 commit 847deb7

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

org.omg.sysml.interactive.tests/src/org/omg/sysml/semantics/tests/SysMLSpecializationSpecialTest.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@
3030
import org.junit.Ignore;
3131
import org.junit.Test;
3232
import org.omg.sysml.lang.sysml.Element;
33+
import org.omg.sysml.lang.sysml.ItemDefinition;
34+
import org.omg.sysml.lang.sysml.OccurrenceUsage;
35+
import org.omg.sysml.lang.sysml.PortDefinition;
36+
import org.omg.sysml.lang.sysml.PortUsage;
3337
import org.omg.sysml.lang.sysml.StateUsage;
3438
import org.omg.sysml.lang.sysml.SysMLFactory;
3539
import org.omg.sysml.lang.sysml.SysMLPackage;
3640
import org.omg.sysml.lang.sysml.TransitionUsage;
3741
import org.omg.sysml.lang.sysml.Type;
3842
import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil;
3943
import org.omg.sysml.util.ElementUtil;
44+
import org.omg.sysml.util.FeatureUtil;
4045
import org.omg.sysml.util.NamespaceUtil;
4146
import org.omg.sysml.util.TypeUtil;
4247

@@ -91,6 +96,93 @@ public void checkTransitionUsageStateSpecialization_StateUsage() {
9196
checkTransitionUsageStateSpecialization("StateUsage");
9297
}
9398

99+
@Test
100+
public void checkFeatureObjectSpecialization_OccurrenceUsage() {
101+
//create and add root package
102+
org.omg.sysml.lang.sysml.Package root = SysMLFactory.eINSTANCE.createPackage();
103+
getResource().getContents().add(root);
104+
105+
//check if library element exists
106+
Element libraryElement = SysMLLibraryUtil.getLibraryElement(root, "Objects::objects");
107+
assertTrue(libraryElement instanceof Type);
108+
109+
//create owning package
110+
org.omg.sysml.lang.sysml.Package owner = SysMLFactory.eINSTANCE.createPackage();
111+
NamespaceUtil.addOwnedMemberTo(root, owner);
112+
113+
//create occurrence usage
114+
OccurrenceUsage occurrence = SysMLFactory.eINSTANCE.createOccurrenceUsage();
115+
occurrence.setIsReference(false);
116+
NamespaceUtil.addOwnedMemberTo(owner, occurrence);
117+
118+
//create structure type
119+
ItemDefinition type = SysMLFactory.eINSTANCE.createItemDefinition();
120+
FeatureUtil.addFeatureTypingTo(occurrence).setType(type);
121+
122+
//run transformation, add implicit elements
123+
ElementUtil.transformAll(root, true);
124+
125+
assertTrue(String.format("OccurrenceUsage specializes subobjects instead of %s", getSpecifics(occurrence)), occurrence.specializes((Type)libraryElement));
126+
}
127+
128+
@Test
129+
public void checkFeatureSubobjectSpecialization_OccurrenceUsage() {
130+
//create and add root package
131+
org.omg.sysml.lang.sysml.Package root = SysMLFactory.eINSTANCE.createPackage();
132+
getResource().getContents().add(root);
133+
134+
//check if library element exists
135+
Element libraryElement = SysMLLibraryUtil.getLibraryElement(root, "Objects::Object::subobjects");
136+
assertTrue(libraryElement instanceof Type);
137+
138+
//create owning type
139+
Type owner = (Type) SysMLFactory.eINSTANCE.createItemDefinition();
140+
NamespaceUtil.addOwnedMemberTo(root, owner);
141+
142+
//create occurrence usage
143+
OccurrenceUsage occurrence = SysMLFactory.eINSTANCE.createOccurrenceUsage();
144+
occurrence.setIsReference(false);
145+
TypeUtil.addOwnedFeatureTo(owner, occurrence);
146+
147+
//create structure type
148+
ItemDefinition type = SysMLFactory.eINSTANCE.createItemDefinition();
149+
FeatureUtil.addFeatureTypingTo(occurrence).setType(type);
150+
151+
//run transformation, add implicit elements
152+
ElementUtil.transformAll(root, true);
153+
154+
assertTrue(String.format("OccurrenceUsage specializes subobjects instead of %s", getSpecifics(occurrence)), occurrence.specializes((Type)libraryElement));
155+
}
156+
157+
@Test
158+
public void checkFeatureSubobjectSpecialization_PortUsage() {
159+
//create and add root package
160+
org.omg.sysml.lang.sysml.Package root = SysMLFactory.eINSTANCE.createPackage();
161+
getResource().getContents().add(root);
162+
163+
//check if library element exists
164+
Element libraryElement = SysMLLibraryUtil.getLibraryElement(root, "Objects::Object::subobjects");
165+
assertTrue(libraryElement instanceof Type);
166+
167+
//create owning type
168+
Type owner = (Type) SysMLFactory.eINSTANCE.createPortDefinition();
169+
NamespaceUtil.addOwnedMemberTo(root, owner);
170+
171+
//create occurrence usage
172+
PortUsage occurrence = SysMLFactory.eINSTANCE.createPortUsage();
173+
occurrence.setIsReference(false);
174+
TypeUtil.addOwnedFeatureTo(owner, occurrence);
175+
176+
//create structure type
177+
PortDefinition type = SysMLFactory.eINSTANCE.createPortDefinition();
178+
FeatureUtil.addFeatureTypingTo(occurrence).setType(type);
179+
180+
//run transformation, add implicit elements
181+
ElementUtil.transformAll(root, true);
182+
183+
assertTrue(String.format("OccurrenceUsage specializes subobjects instead of %s", getSpecifics(occurrence)), occurrence.specializes((Type)libraryElement));
184+
}
185+
94186
@Test
95187
@Ignore("TBD")
96188
public void checkUsageVariationUsageSpecialization() {

0 commit comments

Comments
 (0)