|
30 | 30 | import org.junit.Ignore; |
31 | 31 | import org.junit.Test; |
32 | 32 | 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; |
33 | 37 | import org.omg.sysml.lang.sysml.StateUsage; |
34 | 38 | import org.omg.sysml.lang.sysml.SysMLFactory; |
35 | 39 | import org.omg.sysml.lang.sysml.SysMLPackage; |
36 | 40 | import org.omg.sysml.lang.sysml.TransitionUsage; |
37 | 41 | import org.omg.sysml.lang.sysml.Type; |
38 | 42 | import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil; |
39 | 43 | import org.omg.sysml.util.ElementUtil; |
| 44 | +import org.omg.sysml.util.FeatureUtil; |
40 | 45 | import org.omg.sysml.util.NamespaceUtil; |
41 | 46 | import org.omg.sysml.util.TypeUtil; |
42 | 47 |
|
@@ -91,6 +96,93 @@ public void checkTransitionUsageStateSpecialization_StateUsage() { |
91 | 96 | checkTransitionUsageStateSpecialization("StateUsage"); |
92 | 97 | } |
93 | 98 |
|
| 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 | + |
94 | 186 | @Test |
95 | 187 | @Ignore("TBD") |
96 | 188 | public void checkUsageVariationUsageSpecialization() { |
|
0 commit comments