1212import static org .junit .Assert .assertEquals ;
1313
1414import java .io .IOException ;
15+ import java .util .Collection ;
1516import java .util .Map ;
1617
1718import javax .xml .parsers .ParserConfigurationException ;
2122import org .eclipse .basyx .components .aas .AASServerComponent ;
2223import org .eclipse .basyx .components .aas .configuration .AASServerBackend ;
2324import org .eclipse .basyx .components .aas .configuration .BaSyxAASServerConfiguration ;
25+ import org .eclipse .basyx .components .aas .mongodb .MongoDBAASAPI ;
2426import org .eclipse .basyx .components .aas .mongodb .MongoDBAASAggregator ;
2527import org .eclipse .basyx .components .aas .mongodb .MongoDBSubmodelAPI ;
2628import org .eclipse .basyx .components .configuration .BaSyxContextConfiguration ;
2729import org .eclipse .basyx .components .configuration .BaSyxMongoDBConfiguration ;
2830import org .eclipse .basyx .submodel .metamodel .api .ISubmodel ;
2931import org .eclipse .basyx .submodel .metamodel .api .identifier .IIdentifier ;
3032import org .eclipse .basyx .submodel .metamodel .api .identifier .IdentifierType ;
33+ import org .eclipse .basyx .submodel .metamodel .api .reference .IReference ;
3134import org .eclipse .basyx .submodel .metamodel .map .Submodel ;
3235import org .eclipse .basyx .submodel .metamodel .map .identifier .Identifier ;
3336import org .eclipse .basyx .vab .modelprovider .api .IModelProvider ;
@@ -82,10 +85,8 @@ public void testAddSubmodelPersistency() throws Exception {
8285 createAssetAdministrationShell ();
8386 createSubmodel ();
8487
85- MongoDBSubmodelAPI api = new MongoDBSubmodelAPI (mongoDBConfig , SM_IDENTIFICATION .getId ());
86- ISubmodel persistentSM = api .getSubmodel ();
87-
88- assertEquals (SM_IDSHORT , persistentSM .getIdShort ());
88+ checkIfSubmodelHasBeenPersisted (SM_IDENTIFICATION );
89+ checkSubmodelReferencesSize (1 );
8990 }
9091
9192 @ Test
@@ -99,6 +100,27 @@ public void testAggregatorPersistency() throws Exception {
99100 assertEquals (SM_IDSHORT , persistentSM .getIdShort ());
100101 }
101102
103+ @ Test
104+ public void testDeleteSubmodelPersistency () {
105+ createAssetAdministrationShell ();
106+ createSubmodel ();
107+
108+ deleteSubmodel ();
109+ checkSubmodelReferencesSize (0 );
110+ }
111+
112+ private void checkIfSubmodelHasBeenPersisted (Identifier smIdentification ) {
113+ MongoDBSubmodelAPI smAPI = new MongoDBSubmodelAPI (mongoDBConfig , smIdentification .getId ());
114+ ISubmodel persistentSM = smAPI .getSubmodel ();
115+ assertEquals (SM_IDSHORT , persistentSM .getIdShort ());
116+ }
117+
118+ private void checkSubmodelReferencesSize (int expectedSize ) {
119+ MongoDBAASAPI aasAPI = new MongoDBAASAPI (mongoDBConfig , aasId );
120+ Collection <IReference > submodelReferences = aasAPI .getAAS ().getSubmodelReferences ();
121+ assertEquals (expectedSize , submodelReferences .size ());
122+ }
123+
102124 @ SuppressWarnings ("unchecked" )
103125 private ISubmodel getSubmodelFromAggregator (MongoDBAASAggregator aggregator ) {
104126 IModelProvider aasProvider = aggregator .getAASProvider (new ModelUrn (aasId ));
@@ -112,6 +134,10 @@ private void createSubmodel() {
112134 manager .createSubmodel (new ModelUrn (aasId ), sm );
113135 }
114136
137+ private void deleteSubmodel () {
138+ manager .deleteSubmodel (new ModelUrn (aasId ), SM_IDENTIFICATION );
139+ }
140+
115141 private void createAssetAdministrationShell () {
116142 AssetAdministrationShell shell = new AssetAdministrationShell ();
117143 IIdentifier identifier = new ModelUrn (aasId );
0 commit comments