12
12
*/
13
13
package io .openmanufacturing .sds .aspectmodel .aas ;
14
14
15
+ import static org .assertj .core .api .Assertions .assertThat ;
15
16
import static org .junit .jupiter .api .Assertions .*;
16
17
17
18
import java .io .ByteArrayInputStream ;
18
19
import java .io .ByteArrayOutputStream ;
19
20
import java .io .IOException ;
20
- import java .nio .file .Files ;
21
- import java .nio .file .Path ;
22
21
import java .util .List ;
23
22
import java .util .Map ;
24
23
import java .util .Set ;
25
24
import java .util .stream .Collectors ;
26
25
26
+ import org .assertj .core .api .InstanceOfAssertFactories ;
27
27
import org .eclipse .digitaltwin .aas4j .v3 .dataformat .DeserializationException ;
28
28
import org .eclipse .digitaltwin .aas4j .v3 .dataformat .xml .XmlDeserializer ;
29
29
import org .eclipse .digitaltwin .aas4j .v3 .model .ConceptDescription ;
30
30
import org .eclipse .digitaltwin .aas4j .v3 .model .DataSpecificationIEC61360 ;
31
31
import org .eclipse .digitaltwin .aas4j .v3 .model .DataTypeDefXsd ;
32
32
import org .eclipse .digitaltwin .aas4j .v3 .model .EmbeddedDataSpecification ;
33
33
import org .eclipse .digitaltwin .aas4j .v3 .model .Environment ;
34
+ import org .eclipse .digitaltwin .aas4j .v3 .model .LangString ;
35
+ import org .eclipse .digitaltwin .aas4j .v3 .model .MultiLanguageProperty ;
34
36
import org .eclipse .digitaltwin .aas4j .v3 .model .Property ;
35
37
import org .eclipse .digitaltwin .aas4j .v3 .model .SubmodelElement ;
36
38
import org .eclipse .digitaltwin .aas4j .v3 .model .SubmodelElementCollection ;
@@ -53,13 +55,71 @@ class AspectModelAASGeneratorTest {
53
55
AspectModelAASGenerator generator = new AspectModelAASGenerator ();
54
56
55
57
@ Test
56
- void testGenerateXmlFromBammAspectWithSimpleProperty () throws IOException , DeserializationException {
57
- //getAssetAdministrationShellFromAspectWithData( TestAspect.ASPECT_WITH_PROPERTY );
58
- //getAssetAdministrationShellFromAspectWithData( TestAspect.ASPECT_WITH_ENTITY );
59
- //getAssetAdministrationShellFromAspectWithData( TestAspect.ASPECT_WITH_NESTED_ENTITY );
60
- //getAssetAdministrationShellFromAspectWithData( TestAspect.ASPECT_WITH_ENTITY_LIST );
61
- //getAssetAdministrationShellFromAspectWithData( TestAspect.ASPECT_WITH_COLLECTION_OF_SIMPLE_TYPE );
62
- getAssetAdministrationShellFromAspectWithData ( TestAspect .ASPECT_WITH_NESTED_ENTITY_LIST );
58
+ void generateAasxWithAspectDataForMultilanguageText () throws IOException , DeserializationException {
59
+ final Environment env = getAssetAdministrationShellFromAspectWithData ( TestAspect .ASPECT_WITH_MULTI_LANGUAGE_TEXT );
60
+ assertThat ( env .getSubmodels () )
61
+ .singleElement ()
62
+ .satisfies ( subModel -> {
63
+ assertThat ( subModel .getSubmodelElements () )
64
+ .singleElement ()
65
+ .satisfies ( property -> {
66
+ assertThat ( property ).asInstanceOf ( InstanceOfAssertFactories .type ( MultiLanguageProperty .class ) )
67
+ .extracting ( mlp -> mlp .getValue () )
68
+ .asList ()
69
+ .hasSize ( 2 )
70
+ .allSatisfy ( langString -> {
71
+ List .of ( "en" , "de" ).contains ( ((LangString ) langString ).getLanguage () );
72
+ } );
73
+ } );
74
+ } );
75
+ }
76
+
77
+ @ Test
78
+ void generateAasxWithAspectDataForEitherWithEntity () throws IOException , DeserializationException {
79
+ final Environment env = getAssetAdministrationShellFromAspectWithData ( TestAspect .ASPECT_WITH_EITHER_WITH_COMPLEX_TYPES );
80
+ assertThat ( env .getSubmodels () )
81
+ .singleElement ()
82
+ .satisfies ( subModel -> {
83
+ assertThat ( subModel .getSubmodelElements () )
84
+ .anySatisfy ( sme -> {
85
+ assertThat ( sme ).asInstanceOf ( InstanceOfAssertFactories .type ( SubmodelElementList .class ) )
86
+ .extracting ( smel -> smel .getValue () )
87
+ .asList ()
88
+ .anySatisfy ( entity -> {
89
+ assertThat ( entity ).asInstanceOf ( InstanceOfAssertFactories .type ( SubmodelElementCollection .class ) )
90
+ .extracting ( smec -> smec .getValue () )
91
+ .asList ()
92
+ .singleElement ( InstanceOfAssertFactories .type ( Property .class ) )
93
+ .extracting ( entityProperty -> entityProperty .getValue () )
94
+ .isEqualTo ( "The result" );
95
+ } );
96
+ } );
97
+ } );
98
+ }
99
+
100
+ @ Test
101
+ void generateAasxWithAspectDataForNestedEntityLists () throws IOException , DeserializationException {
102
+ final Environment env = getAssetAdministrationShellFromAspectWithData ( TestAspect .ASPECT_WITH_NESTED_ENTITY_LIST );
103
+ assertThat ( env .getSubmodels () )
104
+ .singleElement ()
105
+ .satisfies ( subModel -> {
106
+ assertThat ( subModel .getSubmodelElements () )
107
+ .anySatisfy ( sme -> {
108
+ assertThat ( sme ).asInstanceOf ( InstanceOfAssertFactories .type ( SubmodelElementList .class ) )
109
+ .extracting ( smel -> smel .getValue () )
110
+ .asList ()
111
+ .anySatisfy ( entity -> {
112
+ assertThat ( entity ).asInstanceOf ( InstanceOfAssertFactories .type ( SubmodelElementCollection .class ) )
113
+ .extracting ( smec -> smec .getValue () )
114
+ .asList ()
115
+ .anySatisfy ( property -> {
116
+ assertThat ( property ).asInstanceOf ( InstanceOfAssertFactories .type ( Property .class ) )
117
+ .extracting ( Property ::getValue )
118
+ .isEqualTo ( "2.25" );
119
+ } );
120
+ } );
121
+ } );
122
+ } );
63
123
}
64
124
65
125
@ Test
@@ -269,8 +329,6 @@ private Environment getAssetAdministrationShellFromAspect( final TestAspect test
269
329
throws DeserializationException , IOException {
270
330
final Aspect aspect = loadAspect ( testAspect );
271
331
final ByteArrayOutputStream out = generator .generateXmlOutput ( aspect );
272
- //final ByteArrayOutputStream out1 = generator.generateAasxOutput( aspect );
273
- //Files.write( Path.of( testAspect.getName() + ".aasx" ), out1.toByteArray() );
274
332
return loadAASX ( out , testAspect );
275
333
}
276
334
@@ -295,7 +353,6 @@ private Environment loadAASX( final ByteArrayOutputStream byteStream, final Test
295
353
throws DeserializationException , IOException {
296
354
final XmlDeserializer deserializer = new XmlDeserializer ();
297
355
final var data = byteStream .toByteArray ();
298
- Files .write ( Path .of ( testAspect .getName () + ".xml" ), data );
299
356
return deserializer .read ( new ByteArrayInputStream ( data ) );
300
357
}
301
358
}
0 commit comments