|
1 | 1 | /** |
2 | 2 | * SysML 2 Pilot Implementation |
3 | | - * Copyright (C) 2024 Model Driven Solutions, Inc. |
| 3 | + * Copyright (C) 2024-2025 Model Driven Solutions, Inc. |
4 | 4 | * |
5 | 5 | * This program is free software: you can redistribute it and/or modify |
6 | 6 | * it under the terms of the GNU Lesser General Public License as published by |
|
19 | 19 | * |
20 | 20 | * Contributors: |
21 | 21 | * Laszlo Gati, MDS |
| 22 | + * Ed Seidewitz, MDS |
22 | 23 | */ |
23 | 24 | package org.omg.sysml.semantics.tests; |
24 | 25 |
|
| 26 | +import static org.junit.Assert.assertTrue; |
| 27 | + |
| 28 | +import org.eclipse.emf.ecore.EClass; |
| 29 | +import org.eclipse.emf.ecore.EClassifier; |
25 | 30 | import org.junit.Ignore; |
26 | 31 | import org.junit.Test; |
| 32 | +import org.omg.sysml.lang.sysml.Element; |
| 33 | +import org.omg.sysml.lang.sysml.StateUsage; |
| 34 | +import org.omg.sysml.lang.sysml.SysMLFactory; |
| 35 | +import org.omg.sysml.lang.sysml.SysMLPackage; |
| 36 | +import org.omg.sysml.lang.sysml.TransitionUsage; |
| 37 | +import org.omg.sysml.lang.sysml.Type; |
| 38 | +import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil; |
| 39 | +import org.omg.sysml.util.ElementUtil; |
| 40 | +import org.omg.sysml.util.NamespaceUtil; |
| 41 | +import org.omg.sysml.util.TypeUtil; |
27 | 42 |
|
28 | 43 | /** |
29 | 44 | * Semantic constraint tests for "Implied Definition Subclassification Relationships" and |
|
33 | 48 | */ |
34 | 49 | public class SysMLSpecializationSpecialTest extends SysMLSemanticTest { |
35 | 50 |
|
| 51 | + protected void checkTransitionUsageStateSpecialization(String owningTypeName) { |
| 52 | + //create and add root package |
| 53 | + org.omg.sysml.lang.sysml.Package root = SysMLFactory.eINSTANCE.createPackage(); |
| 54 | + getResource().getContents().add(root); |
| 55 | + |
| 56 | + //check if library element exists |
| 57 | + Element libraryElement = SysMLLibraryUtil.getLibraryElement(root, "States::StateAction::stateTransitions"); |
| 58 | + assertTrue(libraryElement instanceof Type); |
| 59 | + |
| 60 | + //create owning type |
| 61 | + EClassifier ownerEClass = SysMLPackage.eINSTANCE.getEClassifier(owningTypeName); |
| 62 | + Type owner = (Type) SysMLFactory.eINSTANCE.create((EClass) ownerEClass); |
| 63 | + NamespaceUtil.addOwnedMemberTo(root, owner); |
| 64 | + |
| 65 | + //create source state usage |
| 66 | + StateUsage state = SysMLFactory.eINSTANCE.createStateUsage(); |
| 67 | + state.setIsReference(false); |
| 68 | + TypeUtil.addOwnedFeatureTo(owner, state); |
| 69 | + |
| 70 | + //create transition usage |
| 71 | + TransitionUsage transition = SysMLFactory.eINSTANCE.createTransitionUsage(); |
| 72 | + transition.setIsReference(false); |
| 73 | + TypeUtil.addOwnedFeatureTo(owner, transition); |
| 74 | + |
| 75 | + //add source state usage to transition usage |
| 76 | + NamespaceUtil.addMemberTo(transition, state); |
| 77 | + |
| 78 | + //run transformation, add implicit elements |
| 79 | + ElementUtil.transformAll(root, true); |
| 80 | + |
| 81 | + assertTrue(String.format("TransitionUsage specializes stateTransitions instead of %s", getSpecifics(transition)), transition.specializes((Type)libraryElement)); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void checkTransitionUsageStateSpecialization_StateDefinition() { |
| 86 | + checkTransitionUsageStateSpecialization("StateDefinition"); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void checkTransitionUsageStateSpecialization_StateUsage() { |
| 91 | + checkTransitionUsageStateSpecialization("StateUsage"); |
| 92 | + } |
| 93 | + |
36 | 94 | @Test |
37 | 95 | @Ignore("TBD") |
38 | 96 | public void checkLifeClassOccurrenceSpecialization() { |
|
0 commit comments