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();
}
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();
}
}
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();
}
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();
}
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);
}
Aggregations