Adds new Snippets to Examples
Adds new Snippets and their tests to the Examples project
Signed-off-by: Maximilian Conradi <maximilian.conradi@iese.fraunhofer.de>
Change-Id: Ie85619dcfeb2f696109a5046fb40f14145fd6639
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/AddSubmodelToAAS.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/AddSubmodelToAAS.java
new file mode 100644
index 0000000..62bfe8f
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/AddSubmodelToAAS.java
@@ -0,0 +1,40 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.map.SubModel;
+
+/**
+ * This snippet showcases how to add a Submodel to an AAS,
+ * that already exists on a server
+ *
+ * @author conradi
+ *
+ */
+public class AddSubmodelToAAS {
+
+ /**
+ * Adds a Submodel to an AAS and registers it
+ *
+ * @param submodel the Submodel to be added
+ * @param aasIdentifier the Identifier of the AAS the Submodel should be added to
+ * @param registryServerURL the URL of the registry server
+ */
+ public static void addSubmodelToAAS(SubModel submodel, IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Create a proxy pointing to the registry server
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Create a ConnectedAASManager using the registryProxy as its registry
+ ConnectedAssetAdministrationShellManager manager =
+ new ConnectedAssetAdministrationShellManager(registryProxy);
+
+ // Add the submodel to the AAS using the ConnectedAASManager
+ // The manager pushes the submodel to the server and registers it
+ // For this to work, the Identification of the Submodel has to be set
+ manager.createSubModel(aasIdentifier, submodel);
+
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/DeleteAAS.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/DeleteAAS.java
new file mode 100644
index 0000000..b79efdf
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/DeleteAAS.java
@@ -0,0 +1,34 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+
+/**
+ * Snippet that showcases how to delete an AAS from a server
+ *
+ * @author conradi
+ *
+ */
+public class DeleteAAS {
+
+ /**
+ * Removes an AAS from the server
+ *
+ * @param aasIdentifier the Identifier of the AAS to be deleted
+ * @param registryServerURL the URL of the registry server (e.g. http://localhost:8080/registry)
+ */
+ public static void deleteAAS(IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Create a proxy pointing to the registry server
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Create a ConnectedAASManager using the registryProxy as its registry
+ ConnectedAssetAdministrationShellManager manager =
+ new ConnectedAssetAdministrationShellManager(registryProxy);
+
+ // Delete the AAS
+ // Automatically deregisters it
+ manager.deleteAAS(aasIdentifier);
+ }
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/DeleteSubmodelFromAAS.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/DeleteSubmodelFromAAS.java
new file mode 100644
index 0000000..a6e0809
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/DeleteSubmodelFromAAS.java
@@ -0,0 +1,35 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+
+/**
+ * Snippet that showcases how to delete a Submodel from a server
+ *
+ * @author conradi
+ *
+ */
+public class DeleteSubmodelFromAAS {
+
+ /**
+ * Removes a Submodel from an AAS
+ *
+ * @param smIdentifier the Identifier of the Submodel to be deleted
+ * @param aasIdentifier the Identifier of the AAS the Submodel belongs to
+ * @param registryServerURL the URL of the registry server (e.g. http://localhost:8080/registry)
+ */
+ public static void deleteSubmodelFromAAS(IIdentifier smIdentifier, IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Create a proxy pointing to the registry server
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Create a ConnectedAASManager using the registryProxy as its registry
+ ConnectedAssetAdministrationShellManager manager =
+ new ConnectedAssetAdministrationShellManager(registryProxy);
+
+ // Delete the Submodel
+ // Automatically deregisters it
+ manager.deleteSubModel(aasIdentifier, smIdentifier);
+ }
+}
\ No newline at end of file
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/LookupAAS.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/LookupAAS.java
new file mode 100644
index 0000000..e7ed77c
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/LookupAAS.java
@@ -0,0 +1,31 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import org.eclipse.basyx.aas.metamodel.map.descriptor.AASDescriptor;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+
+/**
+ * Snippet that showcases how to look up an AAS in a RegistryComponent
+ *
+ * @author conradi
+ *
+ */
+public class LookupAAS {
+
+ /**
+ * Gets the Descriptor of the requested AAS from a registry
+ *
+ * @param aasIdentifier the Identifier of the AAS to be looked up in the registry
+ * @param registryServerURL the URL of the registry server
+ * @return the AASDescriptor looked up in the registry
+ */
+ public static AASDescriptor lookupAAS(IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Create a proxy pointing to the registry
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Lookup the AAS in the registry
+ return registryProxy.lookupAAS(aasIdentifier);
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/PushAASToServer.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/PushAASToServer.java
new file mode 100644
index 0000000..7a78f28
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/PushAASToServer.java
@@ -0,0 +1,37 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+
+
+/**
+ * This snippet showcases how to push a AAS to a server
+ *
+ * @author conradi
+ *
+ */
+public class PushAASToServer {
+
+ /**
+ * Pushes the AAS to a server and registers it
+ *
+ * @param aas the AssetAdministrationShell to be pushed to the server
+ * @param aasServerURL the URL of the aas server (e.g. http://localhost:8080/aasComponent)
+ * @param registryServerURL the URL of the registry server (e.g. http://localhost:8080/registry)
+ */
+ public static void pushAAS(AssetAdministrationShell aas, String aasServerURL, String registryServerURL) {
+
+ // Create a proxy pointing to the registry server
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Create a ConnectedAASManager using the registryProxy as its registry
+ ConnectedAssetAdministrationShellManager manager =
+ new ConnectedAssetAdministrationShellManager(registryProxy);
+
+ // The ConnectedAASManager automatically pushes the given AAS
+ // to the server to which the address was given
+ // It also registers the AAS in the registry it got in its ctor
+ manager.createAAS(aas, aasServerURL);
+ }
+}
\ No newline at end of file
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RegisterAAS.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RegisterAAS.java
new file mode 100644
index 0000000..02e96b3
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RegisterAAS.java
@@ -0,0 +1,34 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import org.eclipse.basyx.aas.metamodel.api.IAssetAdministrationShell;
+import org.eclipse.basyx.aas.metamodel.map.descriptor.AASDescriptor;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+
+/**
+ * Snippet that showcases how to register a given AAS in a RegistryComponent
+ *
+ * @author conradi
+ *
+ */
+public class RegisterAAS {
+
+ /**
+ * Registers a given AssetAdministrationShell in a registry.
+ *
+ * @param aas the AssetAdministrationShell to be registered
+ * @param aasEndpoint the address where the AAS will be hosted (e.g. http://localhost:8080/aasList/{aasId}/aas)
+ * @param registryServerURL the address of the registry
+ */
+ public static void registerAAS(IAssetAdministrationShell aas, String aasEndpoint, String registryServerURL) {
+
+ // Create a proxy pointing to the registry
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Create a Descriptor for the AAS using the endpoint where it will be hosted
+ AASDescriptor descriptor = new AASDescriptor(aas, aasEndpoint);
+
+ // Register this Descriptor in the registry
+ registryProxy.register(descriptor);
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RetrieveRemoteAAS.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RetrieveRemoteAAS.java
new file mode 100644
index 0000000..d50c408
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RetrieveRemoteAAS.java
@@ -0,0 +1,36 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.metamodel.api.IAssetAdministrationShell;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+
+/**
+ * This snippet showcases how to retrieve an AAS from a server
+ *
+ * @author conradi
+ *
+ */
+public class RetrieveRemoteAAS {
+
+ /**
+ * Get an AAS from a server
+ *
+ * @param aasIdentifier the Identifier of the requested AAS
+ * @param registryServerURL the URL of the registry server
+ * @return The requested AAS as ConnectedAAS
+ */
+ public static IAssetAdministrationShell retrieveRemoteAAS(IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Create a proxy pointing to the registry server
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Create a ConnectedAASManager using the registryProxy as its registry
+ ConnectedAssetAdministrationShellManager manager =
+ new ConnectedAssetAdministrationShellManager(registryProxy);
+
+ // Get the requested AAS from the manager
+ return manager.retrieveAAS(aasIdentifier);
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RetrieveSubmodelFromAAS.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RetrieveSubmodelFromAAS.java
new file mode 100644
index 0000000..1404875
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/aas/RetrieveSubmodelFromAAS.java
@@ -0,0 +1,38 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+
+
+/**
+ * This snippet showcases how to retrieve a Submodel from a AAS on a server
+ *
+ * @author conradi
+ *
+ */
+public class RetrieveSubmodelFromAAS {
+
+ /**
+ * Gets a Submodel from an AAS
+ *
+ * @param smIdentifier the Identifier of the requested Submodel
+ * @param aasIdentifier the Identifier of the AAS the Submodel belongs to
+ * @param registryServerURL the URL of the registry server
+ * @return the requested Submodel as ConnectedSubModel
+ */
+ public static ISubModel retrieveSubmodelFromAAS(IIdentifier smIdentifier, IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Create a proxy pointing to the registry server
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Create a ConnectedAASManager using the registryProxy as its registry
+ ConnectedAssetAdministrationShellManager manager =
+ new ConnectedAssetAdministrationShellManager(registryProxy);
+
+ // Get the requested Submodel from the ConnectedAASManager using the Identifiers of the AAS and the SM
+ return manager.retrieveSubModel(aasIdentifier, smIdentifier);
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/AddSubmodelElement.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/AddSubmodelElement.java
new file mode 100644
index 0000000..a33e08d
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/AddSubmodelElement.java
@@ -0,0 +1,35 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import org.eclipse.basyx.examples.snippets.aas.RetrieveSubmodelFromAAS;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.map.submodelelement.SubmodelElement;
+
+/**
+ * This snippet showcases how add to a SubmodelElement to a Submodel,
+ * that already exists on a server
+ *
+ * @author conradi
+ *
+ */
+public class AddSubmodelElement {
+
+ /**
+ * Adds a SubmodelElement to a remote Submodel
+ *
+ * @param smElement the SubmodelElement to be added
+ * @param smIdentifier the Identifier of the Submodel the element should be added to
+ * @param aasIdentifier the Identifier of the AAS the Submodel belongs to
+ * @param registryServerURL the URL of the registry server
+ */
+ public static void addSubmodelElement(SubmodelElement smElement, IIdentifier smIdentifier, IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Get the ConnectedSubmodel
+ ISubModel submodel = RetrieveSubmodelFromAAS.retrieveSubmodelFromAAS(smIdentifier, aasIdentifier, registryServerURL);
+
+ // Add the element to it
+ submodel.addSubModelElement(smElement);
+
+ }
+
+}
\ No newline at end of file
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/DeleteSubmodelElement.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/DeleteSubmodelElement.java
new file mode 100644
index 0000000..8e31408
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/DeleteSubmodelElement.java
@@ -0,0 +1,31 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import org.eclipse.basyx.examples.snippets.aas.RetrieveSubmodelFromAAS;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+
+/**
+ * Snippet that showcases how to delete a SubmodelElement from a Submodel
+ *
+ * @author conradi
+ *
+ */
+public class DeleteSubmodelElement {
+
+ /**
+ * Removes a SubmodelElement from a Submodel
+ *
+ * @param elementId the Id of the Element to be deleted (can also be a path if the Element is in a Collection)
+ * @param smIdentifier the Identifier of the Submodel the Element belongs to
+ * @param aasIdentifier the Identifier of the AAS the Submodel belongs to
+ * @param registryServerURL the URL of the registry server (e.g. http://localhost:8080/registry)
+ */
+ public static void deleteSubmodelElement(String elementId, IIdentifier smIdentifier, IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Retrieve the Submodel from the server as a ConnectedSubmodel
+ ISubModel submodel = RetrieveSubmodelFromAAS.retrieveSubmodelFromAAS(smIdentifier, aasIdentifier, registryServerURL);
+
+ // Delete the Element from the Submodel
+ submodel.deleteSubmodelElement(elementId);
+ }
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/ExecuteOperation.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/ExecuteOperation.java
new file mode 100644
index 0000000..74d5774
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/ExecuteOperation.java
@@ -0,0 +1,45 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement;
+import org.eclipse.basyx.submodel.metamodel.api.submodelelement.operation.IOperation;
+
+/**
+ * Snippet that showcases how to execute an Operation contained in a Submodel
+ *
+ * @author conradi
+ *
+ */
+public class ExecuteOperation {
+
+ /**
+ * Executes an Operation with the given parameters and return the result.
+ * The execution itself is run on the remote server
+ *
+ * @param operationId the idShort of the Operation to be executed
+ * @param operationParameters the parameters for the execution
+ * @param smIdentifier the Identifier of the Submodel the Operation belongs to
+ * @param aasIdentifier the Identifier of the AAS the Submodel belongs to
+ * @param registryServerURL the URL of the registry server
+ * @return the result of the execution
+ * @throws Exception thrown if the execution of the Operation threw an Exception
+ */
+ public static Object executeOperation(String operationId, Object[] operationParameters, IIdentifier smIdentifier, IIdentifier aasIdentifier, String registryServerURL) throws Exception {
+
+ // Get the Operation from the Submodel
+ ISubmodelElement element = RetrieveSubmodelElement.retrieveSubmodelElement(operationId, smIdentifier, aasIdentifier, registryServerURL);
+
+ // Check if the element is really an Operation
+ if( ! (element instanceof IOperation)) {
+ // The element with the given Id is not an Operation
+ throw new IllegalArgumentException("The SubmodelElement '" + operationId + "' is not an Operation");
+ }
+
+ // Cast the retrieved ISubmodelElement to an IOperation
+ IOperation operation = (IOperation) element;
+
+ // Invoke the Operation and return the Result
+ return operation.invoke(operationParameters);
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/LookupSubmodel.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/LookupSubmodel.java
new file mode 100644
index 0000000..1b3e4f4
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/LookupSubmodel.java
@@ -0,0 +1,32 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import org.eclipse.basyx.aas.metamodel.map.descriptor.SubmodelDescriptor;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+
+/**
+ * Snippet that showcases how to look up a Submodel in a RegistryComponent
+ *
+ * @author conradi
+ *
+ */
+public class LookupSubmodel {
+
+ /**
+ * Gets the Descriptor of the requested Submodel from a registry
+ *
+ * @param smIdentifier the Identifier of the Submodel to be looked up in the registry
+ * @param aasIdentifier the Identifier of the AAS the Submodel belongs to
+ * @param registryServerURL the URL of the registry server
+ * @return the SubmodelDescriptor looked up in the registry
+ */
+ public static SubmodelDescriptor lookupSubmodel(IIdentifier smIdentifier, IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Create a proxy pointing to the registry
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Lookup the Submodel in the registry
+ return registryProxy.lookupSubmodel(aasIdentifier, smIdentifier);
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/RegisterSubmodel.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/RegisterSubmodel.java
new file mode 100644
index 0000000..6c4a751
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/RegisterSubmodel.java
@@ -0,0 +1,35 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import org.eclipse.basyx.aas.metamodel.map.descriptor.SubmodelDescriptor;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+
+/**
+ * Snippet that showcases how to register a given Submodel in a RegistryComponent
+ *
+ * @author conradi
+ *
+ */
+public class RegisterSubmodel {
+
+ /**
+ * Registers a given Submodel in a registry.
+ *
+ * @param submodel the Submodel to be registered
+ * @param smEndpoint the address where the SM will be hosted (e.g. http://localhost:8080/aasList/{aasId}/aas/submodels/{smId})
+ * @param registryServerURL the address of the registry
+ */
+ public static void registerSubmodel(ISubModel submodel, String smEndpoint, IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Create a proxy pointing to the registry
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryServerURL);
+
+ // Create a Descriptor for the sm using the endpoint where it will be hosted
+ SubmodelDescriptor descriptor = new SubmodelDescriptor(submodel, smEndpoint);
+
+ // Register this Descriptor in the registry
+ registryProxy.register(aasIdentifier, descriptor);
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/RetrieveSubmodelElement.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/RetrieveSubmodelElement.java
new file mode 100644
index 0000000..cfce36e
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/snippets/submodel/RetrieveSubmodelElement.java
@@ -0,0 +1,34 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import org.eclipse.basyx.examples.snippets.aas.RetrieveSubmodelFromAAS;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement;
+
+/**
+ * This snippet showcases how to retrieve a SubmodelElement from a remote Submodel
+ *
+ * @author conradi
+ *
+ */
+public class RetrieveSubmodelElement {
+
+ /**
+ * Gets a SubmodelElement from a remote Submodel
+ *
+ * @param elementId the idShort SubmodelElement to be retrieved
+ * @param smIdentifier the Identifier of the Submodel the element belongs to
+ * @param aasIdentifier the Identifier of the AAS the Submodel belongs to
+ * @param registryServerURL the URL of the registry server
+ * @return the requested SubmodelElement
+ */
+ public static ISubmodelElement retrieveSubmodelElement(String elementId, IIdentifier smIdentifier, IIdentifier aasIdentifier, String registryServerURL) {
+
+ // Get the ConnectedSubmodel
+ ISubModel submodel = RetrieveSubmodelFromAAS.retrieveSubmodelFromAAS(smIdentifier, aasIdentifier, registryServerURL);
+
+ // Add the element to it
+ return submodel.getSubmodelElement(elementId);
+
+ }
+}
\ No newline at end of file
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleAASComponent.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleAASComponent.java
new file mode 100644
index 0000000..4260956
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleAASComponent.java
@@ -0,0 +1,53 @@
+package org.eclipse.basyx.examples.support;
+
+import org.eclipse.basyx.aas.registration.api.IAASRegistryService;
+import org.eclipse.basyx.components.aas.AASServerComponent;
+import org.eclipse.basyx.components.configuration.BaSyxContextConfiguration;
+
+/**
+ * This class is used to startup an AAS-Server using the AASServerComponent
+ *
+ * @author conradi
+ *
+ */
+public class ExampleAASComponent {
+
+ public static final String CONTEXT_PATH = "aasComponent";
+
+ private int port;
+
+ private IAASRegistryService registry;
+
+ // Hold a reference to the server to be able to shut it down
+ private AASServerComponent aasServer = null;
+
+
+ public ExampleAASComponent(int port, IAASRegistryService registry) {
+ this.port = port;
+ this.registry = registry;
+ }
+
+ public void startupAASServer() {
+ // Create a Configuration telling the component the port to use and the contextPath
+ // The contextPath is attached to the address of the server "http://localhost:8080/{contextPath}"
+ BaSyxContextConfiguration contextConfig = new BaSyxContextConfiguration(port, CONTEXT_PATH);
+ aasServer = new AASServerComponent(contextConfig);
+
+ // Set the registry to be used by the server
+ aasServer.setRegistry(registry);
+
+ // Startup the AASServer
+ aasServer.startComponent();
+ }
+
+ public void shutdownAASServer() {
+ // If an AASServer was started -> stop it
+ if(aasServer != null) {
+ aasServer.stopComponent();
+ }
+ }
+
+ public String getAASServerPath() {
+ return "http://localhost:" + port + "/" + CONTEXT_PATH;
+ }
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleComponentBuilder.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleComponentBuilder.java
new file mode 100644
index 0000000..7db04ec
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleComponentBuilder.java
@@ -0,0 +1,75 @@
+package org.eclipse.basyx.examples.support;
+
+import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.SubModel;
+import org.eclipse.basyx.submodel.metamodel.map.submodelelement.SubmodelElementCollection;
+import org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.Property;
+
+/**
+ * This class is used to build AssetAdministrationShells and Submodels
+ * for the scenarios and snippets.
+ *
+ * Please note that the generated objects are just for showcasing,
+ * several mandatory attributes are missing.
+ *
+ * @author conradi
+ *
+ */
+public class ExampleComponentBuilder {
+
+ public static final String PROPERTY_ID = "prop";
+ public static final int PROPERTY_VALUE = 123;
+
+ public static final String COLLECTION_ID = "collection";
+ public static final String COLLECTION_PROPERTY_ID = "propInCollection";
+ public static final String COLLECTION_PROPERTY_VALUE = "TheValue";
+
+ /**
+ * Builds a Submodel containing a Property and a Collection with a Property
+ *
+ * @param idShort the idShort for the new Submodel
+ * @return the new Submodel
+ */
+ public static SubModel buildExampleSubmodel(String idShort, String id) {
+ SubModel submodel = new SubModel();
+ submodel.setIdShort(idShort);
+ submodel.setIdentification(IdentifierType.CUSTOM, id);
+
+ // Add a Property to the Submodel
+ Property property = new Property();
+ property.setIdShort(PROPERTY_ID);
+ property.setValue(PROPERTY_VALUE);
+ submodel.addSubModelElement(property);
+
+ // Add a SubmodelElementCollection
+ SubmodelElementCollection collection = new SubmodelElementCollection();
+ collection.setIdShort(COLLECTION_ID);
+
+ // Add a Property to the SubmodelElementCollection
+ Property property2 = new Property();
+ property2.setIdShort(COLLECTION_PROPERTY_ID);
+ property2.setValue(COLLECTION_PROPERTY_VALUE);
+ collection.addSubModelElement(property2);
+ submodel.addSubModelElement(collection);
+
+ return submodel;
+ }
+
+ /**
+ * Builds an AssetAdministrationShell
+ *
+ * @param idShort the idShort for the new AAS
+ * @param id the id to be used in Identification
+ * @return the new AAS
+ */
+ public static AssetAdministrationShell buildExampleAAS(String idShort, String id) {
+ AssetAdministrationShell aas = new AssetAdministrationShell();
+ aas.setIdShort(idShort);
+
+ aas.setIdentification(IdentifierType.CUSTOM, id);
+
+ return aas;
+ }
+
+}
diff --git a/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleRegistryComponent.java b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleRegistryComponent.java
new file mode 100644
index 0000000..6f6e8a5
--- /dev/null
+++ b/examples/basys.examples/src/main/java/org/eclipse/basyx/examples/support/ExampleRegistryComponent.java
@@ -0,0 +1,53 @@
+package org.eclipse.basyx.examples.support;
+
+import org.eclipse.basyx.components.configuration.BaSyxContextConfiguration;
+import org.eclipse.basyx.components.registry.RegistryComponent;
+import org.eclipse.basyx.components.registry.configuration.BaSyxRegistryConfiguration;
+import org.eclipse.basyx.components.registry.configuration.RegistryBackend;
+
+/**
+ * This class is used to startup a registry using the RegistryComponent
+ *
+ * @author conradi
+ *
+ */
+public class ExampleRegistryComponent {
+
+ public static final String CONTEXT_PATH = "registry";
+
+ private int port;
+
+ // Hold a reference to the server to be able to shut it down
+ private RegistryComponent registry = null;
+
+
+ public ExampleRegistryComponent(int port) {
+ this.port = port;
+ }
+
+
+ public void startupRegistry() {
+ // Create a Configuration telling the component the port to use and the contextPath
+ // The contextPath is attached to the address of the server "http://localhost:8080/{contextPath}"
+ BaSyxContextConfiguration contextConfig = new BaSyxContextConfiguration(port, CONTEXT_PATH);
+
+ // Create a RegistrationConfiguration telling the component to hold the whole registry in memory
+ BaSyxRegistryConfiguration registryConfig = new BaSyxRegistryConfiguration(RegistryBackend.INMEMORY);
+
+ registry = new RegistryComponent(contextConfig, registryConfig);
+
+ // Startup the Registry
+ registry.startComponent();
+ }
+
+ public void shutdownRegistry() {
+ // If a registry was started -> stop it
+ if(registry != null) {
+ registry.stopComponent();
+ }
+ }
+
+ public String getRegistryPath() {
+ return "http://localhost:" + port + "/" + CONTEXT_PATH;
+ }
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/AbstractSnippetTest.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/AbstractSnippetTest.java
new file mode 100644
index 0000000..1a5260c
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/AbstractSnippetTest.java
@@ -0,0 +1,76 @@
+package org.eclipse.basyx.examples.snippets;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.examples.support.ExampleAASComponent;
+import org.eclipse.basyx.examples.support.ExampleComponentBuilder;
+import org.eclipse.basyx.examples.support.ExampleRegistryComponent;
+import org.eclipse.basyx.submodel.metamodel.map.SubModel;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * This class provides the server environment required by all snippet test
+ *
+ * @author conradi
+ *
+ */
+public abstract class AbstractSnippetTest {
+
+
+ protected static final String AAS_ID_SHORT = "aasIdShort";
+ protected static final String AAS_ID = "aasId";
+ protected static final String AAS_ENDPOINT = "http://localhost:8080/aasComponent/shells/" + AAS_ID + "/aas";
+
+ protected static final String SM_ID_SHORT = "smIdShort";
+ protected static final String SM_ID = "smId";
+ protected static final String SM_ENDPOINT = AAS_ENDPOINT + "/submodels/" + SM_ID_SHORT + "/submodel";
+
+ protected ExampleAASComponent aasComponent;
+ protected ExampleRegistryComponent registryComponent;
+
+ @Before
+ public void setupServers() {
+ registryComponent = new ExampleRegistryComponent(8081);
+ registryComponent.startupRegistry();
+ aasComponent = new ExampleAASComponent(8080, new AASRegistryProxy(registryComponent.getRegistryPath()));
+ aasComponent.startupAASServer();
+
+ // Populate the Server with an example AAS/SM
+ populateServer();
+ }
+
+ @After
+ public void shutdownServers() {
+ aasComponent.shutdownAASServer();
+ registryComponent.shutdownRegistry();
+ }
+
+ /**
+ * Pushes and registers an AAS and a Submodel to the test server
+ */
+ private void populateServer() {
+ ConnectedAssetAdministrationShellManager manager = getManager();
+
+ // Get the example AAS and Submodel
+ AssetAdministrationShell aas = ExampleComponentBuilder.buildExampleAAS(AAS_ID_SHORT, AAS_ID);
+ SubModel sm = ExampleComponentBuilder.buildExampleSubmodel(SM_ID_SHORT, SM_ID);
+
+ // Push and register the AAS
+ manager.createAAS(aas, aasComponent.getAASServerPath());
+
+ // Push and register the Submodel
+ manager.createSubModel(aas.getIdentification(), sm);
+ }
+
+ /**
+ * Creates a ConnectedAASManager using the started registryComponent
+ *
+ * @return the created ConnectedAASManager
+ */
+ protected ConnectedAssetAdministrationShellManager getManager() {
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryComponent.getRegistryPath());
+ return new ConnectedAssetAdministrationShellManager(registryProxy);
+ }
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestAddSubmodelToAAS.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestAddSubmodelToAAS.java
new file mode 100644
index 0000000..4ab8821
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestAddSubmodelToAAS.java
@@ -0,0 +1,46 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.examples.support.ExampleComponentBuilder;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.SubModel;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.junit.Test;
+
+/**
+ * Test for the AddSubmodelToAAS snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestAddSubmodelToAAS extends AbstractSnippetTest {
+
+ private static final String NEW_SM_ID_SHORT = "smIdShort_New";
+ private static final String NEW_SM_ID = "smId_New";
+
+ @Test
+ public void testAddSubmodelToAAS() {
+
+ // Get the example AAS and Submodel
+ SubModel submodel = ExampleComponentBuilder.buildExampleSubmodel(NEW_SM_ID_SHORT, NEW_SM_ID);
+
+ // Get the Identifiers for the AAS and the Submodel
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ IIdentifier smIdentifier = submodel.getIdentification();
+
+ // Add the Submodel to the AAS
+ AddSubmodelToAAS.addSubmodelToAAS(submodel, aasIdentifier, registryComponent.getRegistryPath());
+
+ // Check if the Submodel was correctly added
+ ConnectedAssetAdministrationShellManager manager = getManager();
+ ISubModel remoteSM = manager.retrieveSubModel(aasIdentifier, smIdentifier);
+ assertEquals(NEW_SM_ID_SHORT, remoteSM.getIdShort());
+
+ }
+
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestDeleteAAS.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestDeleteAAS.java
new file mode 100644
index 0000000..f3d795f
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestDeleteAAS.java
@@ -0,0 +1,38 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.eclipse.basyx.vab.exception.provider.ResourceNotFoundException;
+import org.junit.Test;
+
+/**
+ * Test for the DeleteAAS snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestDeleteAAS extends AbstractSnippetTest {
+
+ @Test
+ public void testDeleteAAS() {
+
+ // Get the Identifier of the example AAS
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+
+ // Delete the AAS
+ DeleteAAS.deleteAAS(aasIdentifier, registryComponent.getRegistryPath());
+
+ // Try to retrieve deleted AAS; should throw ResourceNotFoundException
+ try {
+ RetrieveRemoteAAS.retrieveRemoteAAS(aasIdentifier, registryComponent.getRegistryPath());
+ fail();
+ } catch (ResourceNotFoundException e) {
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestDeleteSubmodelFromAAS.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestDeleteSubmodelFromAAS.java
new file mode 100644
index 0000000..504c406
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestDeleteSubmodelFromAAS.java
@@ -0,0 +1,40 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.eclipse.basyx.vab.exception.provider.ResourceNotFoundException;
+import org.junit.Test;
+
+/**
+ * Test for the DeleteSubmodelFromAAS snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestDeleteSubmodelFromAAS extends AbstractSnippetTest {
+
+ @Test
+ public void testDeleteSubmodel() {
+
+ // Get the Identifier of the example AAS and Submodel
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ IIdentifier smIdentifier = new Identifier(IdentifierType.CUSTOM, SM_ID);
+
+ // Delete the Submodel
+ DeleteSubmodelFromAAS.deleteSubmodelFromAAS(smIdentifier, aasIdentifier, registryComponent.getRegistryPath());
+
+ // Try to retrieve deleted Submodel; should throw ResourceNotFoundException
+ try {
+ RetrieveSubmodelFromAAS.retrieveSubmodelFromAAS(
+ smIdentifier, aasIdentifier, registryComponent.getRegistryPath());
+ fail();
+ } catch (ResourceNotFoundException e) {
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestLookupAAS.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestLookupAAS.java
new file mode 100644
index 0000000..339a0cc
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestLookupAAS.java
@@ -0,0 +1,34 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.aas.metamodel.map.descriptor.AASDescriptor;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.junit.Test;
+
+/**
+ * Test for the LookupAAS snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestLookupAAS extends AbstractSnippetTest {
+
+ @Test
+ public void testLookupAAS() {
+
+ // Get the Identifier of the example AAS
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+
+ // Lookup the AAS in the registry
+ AASDescriptor descriptor = LookupAAS.lookupAAS(aasIdentifier, registryComponent.getRegistryPath());
+
+ // Check if the returned Descriptor is as expected
+ assertEquals(AAS_ENDPOINT, descriptor.getFirstEndpoint());
+
+ }
+
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestPushAASToServer.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestPushAASToServer.java
new file mode 100644
index 0000000..1b57fd1
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestPushAASToServer.java
@@ -0,0 +1,38 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.metamodel.api.IAssetAdministrationShell;
+import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.examples.support.ExampleComponentBuilder;
+import org.junit.Test;
+
+/**
+ * Test for the PushAASToServer snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestPushAASToServer extends AbstractSnippetTest {
+
+ protected static final String NEW_AAS_ID_SHORT = "aasIdShort_New";
+ protected static final String NEW_AAS_ID = "aasId_New";
+
+ @Test
+ public void testPushAAS() throws Exception {
+
+ // Get the example AAS
+ AssetAdministrationShell aas = ExampleComponentBuilder.buildExampleAAS(NEW_AAS_ID_SHORT, NEW_AAS_ID);
+
+ // Push the AAS to the server
+ PushAASToServer.pushAAS(aas, aasComponent.getAASServerPath(), registryComponent.getRegistryPath());
+
+ // Check if the AAS is present on the server
+ ConnectedAssetAdministrationShellManager manager = getManager();
+ IAssetAdministrationShell remoteAAS = manager.retrieveAAS(aas.getIdentification());
+ assertEquals(NEW_AAS_ID_SHORT, remoteAAS.getIdShort());
+ }
+
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRegisterAAS.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRegisterAAS.java
new file mode 100644
index 0000000..717f533
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRegisterAAS.java
@@ -0,0 +1,40 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
+import org.eclipse.basyx.aas.metamodel.map.descriptor.AASDescriptor;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.examples.support.ExampleComponentBuilder;
+import org.junit.Test;
+
+/**
+ * Test for the RegisterAAS snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestRegisterAAS extends AbstractSnippetTest {
+
+ protected static final String NEW_AAS_ID_SHORT = "aasIdShort_New";
+ protected static final String NEW_AAS_ID = "aasId_New";
+ protected static final String NEW_AAS_ENDPOINT = "http://localhost:8080/aasComponent/shells/" + NEW_AAS_ID + "/aas";
+
+ @Test
+ public void testRegisterAAS() {
+
+ // Get the example AAS
+ AssetAdministrationShell aas = ExampleComponentBuilder.buildExampleAAS(NEW_AAS_ID_SHORT, NEW_AAS_ID);
+
+ // Register this AAS
+ RegisterAAS.registerAAS(aas, NEW_AAS_ENDPOINT, registryComponent.getRegistryPath());
+
+ // Check if the AAS was correctly registered
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryComponent.getRegistryPath());
+ AASDescriptor descriptor = registryProxy.lookupAAS(aas.getIdentification());
+ assertEquals(NEW_AAS_ENDPOINT, descriptor.getFirstEndpoint());
+
+ }
+
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRetrieveRemoteAAS.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRetrieveRemoteAAS.java
new file mode 100644
index 0000000..933eed8
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRetrieveRemoteAAS.java
@@ -0,0 +1,33 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.aas.metamodel.api.IAssetAdministrationShell;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.junit.Test;
+
+/**
+ * Test for the RetrieveRemoteAAS snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestRetrieveRemoteAAS extends AbstractSnippetTest {
+
+ @Test
+ public void testRetrieveRemoteAAS() {
+
+ // Get the Identifier of the example AAS
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+
+ // Retrieve the AAS from the server
+ IAssetAdministrationShell remoteAAS =
+ RetrieveRemoteAAS.retrieveRemoteAAS(aasIdentifier, registryComponent.getRegistryPath());
+
+ // Check if the retrieved AAS can be used correctly
+ assertEquals(AAS_ID_SHORT, remoteAAS.getIdShort());
+ }
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRetrieveSubmodelFromAAS.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRetrieveSubmodelFromAAS.java
new file mode 100644
index 0000000..03f98a8
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/aas/TestRetrieveSubmodelFromAAS.java
@@ -0,0 +1,36 @@
+package org.eclipse.basyx.examples.snippets.aas;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.junit.Test;
+
+/**
+ * Test for the RetrieveSubmodelFromAAS snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestRetrieveSubmodelFromAAS extends AbstractSnippetTest {
+
+
+ @Test
+ public void testRetrieveSubmodelFromAAS() {
+
+ // Get the Identifiers of the AAS and Submodel
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ IIdentifier smIdentifier = new Identifier(IdentifierType.CUSTOM, SM_ID);
+
+ // Get the Submodel from the server
+ ISubModel remoteSubmodel = RetrieveSubmodelFromAAS.retrieveSubmodelFromAAS(
+ smIdentifier, aasIdentifier, registryComponent.getRegistryPath());
+
+ // Check if the Submodel can be used correctly
+ assertEquals(SM_ID_SHORT, remoteSubmodel.getIdShort());
+ }
+
+}
\ No newline at end of file
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestAddSubmodelElement.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestAddSubmodelElement.java
new file mode 100644
index 0000000..d7af892
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestAddSubmodelElement.java
@@ -0,0 +1,50 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.Property;
+import org.junit.Test;
+
+/**
+ * Test for the AddSubmodelElement snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestAddSubmodelElement extends AbstractSnippetTest {
+
+ private static final String NEW_PROPERTY_ID = "new_prop";
+ private static final int NEW_PROPERTY_VALUE = 321;
+
+ @Test
+ public void testAddSubmodelElement() {
+
+ // Get the Identifiers of the AAS and Submodel
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ IIdentifier smIdentifier = new Identifier(IdentifierType.CUSTOM, SM_ID);
+
+ // Build a new SubmodelElement
+ Property newProperty = new Property();
+ newProperty.setIdShort(NEW_PROPERTY_ID);
+ newProperty.setValue(NEW_PROPERTY_VALUE);
+
+ // Add the new Element to the Submodel
+ AddSubmodelElement.addSubmodelElement(newProperty, smIdentifier, aasIdentifier, registryComponent.getRegistryPath());
+
+ // Get the Element from the server
+ ConnectedAssetAdministrationShellManager manager = getManager();
+ ISubModel remoteSubmodel = manager.retrieveSubModel(aasIdentifier, smIdentifier);
+ ISubmodelElement remoteElement = remoteSubmodel.getSubmodelElement(NEW_PROPERTY_ID);
+
+ // Check if its value is as expected
+ assertEquals(NEW_PROPERTY_VALUE, remoteElement.getValue());
+ }
+
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestDeleteSubmodelElement.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestDeleteSubmodelElement.java
new file mode 100644
index 0000000..5da765a
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestDeleteSubmodelElement.java
@@ -0,0 +1,53 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.basyx.aas.manager.ConnectedAssetAdministrationShellManager;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.examples.support.ExampleComponentBuilder;
+import org.eclipse.basyx.submodel.metamodel.api.ISubModel;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.eclipse.basyx.vab.exception.provider.ResourceNotFoundException;
+import org.junit.Test;
+
+/**
+ * Test for the DeleteSubmodelElement snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestDeleteSubmodelElement extends AbstractSnippetTest {
+
+ @Test
+ public void testDeleteSubmodelElement() {
+
+ // Get the Identifier of the example AAS and Submodel
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ IIdentifier smIdentifier = new Identifier(IdentifierType.CUSTOM, SM_ID);
+
+ // Delete the SubmodelElement
+ DeleteSubmodelElement.deleteSubmodelElement(ExampleComponentBuilder.PROPERTY_ID, smIdentifier, aasIdentifier, registryComponent.getRegistryPath());
+
+ // Create a proxy pointing to the registry server
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryComponent.getRegistryPath());
+
+ // Create a ConnectedAASManager using the registryProxy as its registry
+ ConnectedAssetAdministrationShellManager manager =
+ new ConnectedAssetAdministrationShellManager(registryProxy);
+
+ // Retrieve the Submodel from the server as a ConnectedSubmodel
+ ISubModel submodel = manager.retrieveSubModel(aasIdentifier, smIdentifier);
+
+ // Try to retrieve deleted SubmodelElement; should throw ResourceNotFoundException
+ try {
+ submodel.getSubmodelElement(ExampleComponentBuilder.PROPERTY_ID);
+ fail();
+ } catch (ResourceNotFoundException e) {
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestExecuteOperation.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestExecuteOperation.java
new file mode 100644
index 0000000..6da88ae
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestExecuteOperation.java
@@ -0,0 +1,104 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.function.Function;
+
+import org.eclipse.basyx.aas.metamodel.map.descriptor.SubmodelDescriptor;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.components.configuration.BaSyxContextConfiguration;
+import org.eclipse.basyx.components.servlet.submodel.SubmodelServlet;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.examples.support.ExampleComponentBuilder;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.SubModel;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.eclipse.basyx.submodel.metamodel.map.submodelelement.operation.Operation;
+import org.eclipse.basyx.vab.protocol.http.server.AASHTTPServer;
+import org.eclipse.basyx.vab.protocol.http.server.BaSyxContext;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * Test for the ExecuteOperation snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestExecuteOperation extends AbstractSnippetTest {
+
+ private static final String NEW_SM_ID_SHORT = "smIdShort_New";
+ private static final String NEW_SM_ID = "smId_New";
+
+ private static final String OPERATION_ID = "operation";
+
+ private static final Object[] PARAMETERS = {2, 3};
+ private static final int EXPECTED_RESULT = 5;
+
+ private AASHTTPServer server;
+
+ @After
+ public void shutdownServer() {
+ server.shutdown();
+ }
+
+ @Test
+ public void testExecuteOperation() throws Exception {
+
+ SubModel submodel = ExampleComponentBuilder.buildExampleSubmodel(NEW_SM_ID_SHORT, NEW_SM_ID);
+
+ // Add an Operation which calculates the sum of the two parameters
+ Operation operation = new Operation((Function<Object[], Object>) v -> {
+ return (int) v[0] + (int) v[1];
+ });
+ operation.setIdShort(OPERATION_ID);
+ submodel.addSubModelElement(operation);
+
+ // Startup a Server hosting this Submodel
+ provideSubmodel(submodel);
+
+
+ // Get the Identifiers of the AAS and Submodel
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ IIdentifier smIdentifier = new Identifier(IdentifierType.CUSTOM, NEW_SM_ID);
+
+ // Execute the Operation and get the result
+ Object result = ExecuteOperation.executeOperation(OPERATION_ID, PARAMETERS, smIdentifier, aasIdentifier, registryComponent.getRegistryPath());
+
+ // Check if the result is the expected value
+ assertEquals(EXPECTED_RESULT, result);
+
+ }
+
+ /**
+ * Starts a new server hosting a given Submodel
+ * This is necessary as an Operation can not be transfered to a server via serialization
+ *
+ * @param submodel the Submodel to be hosted
+ */
+ private void provideSubmodel(SubModel submodel) {
+ // Create a BaSyxConetxt for port 8082 with an empty endpoint
+ BaSyxContextConfiguration contextConfig = new BaSyxContextConfiguration(8082, "");
+ BaSyxContext context = contextConfig.createBaSyxContext();
+
+ // Create a new SubmodelServlet containing the submodel
+ SubmodelServlet smServlet = new SubmodelServlet(submodel);
+
+ // Add the SubmodelServlet mapping to the context at the path "/submodel"
+ context.addServletMapping("/submodel/*", smServlet);
+
+
+ // Create and start a HTTP server with the context created above
+ server = new AASHTTPServer(context);
+ server.start();
+
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ SubmodelDescriptor descriptor = new SubmodelDescriptor(submodel, "http://localhost:8082/submodel");
+
+ // Register the new Submodel
+ AASRegistryProxy registry = new AASRegistryProxy(registryComponent.getRegistryPath());
+ registry.register(aasIdentifier, descriptor);
+ }
+
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestLookupSubmodel.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestLookupSubmodel.java
new file mode 100644
index 0000000..0305f12
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestLookupSubmodel.java
@@ -0,0 +1,36 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.aas.metamodel.map.descriptor.SubmodelDescriptor;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.junit.Test;
+
+/**
+ * Test for the LookupSubmodel snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestLookupSubmodel extends AbstractSnippetTest {
+
+ @Test
+ public void testLookupSubmodel() {
+
+ // Get the Identifiers of the AAS and Submodel
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ IIdentifier smIdentifier = new Identifier(IdentifierType.CUSTOM, SM_ID);
+
+ // Lookup the Submodel in the registry
+ SubmodelDescriptor descriptor = LookupSubmodel.lookupSubmodel(
+ smIdentifier, aasIdentifier, registryComponent.getRegistryPath());
+
+ // Check if the returned Descriptor is as expected
+ assertEquals(SM_ENDPOINT, descriptor.getFirstEndpoint());
+
+ }
+
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestRegisterSubmodel.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestRegisterSubmodel.java
new file mode 100644
index 0000000..ea7c3bf
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestRegisterSubmodel.java
@@ -0,0 +1,45 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
+import org.eclipse.basyx.aas.metamodel.map.descriptor.SubmodelDescriptor;
+import org.eclipse.basyx.aas.registration.proxy.AASRegistryProxy;
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.examples.snippets.aas.RegisterAAS;
+import org.eclipse.basyx.examples.support.ExampleComponentBuilder;
+import org.eclipse.basyx.submodel.metamodel.map.SubModel;
+import org.junit.Test;
+
+/**
+ * Test for the RegisterSubmodel snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestRegisterSubmodel extends AbstractSnippetTest {
+
+ private static final String NEW_SM_ID_SHORT = "smIdShort_New";
+ private static final String NEW_SM_ID = "smId_New";
+ private static final String NEW_SM_ENDPOINT = "http://localhost:8080/aasComponent/" + NEW_SM_ID_SHORT + "/submodel";
+
+ @Test
+ public void testRegisterSubmodel() {
+
+ // Get the example AAS and Submodel
+ AssetAdministrationShell aas = ExampleComponentBuilder.buildExampleAAS(AAS_ID_SHORT, AAS_ID);
+ SubModel sm = ExampleComponentBuilder.buildExampleSubmodel(NEW_SM_ID_SHORT, NEW_SM_ID);
+
+ // Register this AAS
+ RegisterAAS.registerAAS(aas, AAS_ENDPOINT, registryComponent.getRegistryPath());
+
+ // Register this Submodel
+ RegisterSubmodel.registerSubmodel(sm, NEW_SM_ENDPOINT, aas.getIdentification(), registryComponent.getRegistryPath());
+
+ // Check if the Submodel was correctly registered
+ AASRegistryProxy registryProxy = new AASRegistryProxy(registryComponent.getRegistryPath());
+ SubmodelDescriptor descriptor = registryProxy.lookupSubmodel(aas.getIdentification(), sm.getIdentification());
+ assertEquals(NEW_SM_ENDPOINT, descriptor.getFirstEndpoint());
+
+ }
+}
diff --git a/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestRetrieveSubmodelElement.java b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestRetrieveSubmodelElement.java
new file mode 100644
index 0000000..7d8d03f
--- /dev/null
+++ b/examples/basys.examples/src/test/java/org/eclipse/basyx/examples/snippets/submodel/TestRetrieveSubmodelElement.java
@@ -0,0 +1,41 @@
+package org.eclipse.basyx.examples.snippets.submodel;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.basyx.examples.snippets.AbstractSnippetTest;
+import org.eclipse.basyx.examples.support.ExampleComponentBuilder;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
+import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType;
+import org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement;
+import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
+import org.junit.Test;
+
+/**
+ * Test for the RetrieveSubmodelElement snippet
+ *
+ * @author conradi
+ *
+ */
+public class TestRetrieveSubmodelElement extends AbstractSnippetTest {
+
+
+ @Test
+ public void testRetrieveSubmodelElement() {
+
+ // Get the Identifiers of the AAS and Submodel
+ IIdentifier aasIdentifier = new Identifier(IdentifierType.CUSTOM, AAS_ID);
+ IIdentifier smIdentifier = new Identifier(IdentifierType.CUSTOM, SM_ID);
+
+ // Get the idShort and value of the element to be retrieved
+ String elementId = ExampleComponentBuilder.PROPERTY_ID;
+ int elementValue = ExampleComponentBuilder.PROPERTY_VALUE;
+
+ // Get the SubmodelElement
+ ISubmodelElement element = RetrieveSubmodelElement.retrieveSubmodelElement(
+ elementId, smIdentifier, aasIdentifier, registryComponent.getRegistryPath());
+
+ // Check if the SubmodelElement contains the expected value
+ assertEquals(elementValue, element.getValue());
+ }
+
+}
\ No newline at end of file