27
27
import java .util .function .Function ;
28
28
import java .util .stream .Collectors ;
29
29
30
+ import org .eclipse .esmf .aspectmodel .resolver .FileSystemStrategy ;
31
+ import org .eclipse .esmf .aspectmodel .resolver .ResolutionStrategy ;
30
32
import org .eclipse .esmf .metamodel .AbstractEntity ;
31
33
import org .eclipse .esmf .metamodel .AspectModel ;
32
34
import org .eclipse .esmf .metamodel .ComplexType ;
35
+ import org .eclipse .esmf .samm .KnownVersion ;
33
36
import org .eclipse .esmf .test .TestAspect ;
34
37
import org .eclipse .esmf .test .TestResources ;
35
38
@@ -51,9 +54,8 @@ void testOfAbstractEntityCyclomaticCreation() {
51
54
}
52
55
53
56
@ Test
54
- void testLoadAspectModelFromZipArchiveFile () throws URISyntaxException {
55
- final ClassLoader classLoader = getClass ().getClassLoader ();
56
- final Path archivePath = Paths .get ( classLoader .getResource ( "namespaces.zip" ).toURI () );
57
+ void testLoadAspectModelFromZipArchiveFile () {
58
+ final Path archivePath = getPackage ( "namespaces.zip" );
57
59
final AspectModel aspectModel = new AspectModelLoader ().loadNamespacePackage ( new File ( archivePath .toString () ) );
58
60
59
61
assertThat ( aspectModel .namespaces () ).hasSize ( 2 );
@@ -70,9 +72,8 @@ void testLoadAspectModelFromZipArchiveFile() throws URISyntaxException {
70
72
}
71
73
72
74
@ Test
73
- void testLoadAspectModelFromZipArchiveInputStream () throws URISyntaxException , FileNotFoundException {
74
- final ClassLoader classLoader = getClass ().getClassLoader ();
75
- final Path archivePath = Paths .get ( classLoader .getResource ( "namespaces.zip" ).toURI () );
75
+ void testLoadAspectModelFromZipArchiveInputStream () throws FileNotFoundException {
76
+ final Path archivePath = getPackage ( "namespaces.zip" );
76
77
final AspectModel aspectModel = new AspectModelLoader ().loadNamespacePackage ( new FileInputStream ( archivePath .toString () ) );
77
78
78
79
assertThat ( aspectModel .namespaces () ).hasSize ( 2 );
@@ -92,9 +93,8 @@ void testLoadAspectModelFromZipArchiveInputStream() throws URISyntaxException, F
92
93
* Test migration to the latest version of Aspect Model in Archive
93
94
*/
94
95
@ Test
95
- void testLoadAspectModelFromZipArchive2_0_0 () throws URISyntaxException , FileNotFoundException {
96
- final ClassLoader classLoader = getClass ().getClassLoader ();
97
- final Path archivePath = Paths .get ( classLoader .getResource ( "namespaces_with_old_version.zip" ).toURI () );
96
+ void testLoadAspectModelFromZipArchive2_0_0 () throws FileNotFoundException {
97
+ final Path archivePath = getPackage ( "namespaces_with_old_version.zip" );
98
98
final AspectModel aspectModel = new AspectModelLoader ().loadNamespacePackage ( new FileInputStream ( archivePath .toString () ) );
99
99
100
100
assertThat ( aspectModel .namespaces () ).hasSize ( 2 );
@@ -109,4 +109,77 @@ void testLoadAspectModelFromZipArchive2_0_0() throws URISyntaxException, FileNot
109
109
assertThat ( aspectsNames ).contains ( aspectModelFile .aspect ().getName () );
110
110
} );
111
111
}
112
+
113
+ @ Test
114
+ void testLoadAspectModelFromZipArchiveAspectModelsRoot () throws FileNotFoundException {
115
+ final Path archivePath = getPackage ( "namespaces-aspect-models-root.zip" );
116
+ final AspectModel aspectModel = new AspectModelLoader ().loadNamespacePackage ( new FileInputStream ( archivePath .toString () ) );
117
+
118
+ assertThat ( aspectModel .namespaces () ).hasSize ( 2 );
119
+ assertThat ( aspectModel .namespaces ().get ( 0 ).getName () ).contains ( "urn:samm:org.eclipse.examples:1.1.0" );
120
+ assertThat ( aspectModel .namespaces ().get ( 1 ).getName () ).contains ( "urn:samm:org.eclipse.examples:1.0.0" );
121
+
122
+ final List <String > aspectsNames = List .of ( "Movement2" , "Movement3" , "Movement" , "SimpleAspect" );
123
+
124
+ assertThat ( aspectModel .files () ).hasSize ( 4 );
125
+ assertThat ( aspectModel .files () )
126
+ .anySatisfy ( aspectModelFile -> {
127
+ assertThat ( aspectsNames ).contains ( aspectModelFile .aspect ().getName () );
128
+ } );
129
+ }
130
+
131
+ @ Test
132
+ void testLoadAspectModelFromZipArchiveAspectModelsSubfolder () throws FileNotFoundException {
133
+ final Path archivePath = getPackage ( "namespaces-aspect-models-subfolder.zip" );
134
+ final AspectModel aspectModel = new AspectModelLoader ().loadNamespacePackage ( new FileInputStream ( archivePath .toString () ) );
135
+
136
+ assertThat ( aspectModel .namespaces () ).hasSize ( 2 );
137
+ assertThat ( aspectModel .namespaces ().get ( 0 ).getName () ).contains ( "urn:samm:org.eclipse.examples:1.1.0" );
138
+ assertThat ( aspectModel .namespaces ().get ( 1 ).getName () ).contains ( "urn:samm:org.eclipse.examples:1.0.0" );
139
+
140
+ final List <String > aspectsNames = List .of ( "Movement2" , "Movement3" , "Movement" , "SimpleAspect" );
141
+
142
+ assertThat ( aspectModel .files () ).hasSize ( 4 );
143
+ assertThat ( aspectModel .files () )
144
+ .anySatisfy ( aspectModelFile -> {
145
+ assertThat ( aspectsNames ).contains ( aspectModelFile .aspect ().getName () );
146
+ } );
147
+ }
148
+
149
+ @ Test
150
+ void testLoadAspectModelFromZipArchiveWithSharedProperty () throws FileNotFoundException , URISyntaxException {
151
+ final Path archivePath = getPackage ( "namespace-with-shared-property.zip" );
152
+
153
+ final File aspectModelsRootDirectory = new File (
154
+ AspectModelLoaderTest .class .getClassLoader ()
155
+ .getResource ( KnownVersion .getLatest ().toString ().toLowerCase () )
156
+ .toURI ().getPath () );
157
+
158
+ final ResolutionStrategy urnStrategy = new FileSystemStrategy ( aspectModelsRootDirectory .toPath () );
159
+
160
+ final AspectModel aspectModel = new AspectModelLoader ( urnStrategy ).loadNamespacePackage (
161
+ new FileInputStream ( archivePath .toString () ) );
162
+
163
+ assertThat ( aspectModel .namespaces () ).hasSize ( 1 );
164
+ assertThat ( aspectModel .namespaces ().get ( 0 ).getName () ).contains ( "urn:samm:org.eclipse.esmf.test:1.0.0" );
165
+
166
+ final List <String > aspectsNames = List .of ( "Movement" );
167
+
168
+ assertThat ( aspectModel .files () ).hasSize ( 2 );
169
+ assertThat ( aspectModel .files () )
170
+ .anySatisfy ( aspectModelFile -> {
171
+ if ( !aspectModelFile .aspects ().isEmpty () ) {
172
+ assertThat ( aspectsNames ).contains ( aspectModelFile .aspect ().getName () );
173
+ }
174
+ } );
175
+ }
176
+
177
+ /**
178
+ * Returns the File object for a test model file
179
+ */
180
+ private Path getPackage ( final String packageName ) {
181
+ return Paths .get ( String .format (
182
+ "%s/../../core/esmf-test-aspect-models/src/main/resources/packages/%s" ,
183
+ System .getProperty ( "user.dir" ), packageName ) );
184
+ }
112
185
}
0 commit comments