def cmHandle = 'some handle'
def noTimestamp = null
def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
- def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name')
def expectedDataspaceName = 'NFP-Operational'
def 'Register or re-register a DMI Plugin with #scenario cm handles.'() {
given: 'a registration '
- NetworkCmProxyDataServiceImpl objectUnderTest = getObjectUnderTestWithModelSyncDisabled()
+ def objectUnderTest = getObjectUnderTestWithModelSyncDisabled()
def dmiPluginRegistration = new DmiPluginRegistration()
dmiPluginRegistration.dmiPlugin = 'my-server'
persistenceCmHandle.cmHandleID = '123'
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'
}
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'
mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
- 'testFieldQuery',
- 5,
+ '(a=1,b=2)',
'testAcceptParam',
'{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
>> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
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'
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}'
}
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'
mockDmiOperations.getResourceDataPassThroughRunningFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
- 'testFieldQuery',
- 5,
+ '(a=1,b=2)',
'testAcceptParam',
'{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
>> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
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'
>> { new ResponseEntity<>(HttpStatus.OK) }
where:
scenario | includeCmHandleProperties || expectedJsonForCmhandleProperties
- 'with' | true || '{"testName":"testValue"}'
- 'without' | false || '{}'
+ 'with' | true || '{"testName":"testValue"}'
+ 'without' | false || '{}'
}
def 'Write resource data for pass-through running from dmi using POST "not found" response (from DMI).'() {
def 'Sync model for a (new) cm handle with #scenario'() {
given: 'DMI Plug-in returns a list of module references'
- getModulesForCmHandle()
def knownModule1 = new ModuleReference('module1', '1')
def knownOtherModule = new ModuleReference('some other module', 'some revision')
+ and: 'persistence cm handle is given'
+ def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name')
+ and: 'additional properties are set as required'
+ if (additionalProperties!=null) {
+ cmHandleForModelSync.setAdditionalProperties(additionalProperties)
+ }
+ and: 'dmi operations returns some module references'
+ def jsonData = TestUtils.getResourceFileContent('cmHandleModules.json')
+ def expectedJsonBody = '{"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
+ mockDmiProperties.getAuthUsername() >> 'someUser'
+ mockDmiProperties.getAuthPassword() >> 'somePassword'
+ def moduleReferencesFromCmHandleAsJson = new ResponseEntity<String>(jsonData, HttpStatus.OK)
+ mockDmiOperations.getResourceFromDmiWithJsonData('some service name', expectedJsonBody, 'some cm handle', 'modules') >> moduleReferencesFromCmHandleAsJson
and: 'CPS-Core returns list of known modules'
mockCpsModuleService.getYangResourceModuleReferences(_) >> [knownModule1, knownOtherModule]
and: 'DMI-Plugin returns resource(s) for "new" module(s)'
def moduleResources = new ResponseEntity<String>(sdncReponseBody, HttpStatus.OK)
- mockDmiOperations.getResourceFromDmiWithJsonData(_, _, _, 'moduleResources') >> moduleResources
+ 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'
1 * mockCpsAdminService.createAnchor(expectedDataspaceName, cmHandleForModelSync.getId(), cmHandleForModelSync.getId())
where: 'the following responses are received from SDNC'
- scenario | sdncReponseBody || expectedYangResourceToContentMap
- 'one unknown module' | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source']
- 'no unknown module' | '[]' || [:]
+ scenario | additionalProperties | sdncReponseBody || expectedYangResourceToContentMap | expectedJsonForAdditionalProperties
+ 'one unknown module' | ['name1':'value1'] | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{"name1":"value1"}'
+ 'no add. properties' | [:] | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{}'
+ 'additional properties is null' | null | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{}'
+ 'no unknown module' | [:] | '[]' || [:] | '{}'
}
-
def 'Getting Yang Resources.'() {
when: 'yang resources is called'
objectUnderTest.getYangResourcesModuleReferences('some cm handle')
1 * mockCpsModuleService.getYangResourcesModuleReferences('NFP-Operational','some cm handle')
}
- def getModulesForCmHandle() {
- def jsonData = TestUtils.getResourceFileContent('cmHandleModules.json')
- mockDmiProperties.getAuthUsername() >> 'someUser'
- mockDmiProperties.getAuthPassword() >> 'somePassword'
- def moduleReferencesFromCmHandleAsJson = new ResponseEntity<String>(jsonData, HttpStatus.OK)
- mockDmiOperations.getResourceFromDmi(_, cmHandleForModelSync.getId(), 'modules') >> moduleReferencesFromCmHandleAsJson
+ 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
}