Adding unit tests and robuestness for DMI registration 25/126225/4
authorJosephKeenan <joseph.keenan@est.tech>
Tue, 14 Dec 2021 12:25:21 +0000 (12:25 +0000)
committerJosephKeenan <joseph.keenan@est.tech>
Wed, 15 Dec 2021 10:17:40 +0000 (10:17 +0000)
-Added more scenarios for combinations of plugins
-Made plugin registration more robust

Issue-ID: CPS-736
Signed-off-by: JosephKeenan <joseph.keenan@est.tech>
Change-Id: I7495eb802fec8708e7ea6b0a97a9d7fe4676c8c1

cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/DmiPluginRegistration.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy

index a604f34..9faf733 100644 (file)
@@ -53,8 +53,6 @@ public class DmiPluginRegistration {
 
     private List<String> removedCmHandles;
 
-    public static final String PLEASE_SUPPLY_CORRECT_PLUGIN_INFORMATION = "Please supply correct plugin information.";
-
     /**
      * Validates plugin service names.
      *
@@ -67,19 +65,22 @@ public class DmiPluginRegistration {
 
         String errorMessage = null;
 
-        if (isNullEmptyOrBlank(combinedServiceName)
-            && isNullEmptyOrBlank(dataServiceName)
-            && isNullEmptyOrBlank(modelsServiceName)) {
-            errorMessage = "No DMI plugin service names";
-        }
-
-        if (!isNullEmptyOrBlank(combinedServiceName)
-            && (!isNullEmptyOrBlank(dataServiceName) || !isNullEmptyOrBlank(modelsServiceName))) {
-            errorMessage = "Invalid combination of plugin service names";
+        if (isNullEmptyOrBlank(combinedServiceName)) {
+            if ((isNullEmptyOrBlank(dataServiceName) && isNullEmptyOrBlank(modelsServiceName))) {
+                errorMessage = "No DMI plugin service names";
+            } else {
+                if (isNullEmptyOrBlank(dataServiceName) || isNullEmptyOrBlank(modelsServiceName)) {
+                    errorMessage = "Cannot register just a Data or Model plugin service name";
+                }
+            }
+        } else {
+            if (!isNullEmptyOrBlank(dataServiceName) || !isNullEmptyOrBlank(modelsServiceName)) {
+                errorMessage = "Cannot register combined plugin service name and other service names";
+            }
         }
 
         if (errorMessage != null) {
-            throw new NcmpException(errorMessage, PLEASE_SUPPLY_CORRECT_PLUGIN_INFORMATION);
+            throw new NcmpException(errorMessage, "Please supply correct plugin information.");
         }
     }
 
index 8c3e593..304c08a 100644 (file)
@@ -170,11 +170,15 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
         and: 'registration is not called'
             0 * objectUnderTest.parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(dmiPluginRegistration)
         where:
-            scenario              | dmiPlugin  | dmiModelPlugin | dmiDataPlugin || expectedMessageDetails
-            'no DMI plugin'       | ''         | ''             | ''            || 'No DMI plugin service names'
-            'all DMI plugins'     | 'service1' | 'service2'     | 'service3'    || 'Invalid combination of plugin service names'
-            'no model DMI plugin' | 'service1' | ''             | 'service2'    || 'Invalid combination of plugin service names'
-            'no data DMI plugin'  | 'service1' | 'service2'     | ''            || 'Invalid combination of plugin service names'
+            scenario                        | dmiPlugin  | dmiModelPlugin | dmiDataPlugin || expectedMessageDetails
+            'empty DMI plugins'             | ''         | ''             | ''            || 'No DMI plugin service names'
+            'blank DMI plugins'             | ' '        | ' '            | ' '           || 'No DMI plugin service names'
+            'null DMI plugins'              | null       | null           | null          || 'No DMI plugin service names'
+            'all DMI plugins'               | 'service1' | 'service2'     | 'service3'    || 'Cannot register combined plugin service name and other service names'
+            '(combined)DMI and Data Plugin' | 'service1' | ''             | 'service2'    || 'Cannot register combined plugin service name and other service names'
+            '(combined)DMI and model Plugin'| 'service1' | 'service2'     | ''            || 'Cannot register combined plugin service name and other service names'
+            'only model DMI plugin'         | ''         | 'service1'     | ''            || 'Cannot register just a Data or Model plugin service name'
+            'only data DMI plugin'          | ''         | ''             | 'service1'    || 'Cannot register just a Data or Model plugin service name'
     }
 
     def getObjectUnderTestWithModelSyncDisabled() {