Search in sources :

Example 1 with ElementDeleteEventMessage

use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testDeleteCapability.

/**
 * Test method for deleting a Capability.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testDeleteCapability() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testDeleteCapability: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    // make sure the element exists
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_7_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_CAPABILITY_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    // add more elements to the browse path
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.CATEGORY_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testDeleteCapability Browse Result Null", bpres);
    Assert.assertTrue("testDeleteCapability Browse Result: size doesn't match", bpres.length == 2);
    Assert.assertTrue("testDeleteCapability Browse Result 1 Good", bpres[0].getStatusCode().isGood());
    Assert.assertTrue("testDeleteCapability Browse Result 2 Good", bpres[1].getStatusCode().isGood());
    // Send event to MessageBus
    ElementDeleteEventMessage msg = new ElementDeleteEventMessage();
    msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("https://acplt.org/Test_Submodel_Template").build()).key(new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.CAPABILITY).value(TestDefines.FULL_CAPABILITY_NAME).build()).build());
    service.getMessageBus().publish(msg);
    Thread.sleep(DEFAULT_TIMEOUT);
    // check that the element is not there anymore
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testDeleteCapability Browse Result Null", bpres);
    Assert.assertTrue("testDeleteCapability Browse Result: size doesn't match", bpres.length == 2);
    Assert.assertTrue("testDeleteCapability Browse Result 1 Bad", bpres[0].getStatusCode().isBad());
    Assert.assertTrue("testDeleteCapability Browse Result 2 Bad", bpres[1].getStatusCode().isBad());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) Test(org.junit.Test)

Example 2 with ElementDeleteEventMessage

use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandler method publishElementDeleteEventMessage.

/**
 * Publish a ElementDeleteEventMessage to the message bus
 *
 * @param reference of the element
 * @param referable the instance
 */
public void publishElementDeleteEventMessage(Reference reference, Referable referable) {
    ElementDeleteEventMessage eventMessage = new ElementDeleteEventMessage();
    eventMessage.setElement(reference);
    eventMessage.setValue(referable);
    try {
        this.messageBus.publish(eventMessage);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) AssetConnectionException(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 3 with ElementDeleteEventMessage

use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpoint2Test method testDeleteSubmodel.

/**
 * Test method for deleting a complete submodel (Technical Data).
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testDeleteSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testDeleteSubmodel: client connected");
    int aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    // make sure the element exists
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_TECH_DATA_NODE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    // add more elements to the browse path
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.IDENTIFICATION_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "Id")));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testDeleteSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testDeleteSubmodel Browse Result: size doesn't match", bpres.length == 2);
    Assert.assertTrue("testDeleteSubmodel Browse Result 1 Good", bpres[0].getStatusCode().isGood());
    Assert.assertTrue("testDeleteSubmodel Browse Result 2 Good", bpres[1].getStatusCode().isGood());
    // Send delete event to MessageBus
    ElementDeleteEventMessage msg = new ElementDeleteEventMessage();
    msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value(AASSimple.SUBMODEL_TECHNICAL_DATA_ID).build()).build());
    service.getMessageBus().publish(msg);
    Thread.sleep(DEFAULT_TIMEOUT);
    // check that the element is not there anymore
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testDeleteSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testDeleteSubmodel Browse Result: size doesn't match", bpres.length == 2);
    Assert.assertTrue("testDeleteSubmodel Browse Result 1 Bad", bpres[0].getStatusCode().isBad());
    Assert.assertTrue("testDeleteSubmodel Browse Result 2 Bad", bpres[1].getStatusCode().isBad());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Example 4 with ElementDeleteEventMessage

use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testDeleteSubmodel.

/**
 * Test method for deleting a complete submodel.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testDeleteSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testDeleteSubmodel: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    // make sure the element exists
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SUBMODEL_5_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    // add more elements to the browse path
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.IDENTIFICATION_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, "Id")));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testDeleteSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testDeleteSubmodel Browse Result: size doesn't match", bpres.length == 2);
    Assert.assertTrue("testDeleteSubmodel Browse Result 1 Good", bpres[0].getStatusCode().isGood());
    Assert.assertTrue("testDeleteSubmodel Browse Result 2 Good", bpres[1].getStatusCode().isGood());
    // Send event to MessageBus
    ElementDeleteEventMessage msg = new ElementDeleteEventMessage();
    msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("https://acplt.org/Test_Submodel2_Mandatory").build()).build());
    service.getMessageBus().publish(msg);
    Thread.sleep(DEFAULT_TIMEOUT);
    // check that the element is not there anymore
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testDeleteSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testDeleteSubmodel Browse Result: size doesn't match", bpres.length == 2);
    Assert.assertTrue("testDeleteSubmodel Browse Result 1 Bad", bpres[0].getStatusCode().isBad());
    Assert.assertTrue("testDeleteSubmodel Browse Result 2 Bad", bpres[1].getStatusCode().isBad());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Example 5 with ElementDeleteEventMessage

use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage in project FAAAST-Service by FraunhoferIOSB.

the class Util method setUpEventCheck.

public static void setUpEventCheck(Referable expected, Class<? extends EventMessage> clazz, Supplier<?> call) {
    AtomicBoolean fired = new AtomicBoolean(false);
    SubscriptionId subscriptionId = IntegrationTestHttpEndpoint.messageBus.subscribe(SubscriptionInfo.create(clazz, x -> {
        if (ElementReadEventMessage.class.isAssignableFrom(x.getClass())) {
            Assert.assertEquals(expected, ((ElementReadEventMessage) x).getValue());
            fired.set(true);
        }
        if (ElementCreateEventMessage.class.isAssignableFrom(x.getClass())) {
            Assert.assertEquals(expected, ((ElementCreateEventMessage) x).getValue());
            fired.set(true);
        }
        if (ElementUpdateEventMessage.class.isAssignableFrom(x.getClass())) {
            Assert.assertEquals(expected, ((ElementUpdateEventMessage) x).getValue());
            fired.set(true);
        }
        if (ElementDeleteEventMessage.class.isAssignableFrom(x.getClass())) {
            Assert.assertEquals(expected, ((ElementDeleteEventMessage) x).getValue());
            fired.set(true);
        }
    }));
    call.get();
    Assert.assertTrue(fired.get());
    IntegrationTestHttpEndpoint.messageBus.unsubscribe(subscriptionId);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ElementReadEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Supplier(java.util.function.Supplier) EntityUtils(org.apache.http.util.EntityUtils) HttpDelete(org.apache.http.client.methods.HttpDelete) SubscriptionInfo(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo) Referable(io.adminshell.aas.v3.model.Referable) ByteArrayInputStream(java.io.ByteArrayInputStream) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) DeserializationException(io.adminshell.aas.v3.dataformat.DeserializationException) IOException(java.io.IOException) SubscriptionId(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId) JsonDeserializer(io.adminshell.aas.v3.dataformat.json.JsonDeserializer) JsonSerializer(io.adminshell.aas.v3.dataformat.json.JsonSerializer) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) StandardCharsets(java.nio.charset.StandardCharsets) EventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage) List(java.util.List) HttpPut(org.apache.http.client.methods.HttpPut) HttpGet(org.apache.http.client.methods.HttpGet) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) HttpResponse(org.apache.http.HttpResponse) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) Assert(org.junit.Assert) SerializationException(io.adminshell.aas.v3.dataformat.SerializationException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SubscriptionId(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) ElementReadEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage)

Aggregations

ElementDeleteEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage)5 UaClient (com.prosysopc.ua.client.UaClient)3 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)3 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)3 RelativePath (com.prosysopc.ua.stack.core.RelativePath)3 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)3 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)2 AssetConnectionException (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException)1 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)1 EventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage)1 SubscriptionId (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId)1 SubscriptionInfo (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo)1 ElementReadEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage)1 ElementCreateEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage)1 ElementUpdateEventMessage (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage)1 DeserializationException (io.adminshell.aas.v3.dataformat.DeserializationException)1 SerializationException (io.adminshell.aas.v3.dataformat.SerializationException)1