-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathSysMLAccessTest.java
More file actions
94 lines (75 loc) · 3.13 KB
/
SysMLAccessTest.java
File metadata and controls
94 lines (75 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package org.omg.sysml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.ecore.resource.Resource;
import org.junit.Test;
import org.omg.sysml.lang.sysml.Element;
import org.omg.sysml.xtext.util.SysMLAccess;
import org.omg.sysml.xtext.util.SysMLParseResult;
public class SysMLAccessTest {
private final static String SYSML_LIBRARY_PATH_KEY = "libraryPath";
public String getLibraryPath() {
return System.getProperty(SYSML_LIBRARY_PATH_KEY);
}
@Test
public void testReadLibrary() throws IOException {
SysMLAccess sysmlAccess = SysMLAccess.createFullyFeatured(getLibraryPath());
sysmlAccess.setVerbose(false);
sysmlAccess.loadLibrary();
Set<Resource> libraryResources = sysmlAccess.getLibraryResources();
assertTrue("Libray was not loaded", !libraryResources.isEmpty());
}
@Test
public void testResolution() throws IOException {
SysMLAccess sysmlAccess = SysMLAccess.createFullyFeatured(getLibraryPath());
sysmlAccess.setVerbose(false);
sysmlAccess.loadLibrary();
Element element = sysmlAccess.resolve("$::Parts::parts");
assertNotNull(element);
assertEquals("Parts::parts", element.getQualifiedName());
}
@Test
public void testParsing() throws IOException {
SysMLAccess sysmlAccess = SysMLAccess.createFullyFeatured(getLibraryPath());
sysmlAccess.setVerbose(false);
sysmlAccess.loadLibrary();
SysMLParseResult result = sysmlAccess.parse("myres.sysml", "package P { part b; }");
assertTrue(result.getIssues().isEmpty());
}
@Test
public void testParsingWithError() throws IOException {
SysMLAccess sysmlAccess = SysMLAccess.createFullyFeatured(getLibraryPath());
sysmlAccess.setVerbose(false);
sysmlAccess.loadLibrary();
SysMLParseResult result = sysmlAccess.parse("myres.sysml", "package P { part b; ");
assertFalse(result.getSyntaxErrors().isEmpty());
}
@Test
public void testParseFile() throws IOException, URISyntaxException {
SysMLAccess sysmlAccess = SysMLAccess.createFullyFeatured(getLibraryPath());
sysmlAccess.setVerbose(false);
sysmlAccess.loadLibrary();
URL testFileURL = getClass().getResource("parseTest.sysml");
File testFile = new File(testFileURL.toURI());
List<SysMLParseResult> results = sysmlAccess.parseFiles(testFile, true);
assertTrue(results.getFirst().getSyntaxErrors().isEmpty());
}
@Test
public void testParseFileWithError() throws IOException, URISyntaxException {
SysMLAccess sysmlAccess = SysMLAccess.createFullyFeatured(getLibraryPath());
sysmlAccess.setVerbose(false);
sysmlAccess.loadLibrary();
URL testFileURL = getClass().getResource("parseTestWithError.sysml");
File testFile = new File(testFileURL.toURI());
List<SysMLParseResult> results = sysmlAccess.parseFiles(testFile, true);
assertFalse(results.getFirst().getSyntaxErrors().isEmpty());
}
}