1818import io .adminshell .aas .v3 .dataformat .DeserializationException ;
1919import io .adminshell .aas .v3 .dataformat .aml .AmlDeserializer ;
2020import io .adminshell .aas .v3 .dataformat .aml .fixtures .FullExample ;
21+ import io .adminshell .aas .v3 .dataformat .aml .fixtures .SimpleExample ;
2122import io .adminshell .aas .v3 .dataformat .core .AASFull ;
23+ import io .adminshell .aas .v3 .dataformat .core .AASSimple ;
2224import io .adminshell .aas .v3 .model .*;
2325
2426import java .io .FileNotFoundException ;
2729import java .util .List ;
2830import java .util .stream .Collectors ;
2931
30- import org .junit .Before ;
3132import org .junit .Test ;
3233
3334import static org .junit .Assert .assertEquals ;
@@ -36,18 +37,29 @@ public class AmlDeserializerTest {
3637
3738 private final AmlDeserializer deserializer = new AmlDeserializer ();
3839
39- private AssetAdministrationShellEnvironment actual ;
40- private AssetAdministrationShellEnvironment expected ;
40+ @ Test
41+ public void testSAPFullExample () throws FileNotFoundException , DeserializationException {
42+ AssetAdministrationShellEnvironment actual = deserializer .read (FullExample .FILE );
43+ AssetAdministrationShellEnvironment expected = AASFull .createEnvironment ();
44+ //some changes on the Full Example environment are necessary because there are some constructs inside which are
45+ //not possible with AML due to the mapping specifications
4146
42- @ Before
43- public void init () throws FileNotFoundException , DeserializationException {
44- actual = deserializer .read (FullExample .FILE );
45- expected = AASFull .createEnvironment ();
47+ //remove asset administration shells with no submodels
48+ adaptAssetAdministrationShells (expected );
49+ //remove leveltypes and valuelists from embedded dataspecification
50+ adaptConceptDescriptions (expected );
51+ //remove non referenced submodels
52+ adaptSubmodels (expected );
53+ //swap the idx of two submodels because assertEquals checks also the order of the elements
54+ swapSubmodelIdx (actual , 0 , 2 );
55+ assertEquals (expected , actual );
4656 }
4757
4858 @ Test
49- public void testSAPFullExample () {
50- //some changes on the Full Example environment are necessary because there are some constructs inside which are
59+ public void testSAPSimpleExample () throws FileNotFoundException , DeserializationException {
60+ AssetAdministrationShellEnvironment actual = deserializer .read (SimpleExample .FILE );
61+ AssetAdministrationShellEnvironment expected = AASSimple .createEnvironment ();
62+ //some changes on the Simple Example environment are necessary because there are some constructs inside which are
5163 //not possible with AML due to the mapping specifications
5264
5365 //remove asset administration shells with no submodels
@@ -57,64 +69,82 @@ public void testSAPFullExample() {
5769 //remove non referenced submodels
5870 adaptSubmodels (expected );
5971 //swap the idx of two submodels because assertEquals checks also the order of the elements
60- swapSubmodelIdx (actual ,0 ,2 );
72+ swapSubmodelIdx (expected , 1 , 2 );
73+ // remove assets as they are not part of the current AML specification
74+ removeAssets (expected );
75+ adaptAssetInformation (expected );
6176 assertEquals (expected , actual );
6277 }
6378
6479 @ Test
65- public void testSubmodels () {
80+ public void testSubmodels () throws FileNotFoundException , DeserializationException {
81+ AssetAdministrationShellEnvironment actual = deserializer .read (FullExample .FILE );
82+ AssetAdministrationShellEnvironment expected = AASFull .createEnvironment ();
6683 adaptSubmodels (expected );
67- swapSubmodelIdx (actual , 0 ,2 );
68- assertEquals (expected .getSubmodels (),actual .getSubmodels ());
84+ swapSubmodelIdx (actual , 0 , 2 );
85+ assertEquals (expected .getSubmodels (), actual .getSubmodels ());
6986 }
7087
71- private void swapSubmodelIdx (AssetAdministrationShellEnvironment env , int idxSrc , int idxDest ){
72- Collections .swap (env .getSubmodels (),idxSrc ,idxDest );
88+ private void swapSubmodelIdx (AssetAdministrationShellEnvironment env , int idxSrc , int idxDest ) {
89+ Collections .swap (env .getSubmodels (), idxSrc , idxDest );
90+ }
91+
92+ private void adaptAssetInformation (AssetAdministrationShellEnvironment env ) {
93+ // remove thumbnail as it is not defined in current AML specification
94+ env .getAssetAdministrationShells ().forEach (x -> x .getAssetInformation ().setDefaultThumbnail (null ));
7395 }
7496
7597 private void adaptSubmodels (AssetAdministrationShellEnvironment env ) {
7698 //non referenced submodels are not considered in AML
7799 List <String > submodelIds = new ArrayList <>();
78100 env .getAssetAdministrationShells ().stream ().forEach (
79101 x -> x .getSubmodels ().stream ()
80- .forEach (y -> y .getKeys ().stream ().forEach (z ->submodelIds .add (z .getValue ()))));
102+ .forEach (y -> y .getKeys ().stream ().forEach (z -> submodelIds .add (z .getValue ()))));
81103
82104 List <Submodel > referencedSubmodels = env .getSubmodels ().stream ().filter (x -> submodelIds .contains (x .getIdentification ().getIdentifier ())).collect (Collectors .toList ());
83105 env .setSubmodels (referencedSubmodels );
84106 }
85107
108+ private void removeAssets (AssetAdministrationShellEnvironment env ) {
109+ env .getAssets ().clear ();
110+ }
111+
86112 @ Test
87- public void testAssetAdministrationShells () {
113+ public void testAssetAdministrationShells () throws FileNotFoundException , DeserializationException {
114+ AssetAdministrationShellEnvironment actual = deserializer .read (FullExample .FILE );
115+ AssetAdministrationShellEnvironment expected = AASFull .createEnvironment ();
88116 adaptAssetAdministrationShells (expected );
89117 assertEquals (expected .getAssetAdministrationShells (), actual .getAssetAdministrationShells ());
90118 }
91119
92- private void adaptAssetAdministrationShells (AssetAdministrationShellEnvironment env ){
120+ private void adaptAssetAdministrationShells (AssetAdministrationShellEnvironment env ) {
93121 //Need to remove Asset Administration Shell which have no Submodels
94122 //they are not considered in AML due to the specification
95123 List <AssetAdministrationShell > nonEmptyShells = new ArrayList <>();
96- for (AssetAdministrationShell aas : env .getAssetAdministrationShells ()){
97- if (aas .getSubmodels () != null && aas .getSubmodels ().size () > 0 ){
124+ for (AssetAdministrationShell aas : env .getAssetAdministrationShells ()) {
125+ if (aas .getSubmodels () != null && aas .getSubmodels ().size () > 0 ) {
98126 nonEmptyShells .add (aas );
99127 }
100128 }
101129 env .setAssetAdministrationShells (nonEmptyShells );
102130 }
103131
104132 @ Test
105- public void testConceptDescriptions () {
133+ public void testConceptDescriptions () throws FileNotFoundException , DeserializationException {
134+ AssetAdministrationShellEnvironment actual = deserializer .read (FullExample .FILE );
135+ AssetAdministrationShellEnvironment expected = AASFull .createEnvironment ();
106136 //Need to remove Level Types and Value Lists from embedded dataspecification
107137 //they are not considered in AML due to the specification
108138 adaptConceptDescriptions (expected );
109139 assertEquals (expected .getConceptDescriptions (), actual .getConceptDescriptions ());
110140 }
111141
112- private void adaptConceptDescriptions (AssetAdministrationShellEnvironment env ){
142+ private void adaptConceptDescriptions (AssetAdministrationShellEnvironment env ) {
113143 List <ConceptDescription > expectedConceptDescriptions = env .getConceptDescriptions ();
114- for (ConceptDescription c : expectedConceptDescriptions ){
115- for (EmbeddedDataSpecification embeddedDataSpecification : c .getEmbeddedDataSpecifications ()){
116- ((DataSpecificationIEC61360 )embeddedDataSpecification .getDataSpecificationContent ()).setLevelTypes (new ArrayList <>());
117- ((DataSpecificationIEC61360 )embeddedDataSpecification .getDataSpecificationContent ()).setValueList (null );
144+ for (ConceptDescription c : expectedConceptDescriptions ) {
145+ for (EmbeddedDataSpecification embeddedDataSpecification : c .getEmbeddedDataSpecifications ()) {
146+ ((DataSpecificationIEC61360 ) embeddedDataSpecification .getDataSpecificationContent ()).setLevelTypes (new ArrayList <>());
147+ ((DataSpecificationIEC61360 ) embeddedDataSpecification .getDataSpecificationContent ()).setValueList (null );
118148 }
119149 }
120150
0 commit comments