Merge "Add code translation to Exception handling"
diff --git a/sdks/java/basys.sdk/src/main/java/org/eclipse/basyx/aas/restapi/AASModelProvider.java b/sdks/java/basys.sdk/src/main/java/org/eclipse/basyx/aas/restapi/AASModelProvider.java
index 778ee82..913be5e 100644
--- a/sdks/java/basys.sdk/src/main/java/org/eclipse/basyx/aas/restapi/AASModelProvider.java
+++ b/sdks/java/basys.sdk/src/main/java/org/eclipse/basyx/aas/restapi/AASModelProvider.java
@@ -86,7 +86,7 @@
 			// => the key either points to the idShort of the submodel or its identifier
 			if ((idType.equals(KeyType.IDSHORT) && idValue.equals(idShort))
 					|| (idType.toString().equals(smId.getIdType().toString()) && idValue.equals(smId.getId()))) {
-				iterator.remove();
+				modelProvider.deleteValue(AssetAdministrationShell.SUBMODELS, ref);
 				break;
 			}
 		}
diff --git a/sdks/java/basys.sdk/src/test/java/org/eclipse/basyx/testsuite/regression/aas/restapi/MultiSubmodelProviderTest.java b/sdks/java/basys.sdk/src/test/java/org/eclipse/basyx/testsuite/regression/aas/restapi/MultiSubmodelProviderTest.java
index 3be5919..206e07b 100644
--- a/sdks/java/basys.sdk/src/test/java/org/eclipse/basyx/testsuite/regression/aas/restapi/MultiSubmodelProviderTest.java
+++ b/sdks/java/basys.sdk/src/test/java/org/eclipse/basyx/testsuite/regression/aas/restapi/MultiSubmodelProviderTest.java
@@ -6,11 +6,15 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
+import java.util.Collection;
 import java.util.Map;
 
+import org.eclipse.basyx.aas.metamodel.connected.ConnectedAssetAdministrationShell;
 import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
 import org.eclipse.basyx.aas.restapi.AASModelProvider;
 import org.eclipse.basyx.aas.restapi.VABMultiSubmodelProvider;
+import org.eclipse.basyx.submodel.metamodel.api.reference.IReference;
+import org.eclipse.basyx.submodel.metamodel.map.SubModel;
 import org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.Property;
 import org.eclipse.basyx.submodel.restapi.SubModelProvider;
 import org.eclipse.basyx.testsuite.regression.submodel.restapi.SimpleAASSubmodel;
@@ -78,12 +82,22 @@
 
 	@Test
 	public void createDeleteTest() {
-		proxy.createValue("/aas/submodels", new SimpleAASSubmodel("TestSM"));
+		SubModel sm = new SimpleAASSubmodel("TestSM");
+		proxy.createValue("/aas/submodels", sm);
 
 		getTestRunner("TestSM");
 
+		// Ensure that the Submodel References where updated
+		ConnectedAssetAdministrationShell shell = new ConnectedAssetAdministrationShell(proxy.getDeepProxy("/aas"), null);
+		Collection<IReference> refs = shell.getSubmodelReferences();
+		assertEquals(1, refs.size());
+		assertEquals(sm.getReference(), refs.iterator().next());
+
 		proxy.deleteValue("/aas/submodels/TestSM");
 
+		// Ensure that the Submodel Reference was removed again
+		assertEquals(0, shell.getSubmodelReferences().size());
+
 		try {
 			proxy.getModelPropertyValue("/aas/submodels/TestSM");
 			fail();