Merge "Update Design & Modeling Sections"
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / NetworkCmProxyDataServiceImplSpec.groovy
index 2b376e9..b5d4713 100644 (file)
@@ -231,16 +231,14 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService',
                 'testCmHandle',
                 'testResourceId',
-                'testFieldQuery',
-                5,
+                '(a=1,b=2)',
                 'testAcceptParam',
                 '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('result-json', HttpStatus.OK)
         when: 'get resource data is called'
             def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
             'testResourceId',
             'testAcceptParam',
-            'testFieldQuery',
-            5)
+            '(a=1,b=2)')
         then: 'dmi returns ok response'
             response == 'result-json'
     }
@@ -259,8 +257,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
                     'testResourceId',
                     'testAcceptParam',
-                    'testFieldQuery',
-                    5)
+                    '(a=1,b=2)')
         then: 'exception is thrown with the expected details'
             def exceptionThrown = thrown(NcmpException.class)
             exceptionThrown.details == 'testException'
@@ -276,8 +273,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService',
                     'testCmHandle',
                     'testResourceId',
-                    'testFieldQuery',
-                    5,
+                    '(a=1,b=2)',
                     'testAcceptParam',
                     '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
                     >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
@@ -285,8 +281,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
                     'testResourceId',
                     'testAcceptParam',
-                    'testFieldQuery',
-                    5)
+                    '(a=1,b=2)')
         then: 'exception is thrown'
             def exceptionThrown = thrown(NcmpException.class)
         and: 'details contains the original response'
@@ -303,16 +298,14 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             mockDmiOperations.getResourceDataPassThroughRunningFromDmi('testDmiService',
                     'testCmHandle',
                     'testResourceId',
-                    'testFieldQuery',
-                    5,
+                    '(a=1,b=2)',
                     'testAcceptParam',
                     '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('{result-json}', HttpStatus.OK)
         when: 'get resource data is called'
             def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
                     'testResourceId',
                     'testAcceptParam',
-                    'testFieldQuery',
-                    5)
+                    '(a=1,b=2)')
         then: 'get resource data returns expected response'
             response == '{result-json}'
     }
@@ -331,8 +324,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
                     'testResourceId',
                     'testAcceptParam',
-                    'testFieldQuery',
-                    5)
+                    '(a=1,b=2)')
         then: 'exception is thrown with the expected details'
             def exceptionThrown = thrown(NcmpException.class)
             exceptionThrown.details == 'testException'
@@ -348,8 +340,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             mockDmiOperations.getResourceDataPassThroughRunningFromDmi('testDmiService',
                     'testCmHandle',
                     'testResourceId',
-                    'testFieldQuery',
-                    5,
+                    '(a=1,b=2)',
                     'testAcceptParam',
                     '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
                     >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
@@ -357,8 +348,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
                     'testResourceId',
                     'testAcceptParam',
-                    'testFieldQuery',
-                    5)
+                    '(a=1,b=2)')
         then: 'exception is thrown'
             def exceptionThrown = thrown(NcmpException.class)
         and: 'details contains the original response'
@@ -419,7 +409,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             }
         and: 'dmi operations returns some module references'
             def jsonData = TestUtils.getResourceFileContent('cmHandleModules.json')
-            def expectedJsonBody = '{"operation":"read","cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
+            def expectedJsonBody = '{"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
             mockDmiProperties.getAuthUsername() >> 'someUser'
             mockDmiProperties.getAuthPassword() >> 'somePassword'
             def moduleReferencesFromCmHandleAsJson = new ResponseEntity<String>(jsonData, HttpStatus.OK)
@@ -428,10 +418,10 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             mockCpsModuleService.getYangResourceModuleReferences(_) >> [knownModule1, knownOtherModule]
         and: 'DMI-Plugin returns resource(s) for "new" module(s)'
             def moduleResources = new ResponseEntity<String>(sdncReponseBody, HttpStatus.OK)
-            def jsonDataToFetchYangResource = '{"operation":"read","dataType":"application/json","data":"{\\"modules\\":[{\\"name\\":\\"module2\\",\\"revision\\":\\"1\\"}]}","cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
+            def jsonDataToFetchYangResource = '{"data":{"modules":[{"name":"module2","revision":"1"}]},"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
             mockDmiOperations.getResourceFromDmiWithJsonData('some service name', jsonDataToFetchYangResource, 'some cm handle', 'moduleResources') >> moduleResources
         when: 'module Sync is triggered'
-            objectUnderTest.createAnchorAndSyncModel(cmHandleForModelSync)
+            objectUnderTest.syncModulesAndCreateAnchor(cmHandleForModelSync)
         then: 'the CPS module service is called once with the correct parameters'
             1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, [knownModule1])
         and: 'admin service create anchor method has been called with correct parameters'
@@ -451,10 +441,22 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             1 * mockCpsModuleService.getYangResourcesModuleReferences('NFP-Operational','some cm handle')
     }
 
+    def 'Create the request body to get yang resources from DMI.'() {
+        given: 'the expected json request'
+            def expectedRequestBody = '{"data":{"modules":[{"name":"module1","revision":"1"},{"name":"module2","revision":"2"}]},"cmHandleProperties":{"name1":"value1"}}'
+        and: 'module references and cm handle properties'
+            def moduleReferences = [new ModuleReference('module1', '1'),new ModuleReference('module2', '2')]
+            def cmHandleProperties = ['name1':'value1']
+        when: 'get request body to fetch yang resources from DMI is called'
+            def result = objectUnderTest.getRequestBodyToFetchYangResourceFromDmi(moduleReferences, cmHandleProperties)
+        then: 'the result is the same as the expected request body'
+            result == expectedRequestBody
+    }
+
     def getObjectUnderTestWithModelSyncDisabled() {
         def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(mockDmiOperations, mockCpsModuleService,
                 mockCpsDataService, mockCpsQueryService, mockCpsAdminService, spyObjectMapper))
-        objectUnderTest.createAnchorAndSyncModel(_) >> null
+        objectUnderTest.syncModulesAndCreateAnchor(_) >> null
         return objectUnderTest
     }