[CPS] Fix SonarQube Violations / Improve Coverage - Recurring task 53/133853/2
authorraviteja.karumuri <raviteja.karumuri@est.tech>
Fri, 24 Mar 2023 17:50:58 +0000 (17:50 +0000)
committerraviteja.karumuri <raviteja.karumuri@est.tech>
Tue, 28 Mar 2023 12:00:21 +0000 (13:00 +0100)
Issue-ID: CPS-475
Signed-off-by: raviteja.karumuri <raviteja.karumuri@est.tech>
Change-Id: Id3507fb24c4c6eb002a9ae6fed553daa2fca7895

cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/SubscriptionModelLoaderSpec.groovy

index 9072082..650916e 100644 (file)
@@ -44,10 +44,10 @@ class SubscriptionModelLoaderSpec extends Specification {
     def mockCpsDataService = Mock(CpsDataService)
     def objectUnderTest = new SubscriptionModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService)
 
-    def SUBSCRIPTION_DATASPACE_NAME = objectUnderTest.SUBSCRIPTION_DATASPACE_NAME;
-    def SUBSCRIPTION_ANCHOR_NAME = objectUnderTest.SUBSCRIPTION_ANCHOR_NAME;
-    def SUBSCRIPTION_SCHEMASET_NAME = objectUnderTest.SUBSCRIPTION_SCHEMASET_NAME;
-    def SUBSCRIPTION_REGISTRY_DATANODE_NAME = objectUnderTest.SUBSCRIPTION_REGISTRY_DATANODE_NAME;
+    def SUBSCRIPTION_DATASPACE_NAME = objectUnderTest.SUBSCRIPTION_DATASPACE_NAME
+    def SUBSCRIPTION_ANCHOR_NAME = objectUnderTest.SUBSCRIPTION_ANCHOR_NAME
+    def SUBSCRIPTION_SCHEMASET_NAME = objectUnderTest.SUBSCRIPTION_SCHEMASET_NAME
+    def SUBSCRIPTION_REGISTRY_DATANODE_NAME = objectUnderTest.SUBSCRIPTION_REGISTRY_DATANODE_NAME
 
     def sampleYangContentMap = ['subscription.yang':'module subscription { *sample content* }']
 
@@ -67,7 +67,7 @@ class SubscriptionModelLoaderSpec extends Specification {
 
     @AfterEach
     void teardown() {
-        ((Logger) LoggerFactory.getLogger(SubscriptionModelLoader.class)).detachAndStopAllAppenders();
+        ((Logger) LoggerFactory.getLogger(SubscriptionModelLoader.class)).detachAndStopAllAppenders()
     }
 
     def 'Onboard subscription model successfully via application ready event'() {
@@ -83,6 +83,20 @@ class SubscriptionModelLoaderSpec extends Specification {
             1 * mockCpsDataService.saveData(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME, '{"' + SUBSCRIPTION_REGISTRY_DATANODE_NAME + '":{}}', _)
     }
 
+    def 'No subscription model onboarding when subscription model loader is disabled' () {
+        when: 'model loader is disabled'
+            objectUnderTest.subscriptionModelLoaderEnabled = false
+        and: 'application is ready'
+            objectUnderTest.onApplicationEvent(applicationReadyEvent)
+        then: 'the module service to create schema set was not called'
+            0 * mockCpsModuleService.createSchemaSet(*_)
+        and: 'the admin service to create an anchor set was not called'
+            0 * mockCpsAdminService.createAnchor(*_)
+        and: 'the data service to create a top level datanode was not called'
+            0 * mockCpsDataService.saveData(*_)
+    }
+
+
     def 'Create schema set from model file'() {
         given: 'the method to create yang resource to content map returns the correct map'
             def yangResourceToContentMap = objectUnderTest.createYangResourceToContentMap()
@@ -111,7 +125,7 @@ class SubscriptionModelLoaderSpec extends Specification {
             def yangResourceToContentMap = objectUnderTest.createYangResourceToContentMap()
         and: 'creating a schema set throws an exception'
             mockCpsModuleService.createSchemaSet(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_SCHEMASET_NAME, yangResourceToContentMap) >>
-                    { throw new NcmpStartUpException("Creating schema set failed", ""); }
+                    { throw new NcmpStartUpException("Creating schema set failed", "") }
         when: 'the method to onboard model is called'
             objectUnderTest.onboardSubscriptionModel()
         then: 'the log message contains the correct exception message'
@@ -147,7 +161,7 @@ class SubscriptionModelLoaderSpec extends Specification {
     def 'Create top level node fails due to an AlreadyDefined exception'() {
         given: 'the saving of the node data will throw an Already Defined exception'
             mockCpsDataService.saveData(*_) >>
-                { AlreadyDefinedException.forDataNode('/xpath', "sampleContextName", null) }
+                { throw AlreadyDefinedException.forDataNode('/xpath', "sampleContextName", null) }
         when: 'the method to onboard model is called'
             objectUnderTest.onboardSubscriptionModel()
         then: 'no exception thrown'