|
23 | 23 |
|
24 | 24 | import static org.junit.Assert.assertEquals; |
25 | 25 | import static org.junit.Assert.assertFalse; |
| 26 | +import static org.junit.Assert.assertNull; |
26 | 27 | import static org.junit.Assert.assertTrue; |
27 | 28 |
|
28 | 29 | import java.util.List; |
29 | 30 |
|
30 | 31 | import org.junit.Test; |
31 | 32 | import org.omg.sysml.interactive.SysMLInteractive; |
| 33 | +import org.omg.sysml.interactive.SysMLInteractiveResult; |
32 | 34 | import org.omg.sysml.lang.sysml.AcceptActionUsage; |
33 | 35 | import org.omg.sysml.lang.sysml.ActionUsage; |
34 | 36 | import org.omg.sysml.lang.sysml.AttributeUsage; |
|
37 | 39 | import org.omg.sysml.lang.sysml.Expression; |
38 | 40 | import org.omg.sysml.lang.sysml.ItemUsage; |
39 | 41 | import org.omg.sysml.lang.sysml.Namespace; |
| 42 | +import org.omg.sysml.lang.sysml.Relationship; |
40 | 43 | import org.omg.sysml.lang.sysml.TriggerInvocationExpression; |
41 | 44 | import org.omg.sysml.lang.sysml.Usage; |
42 | 45 | import org.omg.sysml.lang.sysml.ViewUsage; |
43 | 46 |
|
44 | | -public class DerivedPropertyTest extends SysMLInteractiveTest { |
| 47 | +public class DerivedPropertyAndOperationTest extends SysMLInteractiveTest { |
45 | 48 |
|
46 | 49 | @Test |
47 | 50 | public void testOwnedUsage() throws Exception { |
@@ -86,5 +89,87 @@ public void testViewExpose() throws Exception { |
86 | 89 | List<Element> exposed = view.getExposedElement(); |
87 | 90 | assertEquals(1, exposed.size()); |
88 | 91 | } |
| 92 | + |
| 93 | + public final String qualifiedNameTest = |
| 94 | + "package Test {\n" |
| 95 | + + " package P {\n" |
| 96 | + + " item x;\n" |
| 97 | + + " item x;\n" |
| 98 | + + " }" |
| 99 | + + "}"; |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testQualifiedName() throws Exception { |
| 103 | + SysMLInteractive instance = getSysMLInteractiveInstance(); |
| 104 | + SysMLInteractiveResult result = instance.process(qualifiedNameTest); |
| 105 | + Element root = result.getRootElement(); |
| 106 | + List<Element> elements = ((Namespace)root).getOwnedMember(); |
| 107 | + Namespace P = (Namespace)((Namespace)elements.get(0)).getOwnedMember().get(0); |
| 108 | + List<Element> P_ownedMembers = P.getOwnedMember(); |
| 109 | + assertEquals("Test::P::x", P_ownedMembers.get(0).getQualifiedName()); |
| 110 | + assertNull(P_ownedMembers.get(1).getQualifiedName()); |
| 111 | + } |
| 112 | + |
| 113 | + public final String pathTest = |
| 114 | + "// Path of package: TopLevel\n" |
| 115 | + + "// Path of owning membership: TopLevel/owningMembership\n" |
| 116 | + + "package TopLevel {\n" |
| 117 | + + "\n" |
| 118 | + + " // Path of classifier: TopLevel::A\n" |
| 119 | + + " // Path of owning membership: TopLevel::A/owningMembership\n" |
| 120 | + + " part def A;\n" |
| 121 | + + "\n" |
| 122 | + + " // Path of classifier: TopLevel::B\n" |
| 123 | + + " // Path of owning membership: TopLevel::B/owningMembership\n" |
| 124 | + + " // Path of owned subclassification: TopLevel::B/1\n" |
| 125 | + + " part def B specializes A {\n" |
| 126 | + + " // Path of owning membership: TopLevel::B/2\n" |
| 127 | + + " // Path of feature: TopLevel::B/2/1\n" |
| 128 | + + " ref;\n" |
| 129 | + + " }\n" |
| 130 | + + "\n" |
| 131 | + + " // Path of owning membership: TopLevel/3\n" |
| 132 | + + " // Path of classifier: TopLevel/3/1\n" |
| 133 | + + " part def {\n" |
| 134 | + + " // Path of owning membership: TopLevel/3/1/1\n" |
| 135 | + + " // Path of feature: TopLevel/3/1/1/1\n" |
| 136 | + + " ref f;\n" |
| 137 | + + " }\n" |
| 138 | + + "}"; |
| 139 | + |
| 140 | + @Test |
| 141 | + public void testPathOperation() throws Exception { |
| 142 | + SysMLInteractive instance = getSysMLInteractiveInstance(); |
| 143 | + List<Element> elements = process(instance, pathTest); |
| 144 | + |
| 145 | + Namespace TopLevel = (Namespace)elements.get(0); |
| 146 | + assertEquals("TopLevel", TopLevel.path()); |
| 147 | + assertEquals("TopLevel/owningMembership", TopLevel.getOwningMembership().path()); |
| 148 | + |
| 149 | + Namespace A = (Namespace)TopLevel.getOwnedMember().get(0); |
| 150 | + assertEquals("TopLevel::A", A.path()); |
| 151 | + assertEquals("TopLevel::A/owningMembership", A.getOwningMembership().path()); |
| 152 | + |
| 153 | + Namespace B = (Namespace)TopLevel.getOwnedMember().get(1); |
| 154 | + assertEquals("TopLevel::B", B.path()); |
| 155 | + assertEquals("TopLevel::B/owningMembership", B.getOwningMembership().path()); |
| 156 | + |
| 157 | + Relationship B_1 = B.getOwnedRelationship().get(0); |
| 158 | + assertEquals("TopLevel::B/1", B_1.path()); |
| 159 | + |
| 160 | + Relationship B_2 = B.getOwnedRelationship().get(1); |
| 161 | + assertEquals("TopLevel::B/2", B_2.path()); |
| 162 | + assertEquals("TopLevel::B/2/1", B_2.getOwnedRelatedElement().get(0).path()); |
| 163 | + |
| 164 | + Relationship TopLevel_3 = TopLevel.getOwnedRelationship().get(2); |
| 165 | + assertEquals("TopLevel/3", TopLevel_3.path()); |
| 166 | + |
| 167 | + Element TopLevel_3_1 = TopLevel_3.getOwnedRelatedElement().get(0); |
| 168 | + assertEquals("TopLevel/3/1", TopLevel_3_1.path()); |
| 169 | + |
| 170 | + Relationship TopLevel_3_1_1 = TopLevel_3_1.getOwnedRelationship().get(0); |
| 171 | + assertEquals("TopLevel/3/1/1", TopLevel_3_1_1.path()); |
| 172 | + assertEquals("TopLevel/3/1/1/1", TopLevel_3_1_1.getOwnedRelatedElement().get(0).path()); |
| 173 | + } |
89 | 174 |
|
90 | 175 | } |
0 commit comments