|
14 | 14 |
|
15 | 15 | import static org.assertj.core.api.Assertions.assertThat; |
16 | 16 | import static org.junit.Assert.assertNotNull; |
| 17 | +import static org.junit.Assert.assertNull; |
17 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; |
18 | 19 |
|
19 | 20 | import java.io.IOException; |
|
27 | 28 | import org.eclipse.syson.sysml.ConjugatedPortDefinition; |
28 | 29 | import org.eclipse.syson.sysml.Feature; |
29 | 30 | import org.eclipse.syson.sysml.Membership; |
| 31 | +import org.eclipse.syson.sysml.PartUsage; |
30 | 32 | import org.eclipse.syson.sysml.PortDefinition; |
31 | 33 | import org.eclipse.syson.sysml.PortUsage; |
| 34 | +import org.eclipse.syson.sysml.Redefinition; |
32 | 35 | import org.eclipse.syson.sysml.ReferenceUsage; |
| 36 | +import org.eclipse.syson.sysml.Specialization; |
33 | 37 | import org.eclipse.syson.sysml.SuccessionAsUsage; |
| 38 | +import org.eclipse.syson.sysml.Type; |
34 | 39 | import org.eclipse.syson.sysml.helper.EMFUtils; |
35 | 40 | import org.eclipse.syson.sysml.upload.SysMLExternalResourceLoaderService; |
36 | 41 | import org.junit.jupiter.api.BeforeEach; |
@@ -65,6 +70,91 @@ public void setUp() { |
65 | 70 | this.checker = new SysMLv2SemanticImportChecker(this.sysmlResourceLoader, this.editingDomainFactory, this.sysMLEditingContextProcessor); |
66 | 71 | } |
67 | 72 |
|
| 73 | + @Test |
| 74 | + @DisplayName("Given a model with duplicated names, when importing the model, then the resolution of name shoud match the closest matching element") |
| 75 | + public void checkNameResolutionProcessWithDuplicatedName() throws IOException { |
| 76 | + var input = """ |
| 77 | + package p1 { |
| 78 | + part pa1 { |
| 79 | + part pa11 :> pa1; |
| 80 | + part pa1; |
| 81 | + } |
| 82 | + }"""; |
| 83 | + |
| 84 | + this.checker.checkImportedModel(resource -> { |
| 85 | + PartUsage pa11 = EMFUtils.allContainedObjectOfType(resource, PartUsage.class) |
| 86 | + .filter(pa -> "pa11".equals(pa.getDeclaredName())) |
| 87 | + .findFirst().get(); |
| 88 | + |
| 89 | + assertThat(pa11.getOwnedSpecialization()).hasSize(1); |
| 90 | + |
| 91 | + Specialization specialization = pa11.getOwnedSpecialization().get(0); |
| 92 | + |
| 93 | + Type general = specialization.getGeneral(); |
| 94 | + |
| 95 | + assertNotNull(general); |
| 96 | + assertThat(general.getQualifiedName()).isEqualTo("p1::pa1::pa1"); // And not "p1::pa1" |
| 97 | + |
| 98 | + }).check(input); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + @DisplayName("Given a model with a Redefintion, when importing the model, then the resolution of name should special Redefinition rules") |
| 103 | + public void checkNameResolutionProcessInRedifinition() throws IOException { |
| 104 | + var input = """ |
| 105 | + package p1 { |
| 106 | + part pa2 :> pa0 { |
| 107 | + part pa11 :>> pa1; |
| 108 | + } |
| 109 | + part pa0 { |
| 110 | + part pa1; |
| 111 | + } |
| 112 | + }"""; |
| 113 | + |
| 114 | + this.checker.checkImportedModel(resource -> { |
| 115 | + PartUsage pa11 = EMFUtils.allContainedObjectOfType(resource, PartUsage.class) |
| 116 | + .filter(pa -> "pa11".equals(pa.getDeclaredName())) |
| 117 | + .findFirst().get(); |
| 118 | + |
| 119 | + assertThat(pa11.getOwnedRedefinition()).hasSize(1); |
| 120 | + |
| 121 | + Redefinition redefinition = pa11.getOwnedRedefinition().get(0); |
| 122 | + |
| 123 | + Feature redefinedFeature = redefinition.getRedefinedFeature(); |
| 124 | + |
| 125 | + assertNotNull(redefinedFeature); |
| 126 | + assertThat(redefinedFeature.getQualifiedName()).isEqualTo("p1::pa0::pa1"); |
| 127 | + |
| 128 | + }).check(input); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + @DisplayName("Given a model with a reference to an invalid type, when importing the model then the resolution of name shoud not set a reference with an incompatible target") |
| 133 | + public void checkNameResolutionProcessWithInvalidTargetName() throws IOException { |
| 134 | + var input = """ |
| 135 | + package p1 { |
| 136 | + part pa1 { |
| 137 | + part pa11 :> pa1; // <-- 'pa1' resolve to the Package "pa1" in the current namespace. This model is not valid. |
| 138 | + package pa1; |
| 139 | + } |
| 140 | + }"""; |
| 141 | + |
| 142 | + this.checker.checkImportedModel(resource -> { |
| 143 | + PartUsage pa11 = EMFUtils.allContainedObjectOfType(resource, PartUsage.class) |
| 144 | + .filter(pa -> "pa11".equals(pa.getDeclaredName())) |
| 145 | + .findFirst().get(); |
| 146 | + |
| 147 | + assertThat(pa11.getOwnedSpecialization()).hasSize(1); |
| 148 | + |
| 149 | + Specialization specialization = pa11.getOwnedSpecialization().get(0); |
| 150 | + |
| 151 | + Type general = specialization.getGeneral(); |
| 152 | + |
| 153 | + assertNull(general); |
| 154 | + |
| 155 | + }).check(input); |
| 156 | + } |
| 157 | + |
68 | 158 | @Test |
69 | 159 | @DisplayName("Given a model with PortDefinitions, when importing the model, then a conjugated port is create for each conjugated ports") |
70 | 160 | public void checkConjugatedPortCreation() throws IOException { |
|
0 commit comments