Refactor NbiNotificationsUtils 51/103651/3
authorGilles Thouenon <gilles.thouenon@orange.com>
Fri, 9 Dec 2022 18:22:44 +0000 (19:22 +0100)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Tue, 13 Dec 2022 15:25:04 +0000 (15:25 +0000)
- Adapt tapi_nbinotifications functional test consequently
- speed-up the tapi_nbinotifications functional test

Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: I63973269666268f28d1a47b6714c52a179798af4

nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/utils/NbiNotificationsUtils.java
tests/transportpce_tests/with_docker/test03_tapi_nbinotifications.py

index 02007bab88ce025ea46f5967657e1c678b743077..219f5288f73070200a9798fe30723ca7f25d7c86 100644 (file)
@@ -9,9 +9,10 @@ package org.opendaylight.transportpce.nbinotifications.utils;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService;
 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiServiceBuilder;
 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishTapiNotificationService;
@@ -27,7 +28,6 @@ import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.tap
 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.tapi.service.TargetObjectNameKey;
 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.tapi.service.TcaInfoBuilder;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,39 +55,20 @@ public final class NbiNotificationsUtils {
     }
 
     public static NotificationTapiService transformTapiNotification(PublishTapiNotificationService notification) {
-        Map<AdditionalInfoKey, AdditionalInfo> addInfoMap = new HashMap<>();
-        if (notification.getAdditionalInfo() != null) {
-            for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.AdditionalInfo
-                    addInfo:notification.getAdditionalInfo().values()) {
-                AdditionalInfo transAddInfo = new AdditionalInfoBuilder(addInfo).build();
-                addInfoMap.put(transAddInfo.key(), transAddInfo);
-            }
-        }
-        Map<ChangedAttributesKey, ChangedAttributes> changedAttMap = new HashMap<>();
-        if (notification.getChangedAttributes() != null) {
-            for (org.opendaylight.yang.gen.v1
-                    .urn.onf.otcc.yang.tapi.notification.rev181210.notification.ChangedAttributes
-                    changedAtt:notification.getChangedAttributes().values()) {
-                ChangedAttributes transChangedAtt = new ChangedAttributesBuilder(changedAtt).build();
-                changedAttMap.put(transChangedAtt.key(), transChangedAtt);
-            }
-        }
-        Map<NameKey, Name> nameMap = new HashMap<>();
-        if (notification.getName() != null) {
-            for (Name name:notification.getName().values()) {
-                Name transName = new NameBuilder(name).build();
-                nameMap.put(transName.key(), transName);
-            }
-        }
-        Map<TargetObjectNameKey, TargetObjectName> targetObjNameMap = new HashMap<>();
-        if (notification.getTargetObjectName() != null) {
-            for (org.opendaylight.yang.gen.v1
-                    .urn.onf.otcc.yang.tapi.notification.rev181210.notification.TargetObjectName
-                    targetObjectName:notification.getTargetObjectName().values()) {
-                TargetObjectName transTargetObjName = new TargetObjectNameBuilder(targetObjectName).build();
-                targetObjNameMap.put(transTargetObjName.key(), transTargetObjName);
-            }
-        }
+        Map<AdditionalInfoKey, AdditionalInfo> addInfoMap = notification.nonnullAdditionalInfo().values().stream()
+            .collect(Collectors.toMap(
+                    e -> new AdditionalInfoKey(e.getValueName()),
+                    e -> new AdditionalInfoBuilder(e).build()));
+        Map<ChangedAttributesKey, ChangedAttributes> changedAttMap = notification.nonnullChangedAttributes().values()
+                .stream().collect(Collectors.toMap(
+                        e -> new ChangedAttributesKey(e.getValueName()),
+                        e -> new ChangedAttributesBuilder(e).build()));
+        Map<NameKey, Name> nameMap = notification.nonnullName().values().stream()
+                .collect(Collectors.toMap(Name::key, Function.identity()));
+        Map<TargetObjectNameKey, TargetObjectName> targetObjNameMap = notification.nonnullTargetObjectName().values()
+                .stream().collect(Collectors.toMap(
+                        e -> new TargetObjectNameKey(e.getValueName()),
+                        e -> new TargetObjectNameBuilder(e).build()));
         LOG.info("Notification uuid = {}", notification.getUuid());
         return new NotificationTapiServiceBuilder()
                 .setAlarmInfo(notification.getAlarmInfo() == null ? null
index 571549fb0c98f8249c7b50489789fa85a9cba4a0..b9537caf5da703a461974b1cc434a95dcf48374f 100644 (file)
@@ -295,8 +295,6 @@ class TransportNbiNotificationstesting(unittest.TestCase):
                              response['output']['service']['end-point'][0]['name'][0])
         self.assertDictEqual(dict(input_dict_3, **response['output']['service']['end-point'][1]['name'][0]),
                              response['output']['service']['end-point'][1]['name'][0])
-        # If the gate fails is because of the waiting time not being enough
-        time.sleep(self.WAITING)
 
     def test_12_get_service_Ethernet(self):
         response = test_utils.get_ordm_serv_list_attr_request("services", str(self.uuid_services.eth))
@@ -382,10 +380,10 @@ class TransportNbiNotificationstesting(unittest.TestCase):
         response = test_utils.transportpce_api_rpc_request(
             'tapi-notification', 'get-notification-list', self.cr_get_notif_list_input_data)
         self.assertEqual(response['status_code'], requests.codes.ok)
-        self.assertEqual(response['output']['notification'][1]['target-object-identifier'], str(self.uuid_services.eth))
-        self.assertEqual(response['output']['notification'][1]['target-object-type'], 'CONNECTIVITY_SERVICE')
-        self.assertEqual(response['output']['notification'][1]['changed-attributes'][0]['new-value'], 'UNLOCKED')
-        self.assertEqual(response['output']['notification'][1]['changed-attributes'][1]['new-value'], 'ENABLED')
+        self.assertEqual(response['output']['notification'][0]['target-object-identifier'], str(self.uuid_services.eth))
+        self.assertEqual(response['output']['notification'][0]['target-object-type'], 'CONNECTIVITY_SERVICE')
+        self.assertEqual(response['output']['notification'][0]['changed-attributes'][0]['new-value'], 'UNLOCKED')
+        self.assertEqual(response['output']['notification'][0]['changed-attributes'][1]['new-value'], 'ENABLED')
         time.sleep(2)
 
     def test_19_delete_connectivity_service_Ethernet(self):