+
+ def createJsonArray(name, numberOfElements, keyName, keyValuePrefix, dataPerKey) {
+ def innerJson = (1..numberOfElements).collect {
+ '{"' + keyName + '":"' + keyValuePrefix + '-' + it + '"' + (dataPerKey.empty? '': ',' + dataPerKey) + '}'
+ }.join(',')
+ return '{"' + name + '":[' + innerJson + ']}'
+ }
+
+ def createLeafList(name, numberOfElements, valuePrefix) {
+ def innerJson = (1..numberOfElements).collect {'"' + valuePrefix + '-' + it + '"'}.join(',')
+ return '"' + name + '":[' + innerJson + ']'
+ }
+
+ // *** NCMP Integration Test Utilities ***
+
+ def registerCmHandle(dmiPlugin, cmHandleId, moduleSetTag) {
+ def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: cmHandleId, moduleSetTag: moduleSetTag)
+ networkCmProxyDataService.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: dmiPlugin, createdCmHandles: [cmHandleToCreate]))
+ moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
+ new PollingConditions().within(3, () -> {
+ CmHandleState.READY == networkCmProxyDataService.getCmHandleCompositeState(cmHandleId).cmHandleState
+ })
+ }
+
+ def deregisterCmHandle(dmiPlugin, cmHandleId) {
+ deregisterCmHandles(dmiPlugin, [cmHandleId])
+ }
+
+ def deregisterCmHandles(dmiPlugin, cmHandleIds) {
+ networkCmProxyDataService.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: dmiPlugin, removedCmHandles: cmHandleIds))
+ }
+
+ def mockDmiResponsesForModuleSync(dmiPlugin, cmHandleId, dmiModuleReferencesResponse, dmiModuleResourcesResponse) {
+ mockDmiServer.expect(requestTo("${dmiPlugin}/dmi/v1/ch/${cmHandleId}/modules"))
+ .andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(dmiModuleReferencesResponse))
+ mockDmiServer.expect(requestTo("${dmiPlugin}/dmi/v1/ch/${cmHandleId}/moduleResources"))
+ .andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(dmiModuleResourcesResponse))
+ }
+
+ def mockDmiIsNotAvailableForModuleSync(dmiPlugin, cmHandleId) {
+ mockDmiServer.expect(requestTo("${dmiPlugin}/dmi/v1/ch/${cmHandleId}/modules"))
+ .andRespond(withStatus(HttpStatus.SERVICE_UNAVAILABLE))
+ }
+
+ def mockDmiWillRespondToHealthChecks(dmiPlugin) {
+ mockDmiServer.expect(ExpectedCount.between(0, Integer.MAX_VALUE), requestTo("${dmiPlugin}/actuator/health"))
+ .andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body('{"status":"UP"}'))
+ }
+
+ def overrideCmHandleLastUpdateTime(cmHandleId, newUpdateTime) {
+ String ISO_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
+ DateTimeFormatter ISO_TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern(ISO_TIMESTAMP_PATTERN);
+ def jsonForUpdate = '{ "state": { "last-update-time": "%s" } }'.formatted(ISO_TIMESTAMP_FORMATTER.format(newUpdateTime))
+ cpsDataService.updateNodeLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='${cmHandleId}']", jsonForUpdate, now)
+ }