+ def 'Get module definitions based on cmHandleId.'() {
+ when: 'get module definition request is performed'
+ def response = mvc.perform(
+ get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions"))
+ .andReturn().response
+ then: 'ncmp service method to get module definitions is called'
+ mockNetworkCmProxyDataService.getModuleDefinitionsByCmHandleId('some-cmhandle')
+ >> [new ModuleDefinition('sampleModuleName', '2021-10-03',
+ 'module sampleModuleName{ sample module content }')]
+ and: 'response contains an array with the module name, revision and content'
+ response.getContentAsString() == '[{"moduleName":"sampleModuleName","revision":"2021-10-03","content":"module sampleModuleName{ sample module content }"}]'
+ and: 'response returns an OK http code'
+ response.status == HttpStatus.OK.value()
+ }
+
+ def 'Set the data sync enabled based on the cm handle id and the data sync flag is #scenario'() {
+ when: 'the set data sync enabled request is invoked'
+ def response = mvc.perform(
+ put("$ncmpBasePathV1/ch/some-cm-handle-id/data-sync?dataSyncEnabled=" + dataSyncEnabledFlag))
+ .andReturn().response
+ then: 'method to set data sync enabled is called'
+ 1 * mockNetworkCmProxyDataService.setDataSyncEnabled('some-cm-handle-id', dataSyncEnabledFlag)
+ and: 'the response returns an OK http code'
+ response.status == HttpStatus.OK.value()
+ where: 'the following parameters are used'
+ scenario | dataSyncEnabledFlag
+ 'enabled' | true
+ 'disabled' | false
+ }
+
+ def 'Get Resource Data from operational with or without descendants'() {
+ given: 'resource data url with descendants #enabled'
+ def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:operational" +
+ "?resourceIdentifier=parent/child&include-descendants=${booleanValue}"
+ when: 'get data resource request is performed'
+ def response = mvc.perform(
+ get(getUrl)
+ .contentType(MediaType.APPLICATION_JSON)
+ ).andReturn().response
+ then: 'the NCMP data service is called with getResourceDataOperational with #descendantsOption'
+ 1 * mockNetworkCmProxyDataService.getResourceDataForCmHandle(OPERATIONAL.datastoreName, 'testCmHandle', 'parent/child', descendantsOption)
+ and: 'response status is Ok'
+ response.status == HttpStatus.OK.value()
+ where: 'the following parameters are used'
+ booleanValue | descendantsOption
+ false | OMIT_DESCENDANTS
+ true | INCLUDE_ALL_DESCENDANTS
+ }
+
+ def 'Attempt execute #operation rest operation on resource data with #scenario'() {
+ given: 'resource data url'
+ def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/${datastoreInUrl}?resourceIdentifier=parent/child"
+ when: 'selected request for data resource is performed on url'
+ def response = mvc.perform(
+ executeRestOperation(operation, url))
+ .andReturn().response
+ then: 'the response status is as expected'
+ assert response.status == HttpStatus.BAD_REQUEST.value()
+ and: 'the response is as expected'
+ assert response.getContentAsString().contains(datastoreInUrl)
+ where: 'the following parameters are used'
+ scenario | operation | datastoreInUrl
+ 'unsupported datastore' | 'POST' | 'ncmp-datastore:operational'
+ 'invalid datastore' | 'POST' | 'invalid'
+ 'unsupported datastore' | 'PUT' | 'ncmp-datastore:operational'
+ 'invalid datastore' | 'PUT' | 'invalid'
+ 'unsupported datastore' | 'PATCH' | 'ncmp-datastore:operational'
+ 'invalid datastore' | 'PATCH' | 'invalid'
+ 'unsupported datastore' | 'DELETE' | 'ncmp-datastore:operational'
+ 'invalid datastore' | 'DELETE' | 'invalid'
+ }
+
+ def executeRestOperation(operation, url) {
+ if (operation == 'POST') {
+ return post(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody)
+ }
+ if (operation == 'PUT') {
+ return put(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody)
+ }
+ if (operation == 'PATCH') {
+ return patch(url).contentType(MediaType.APPLICATION_JSON_VALUE).content(requestBody)
+ }
+ if (operation == 'DELETE') {
+ return delete(url).contentType(MediaType.APPLICATION_JSON_VALUE)
+ }
+ }
+