Skip to content

Commit 7438411

Browse files
committed
ST6RI-981 Integrated new tests into SysMLInteractiveTest framework.
1 parent 4e5d5af commit 7438411

4 files changed

Lines changed: 49 additions & 140 deletions

File tree

‎org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/ExpressionResultConsultationTest.java‎

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
33
* Copyright (c) 2026 Obeo
4+
* Copyright (c) 2026 Model Driven Solutions, Inc.
45
*
56
* This program and the accompanying materials are made available under the
67
* terms of the Eclipse Public License 2.0 which is available at
@@ -19,8 +20,6 @@
1920

2021
import java.io.ByteArrayInputStream;
2122
import java.io.ByteArrayOutputStream;
22-
import java.nio.file.Path;
23-
import java.util.Collections;
2423
import java.util.List;
2524
import java.util.Map;
2625

@@ -29,11 +28,7 @@
2928
import org.eclipse.emf.ecore.resource.Resource;
3029
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
3130
import org.eclipse.xtext.EcoreUtil2;
32-
import org.junit.After;
33-
import org.junit.BeforeClass;
3431
import org.junit.Test;
35-
import org.omg.sysml.interactive.SysMLInteractive;
36-
import org.omg.sysml.interactive.SysMLInteractiveResult;
3732
import org.omg.sysml.lang.sysml.ConstructorExpression;
3833
import org.omg.sysml.lang.sysml.Element;
3934
import org.omg.sysml.lang.sysml.Expression;
@@ -54,42 +49,7 @@
5449
import org.omg.sysml.xtext.postprocessing.SysMLParserPostProcessorFactory;
5550

5651
/** Tests the semantic contract of expression results across consultation and explicit transformation. */
57-
public class ExpressionResultConsultationTest {
58-
59-
protected static SysMLInteractive interactive;
60-
61-
/** Loads and resolves the standard library once for the textual scenarios. */
62-
@BeforeClass
63-
public static void loadLibraries() {
64-
interactive = SysMLInteractive.createInstance();
65-
interactive.setVerbose(false);
66-
interactive.loadLibrary(Path.of(System.getProperty("libraryPath")).toAbsolutePath().toString());
67-
}
68-
69-
/** Removes each test model while retaining the shared resolved libraries. */
70-
@After
71-
public void removeModels() {
72-
interactive.removeResource();
73-
}
74-
75-
private Resource parse(String name, String text) throws Exception {
76-
interactive.setResource(name);
77-
interactive.parse(text);
78-
Element rootElement = interactive.getRootElement();
79-
SysMLInteractiveResult result = new SysMLInteractiveResult(rootElement, Collections.emptyList());
80-
assertTrue("'" + text + "':\n" + result.formatIssues(), result.getIssues().isEmpty());
81-
return interactive.getResource();
82-
}
83-
84-
private static <T extends Type> T findByName(Resource resource, String name, Class<T> kind) {
85-
for (var contents = resource.getAllContents(); contents.hasNext();) {
86-
var object = contents.next();
87-
if (kind.isInstance(object) && name.equals(kind.cast(object).getDeclaredName())) {
88-
return kind.cast(object);
89-
}
90-
}
91-
throw new AssertionError("Missing " + name);
92-
}
52+
public class ExpressionResultConsultationTest extends SysMLInteractiveTest {
9353

9454
private static <T> T findSingle(Resource resource, Class<T> kind) {
9555
T found = null;

‎org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/FeatureChainConsultationTest.java‎

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
33
* Copyright (c) 2026 Obeo
4+
* Copyright (c) 2026 Model Driven Solutions, Inc.
45
*
56
* This program and the accompanying materials are made available under the
67
* terms of the Eclipse Public License 2.0 which is available at
@@ -20,22 +21,16 @@
2021

2122
import java.io.ByteArrayInputStream;
2223
import java.io.ByteArrayOutputStream;
23-
import java.nio.charset.StandardCharsets;
24-
import java.nio.file.Path;
2524
import java.util.ArrayList;
2625
import java.util.List;
2726
import java.util.Map;
2827

2928
import org.eclipse.emf.common.util.URI;
3029
import org.eclipse.emf.ecore.EObject;
3130
import org.eclipse.emf.ecore.resource.Resource;
32-
import org.eclipse.emf.ecore.resource.ResourceSet;
3331
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
3432
import org.eclipse.xtext.EcoreUtil2;
35-
import org.junit.After;
36-
import org.junit.BeforeClass;
3733
import org.junit.Test;
38-
import org.omg.sysml.interactive.SysMLInteractive;
3934
import org.omg.sysml.lang.sysml.Element;
4035
import org.omg.sysml.lang.sysml.Expression;
4136
import org.omg.sysml.lang.sysml.Feature;
@@ -54,49 +49,7 @@
5449
import org.omg.sysml.xtext.postprocessing.SysMLParserPostProcessorFactory;
5550

5651
/** Characterizes feature-chain structure and semantics across consultation and editing. */
57-
public class FeatureChainConsultationTest {
58-
private static ResourceSet resourceSet;
59-
private final List<Resource> models = new ArrayList<>();
60-
61-
/** Loads and resolves the standard library once for the textual scenarios. */
62-
@BeforeClass
63-
public static void loadLibraries() {
64-
SysMLInteractive interactive = SysMLInteractive.createInstance();
65-
interactive.setVerbose(false);
66-
interactive.getLibraryIndexCache().setIndexDisabled(true);
67-
interactive.loadLibrary(Path.of(System.getProperty("libraryPath")).toAbsolutePath().toString());
68-
resourceSet = interactive.getResourceSet();
69-
for (int i = 0; i < resourceSet.getResources().size(); i++) {
70-
EcoreUtil2.resolveLazyCrossReferences(resourceSet.getResources().get(i), null);
71-
}
72-
}
73-
74-
/** Removes each test model while retaining the shared resolved libraries. */
75-
@After
76-
public void removeModels() {
77-
for (Resource resource : models) {
78-
resource.unload();
79-
resourceSet.getResources().remove(resource);
80-
}
81-
}
82-
83-
private Resource parse(String name, String text) throws Exception {
84-
Resource resource = resourceSet.createResource(URI.createURI("memory:/" + name));
85-
models.add(resource);
86-
resource.load(new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)), Map.of());
87-
assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
88-
return resource;
89-
}
90-
91-
private static <T extends Type> T findByName(Resource resource, String name, Class<T> kind) {
92-
for (var contents = resource.getAllContents(); contents.hasNext();) {
93-
var object = contents.next();
94-
if (kind.isInstance(object) && name.equals(kind.cast(object).getDeclaredName())) {
95-
return kind.cast(object);
96-
}
97-
}
98-
throw new AssertionError("Missing " + name);
99-
}
52+
public class FeatureChainConsultationTest extends SysMLInteractiveTest {
10053

10154
private static <T> T findSingle(Resource resource, Class<T> kind) {
10255
T found = null;
@@ -115,7 +68,6 @@ private static <T> T findSingle(Resource resource, Class<T> kind) {
11568
return found;
11669
}
11770

118-
11971
/**
12072
* A cached textual chain retains its source target, output and argument order
12173
* through queries, cache clearing and repeated materialization.

‎org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/MultiplicityPreparationTest.java‎

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,24 @@
1515
import static org.junit.Assert.assertSame;
1616
import static org.junit.Assert.assertTrue;
1717

18-
import java.nio.file.Path;
1918
import java.util.ArrayList;
20-
import java.util.Collections;
2119
import java.util.List;
2220
import org.eclipse.emf.ecore.EObject;
2321
import org.eclipse.emf.ecore.resource.Resource;
24-
import org.junit.After;
25-
import org.junit.BeforeClass;
2622
import org.junit.Test;
27-
import org.omg.sysml.interactive.SysMLInteractive;
28-
import org.omg.sysml.interactive.SysMLInteractiveResult;
29-
import org.omg.sysml.lang.sysml.Element;
3023
import org.omg.sysml.lang.sysml.Multiplicity;
3124
import org.omg.sysml.lang.sysml.MultiplicityRange;
3225
import org.omg.sysml.lang.sysml.OwningMembership;
3326
import org.omg.sysml.lang.sysml.Relationship;
3427
import org.omg.sysml.lang.sysml.Subsetting;
3528
import org.omg.sysml.lang.sysml.SysMLPackage;
36-
import org.omg.sysml.lang.sysml.Type;
3729
import org.omg.sysml.lang.sysml.Usage;
3830
import org.omg.sysml.util.ElementUtil;
3931
import org.omg.sysml.util.TypeUtil;
4032
import org.omg.sysml.xtext.postprocessing.SysMLParserPostProcessorFactory;
4133

4234
/** Tests the boundary between parser preparation of multiplicities and derived consultation. */
43-
public class MultiplicityPreparationTest {
44-
45-
protected static SysMLInteractive interactive;
46-
47-
/** Loads and resolves the standard library once for the textual test scenarios. */
48-
@BeforeClass
49-
public static void loadLibraries() {
50-
interactive = SysMLInteractive.createInstance();
51-
interactive.setVerbose(false);
52-
interactive.loadLibrary(Path.of(System.getProperty("libraryPath")).toAbsolutePath().toString());
53-
}
54-
55-
/** Removes each test model while retaining the shared resolved libraries. */
56-
@After
57-
public void removeResource() {
58-
interactive.removeResource();
59-
}
35+
public class MultiplicityPreparationTest extends SysMLInteractiveTest {
6036

6137
/**
6238
* Parsing end usages prepares one multiplicity before any feature consultation;
@@ -235,23 +211,4 @@ public void defaultMultiplicityDependsOnKindAndOwner() throws Exception {
235211
}
236212
}
237213

238-
private Resource parse(String name, String text) throws Exception {
239-
interactive.setResource(name);
240-
interactive.parse(text);
241-
Element rootElement = interactive.getRootElement();
242-
SysMLInteractiveResult result = new SysMLInteractiveResult(rootElement, Collections.emptyList());
243-
assertTrue("'" + text + "':\n" + result.formatIssues(), result.getIssues().isEmpty());
244-
return interactive.getResource();
245-
}
246-
247-
private static <T extends Type> T findByName(Resource resource, String name, Class<T> kind) {
248-
for (var contents = resource.getAllContents(); contents.hasNext();) {
249-
EObject object = contents.next();
250-
if (kind.isInstance(object) && name.equals(kind.cast(object).getDeclaredName())) {
251-
return kind.cast(object);
252-
}
253-
}
254-
throw new AssertionError("Missing " + name);
255-
}
256-
257214
}

‎org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/SysMLInteractiveTest.java‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,48 @@
2525

2626
import static org.junit.Assert.assertTrue;
2727

28+
import java.nio.file.Path;
29+
import java.util.Collections;
2830
import java.util.List;
2931

3032
import org.omg.sysml.lang.sysml.Element;
3133
import org.omg.sysml.lang.sysml.Namespace;
34+
import org.omg.sysml.lang.sysml.Type;
35+
import org.eclipse.emf.ecore.EObject;
36+
import org.eclipse.emf.ecore.resource.Resource;
37+
import org.junit.After;
38+
import org.junit.BeforeClass;
3239
import org.omg.sysml.interactive.SysMLInteractive;
3340
import org.omg.sysml.interactive.SysMLInteractiveResult;
3441

3542
public abstract class SysMLInteractiveTest {
3643

3744
private final static String SYSML_LIBRARY_PATH_KEY = "libraryPath";
3845

39-
public String getLibraryPath() {
46+
/** Loads and resolves the standard library once for the textual test scenarios. */
47+
@BeforeClass
48+
public static void loadLibraries() {
49+
createSysMLInteractiveInstance();
50+
}
51+
52+
/** Removes each test model while retaining the shared resolved libraries. */
53+
@After
54+
public void removeResource() {
55+
SysMLInteractive.getInstance().removeResource();
56+
}
57+
58+
public static String getLibraryPath() {
4059
return System.getProperty(SYSML_LIBRARY_PATH_KEY);
4160
}
4261

43-
public SysMLInteractive createSysMLInteractiveInstance() {
62+
public static SysMLInteractive createSysMLInteractiveInstance() {
4463
SysMLInteractive instance = SysMLInteractive.createInstance();
4564
instance.setVerbose(false);
46-
instance.loadLibrary(getLibraryPath());
65+
instance.loadLibrary(Path.of(getLibraryPath()).toAbsolutePath().toString());
4766
return instance;
4867
}
4968

50-
public SysMLInteractive getSysMLInteractiveInstance() {
69+
public static SysMLInteractive getSysMLInteractiveInstance() {
5170
SysMLInteractive instance = SysMLInteractive.getInstance();
5271
instance.setVerbose(false);
5372
instance.loadLibrary(getLibraryPath());
@@ -68,4 +87,25 @@ public List<Element> process(SysMLInteractive instance, String input) {
6887
public List<Element> process(String input) {
6988
return process(null, input);
7089
}
90+
91+
protected Resource parse(String name, String text) throws Exception {
92+
SysMLInteractive interactive = SysMLInteractive.getInstance();
93+
interactive.setResource(name);
94+
interactive.parse(text);
95+
Element rootElement = interactive.getRootElement();
96+
SysMLInteractiveResult result = new SysMLInteractiveResult(rootElement, Collections.emptyList());
97+
assertTrue("'" + text + "':\n" + result.formatIssues(), result.getIssues().isEmpty());
98+
return interactive.getResource();
99+
}
100+
101+
protected static <T extends Type> T findByName(Resource resource, String name, Class<T> kind) {
102+
for (var contents = resource.getAllContents(); contents.hasNext();) {
103+
EObject object = contents.next();
104+
if (kind.isInstance(object) && name.equals(kind.cast(object).getDeclaredName())) {
105+
return kind.cast(object);
106+
}
107+
}
108+
throw new AssertionError("Missing " + name);
109+
}
110+
71111
}

0 commit comments

Comments
 (0)