diff options
author | 2023-04-14 16:25:18 +0100 | |
---|---|---|
committer | 2023-04-18 15:41:17 +0100 | |
commit | 5a87ef15be1dd27dedacb748c58add2502e956c5 (patch) | |
tree | cd1ed00a275d6e8ce9fb75fe6a1c174abc300d44 /gui-clamp/ui-react/src/api | |
parent | 02de4ef3ee93b49abd74821a0dfbd4b185ce7246 (diff) |
Restructure policy-gui repo
- Removed gui-clamp module
- Added gui-runtime module
- Created gui-acm for future gui development work
Issue-ID: POLICY-4638
Change-Id: I6d6468ae1c83d39e5b837f1dadf42bda5671ee70
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'gui-clamp/ui-react/src/api')
18 files changed, 0 insertions, 3217 deletions
diff --git a/gui-clamp/ui-react/src/api/ACMService.js b/gui-clamp/ui-react/src/api/ACMService.js deleted file mode 100644 index a03aac2..0000000 --- a/gui-clamp/ui-react/src/api/ACMService.js +++ /dev/null @@ -1,180 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -export default class ACMService { - - static async getACMInstantiation() { - - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/instantiation'); - - return response - } - - static async createInstanceProperties(instancePropertiesTemplate) { - - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/instanceProperties', { - method: 'POST', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin', - body: JSON.stringify(instancePropertiesTemplate), - }); - - return response - } - - static async updateInstanceProperties(instanceName, version, instancePropertiesTemplate) { - const params = { - name: instanceName, - version: version - } - - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/instanceProperties?' + (new URLSearchParams(params)), { - method: 'PUT', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin', - body: JSON.stringify(instancePropertiesTemplate), - }); - - return response - } - - static async deleteInstantiation(name, version) { - const params = { - name: name, - version: version - } - - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/instanceProperties?' + (new URLSearchParams(params)), { - method: 'DELETE', - credentials: 'same-origin', - }); - - const data = await response; - - return data; - } - - static async getInstanceOrderState(name, version) { - const params = { - name: name, - version: version - } - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/instantiationState'+ '?' + (new URLSearchParams(params))); - - const data = await response; - - return data; - } - - static async changeInstanceOrderState(toscaObject) { - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/instantiation/command', { - method: 'PUT', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin', - body: JSON.stringify(toscaObject) - }); - - return response - } - - static async getToscaTemplate(name, version, instanceName) { - const params = instanceName != null ? - { - name: name, - version: version, - instanceName: instanceName - } : - { - name: name, - version: version - } - - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/commission/toscaservicetemplate' + '?' + (new URLSearchParams(params))); - - const data = await response; - - return data; - } - - static async uploadToscaFile(toscaObject) { - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/commission', { - method: 'POST', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin', - body: JSON.stringify(toscaObject), - }); - - return response - - } - - static async deleteToscaTemplate(name, version) { - const params = { - name: name, - version: version - } - - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/commission' + '?' + (new URLSearchParams(params)), - { - method: 'DELETE' - }); - - const data = await response; - - return data; - } - - static async getCommonOrInstanceProperties(name, version, instanceName, isCommon) { - const params = instanceName != null ? - { - name: name, - version: version, - instanceName: instanceName, - common: isCommon - } : - { - name: name, - version: version, - common: isCommon - } - - const response = await fetch(window.location.pathname + - 'onap/policy/clamp/acm/v2/commission/getCommonOrInstanceProperties' + '?' + (new URLSearchParams(params))); - - return response; - } - -} diff --git a/gui-clamp/ui-react/src/api/ACMService.test.js b/gui-clamp/ui-react/src/api/ACMService.test.js deleted file mode 100644 index e4a3837..0000000 --- a/gui-clamp/ui-react/src/api/ACMService.test.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -import ACMService from "./ACMService"; - -describe("Verify GetACMInstantiation", () => { - let response; - let name = "name"; - let template = "template"; - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Success", - ok: true, - }) - ); - beforeEach(async () => { - response = await ACMService.getACMInstantiation(name, template); - }); - it("Test getACMInstantiation", () => { - expect(response.status).toEqual("Success"); - }); -}); -describe("Verify DeleteInstantiation", () => { - let response; - let name = "name"; - let version = "version"; - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Success", - ok: true, - }) - ); - beforeEach(async () => { - response = await ACMService.deleteInstantiation(name, version); - }); - it("Test deleteInstantiation", () => { - expect(response.status).toEqual("Success"); - }); -}); diff --git a/gui-clamp/ui-react/src/api/LoopActionService.js b/gui-clamp/ui-react/src/api/LoopActionService.js deleted file mode 100644 index 6f3b22f..0000000 --- a/gui-clamp/ui-react/src/api/LoopActionService.js +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -export default class LoopActionService { - - static performAction(cl_name, uiAction) { - console.info("LoopActionService perform action: " + uiAction + " closedloopName=" + cl_name); - const svcAction = uiAction.toLowerCase(); - return fetch(window.location.pathname + "restservices/clds/v2/loop/" + svcAction + "/" + cl_name, { - method: 'PUT', - credentials: 'same-origin' - }) - .then(function (response) { - if (response.ok) { - return response; - } else { - return Promise.reject("Perform action failed with code:" + response.status); - } - }) - .then(function (data) { - console.info("Action Successful: " + uiAction); - return data; - }) - .catch(function (error) { - console.info("Action Failure: " + uiAction); - return Promise.reject(error); - }); - } - - - static refreshStatus(cl_name) { - console.info("Refresh the status for closedloopName=" + cl_name); - - return fetch(window.location.pathname + "restservices/clds/v2/loop/getstatus/" + cl_name, { - method: 'GET', - credentials: 'same-origin' - }) - .then(function (response) { - if (response.ok) { - return response.json(); - } else { - return Promise.reject("Refresh status failed with code:" + response.status); - } - }) - .then(function (data) { - console.info("Refresh status Successful"); - return data; - }) - .catch(function (error) { - console.info("Refresh status failed:", error); - return Promise.reject(error); - }); - } -} diff --git a/gui-clamp/ui-react/src/api/LoopActionService.test.js b/gui-clamp/ui-react/src/api/LoopActionService.test.js deleted file mode 100644 index 4253c8c..0000000 --- a/gui-clamp/ui-react/src/api/LoopActionService.test.js +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -import LoopActionService from "./LoopActionService"; - -describe("Verify PerformAction", () => { - let response; - let cl_name = "name"; - let uiAction = "action"; - describe("Response Ok Check", () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Success", - ok: true, - }) - ); - beforeEach(async () => { - response = await LoopActionService.performAction(cl_name, uiAction); - }); - it("Test performAction returns correct response status", () => { - expect(response.ok).toEqual(true); - }); - }); -}); -describe("Verify RefreshStatus", () => { - let response; - let cl_name = "name"; - describe("Response Ok Check", () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "name" }), - status: "Success", - ok: true, - }) - ); - beforeEach(async () => { - response = await LoopActionService.refreshStatus(cl_name); - }); - it("Test refreshStatus returns correct response", () => { - expect(response).toEqual({ name: "name" }); - }); - }); -}); diff --git a/gui-clamp/ui-react/src/api/LoopCache.js b/gui-clamp/ui-react/src/api/LoopCache.js deleted file mode 100644 index ac2da07..0000000 --- a/gui-clamp/ui-react/src/api/LoopCache.js +++ /dev/null @@ -1,252 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -export default class LoopCache { - loopJsonCache; - - constructor(loopJson) { - this.loopJsonCache = loopJson; - } - - updateMicroServiceProperties(name, newMsProperties) { - for (var policy in this.loopJsonCache["microServicePolicies"]) { - if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) { - this.loopJsonCache["microServicePolicies"][policy]["configurationsJson"] = newMsProperties; - } - } - } - - updateMicroServicePdpGroup(name, pdpGroup, pdpSubgroup) { - for (var policy in this.loopJsonCache["microServicePolicies"]) { - if (this.loopJsonCache["microServicePolicies"][policy]["name"] === name) { - this.loopJsonCache["microServicePolicies"][policy]["pdpGroup"] = pdpGroup; - this.loopJsonCache["microServicePolicies"][policy]["pdpSubgroup"] = pdpSubgroup; - } - } - } - - updateGlobalProperties(newGlobalProperties) { - this.loopJsonCache["globalPropertiesJson"] = newGlobalProperties; - } - - updateOperationalPolicyProperties(name, newOpProperties) { - for (var policy in this.loopJsonCache["operationalPolicies"]) { - if (this.loopJsonCache["operationalPolicies"][policy]["name"] === name) { - this.loopJsonCache["operationalPolicies"][policy]["configurationsJson"] = newOpProperties; - } - } - } - - updateOperationalPolicyPdpGroup(name, pdpGroup, pdpSubgroup) { - for (var policy in this.loopJsonCache["operationalPolicies"]) { - if (this.loopJsonCache["operationalPolicies"][policy]["name"] === name) { - this.loopJsonCache["operationalPolicies"][policy]["pdpGroup"] = pdpGroup; - this.loopJsonCache["operationalPolicies"][policy]["pdpSubgroup"] = pdpSubgroup; - } - } - } - - getLoopName() { - return this.loopJsonCache["name"]; - } - - getOperationalPolicyJsonSchema() { - return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"]; - } - - getOperationalPolicies() { - return this.loopJsonCache["operationalPolicies"]; - } - - getOperationalPoliciesNoJsonSchema() { - var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"])); - delete operationalPolicies[0]["jsonRepresentation"]; - return operationalPolicies; - } - - getGlobalProperties() { - return this.loopJsonCache["globalPropertiesJson"]; - } - - getDcaeDeploymentProperties() { - return this.loopJsonCache["globalPropertiesJson"]["dcaeDeployParameters"]; - } - - getMicroServicePolicies() { - return this.loopJsonCache["microServicePolicies"]; - } - - getOperationalPolicyForName(name) { - var opProperties = this.getOperationalPolicies(); - for (var policy in opProperties) { - if (opProperties[policy]["name"] === name) { - return opProperties[policy]; - } - } - return null; - } - - getOperationalPolicyPropertiesForName(name) { - var opConfig = this.getOperationalPolicyForName(name); - if (opConfig !== null) { - return opConfig["configurationsJson"]; - } - return null; - } - - getOperationalPolicyJsonRepresentationForName(name) { - var opConfig = this.getOperationalPolicyForName(name); - if (opConfig !== null) { - return opConfig["jsonRepresentation"]; - } - return null; - } - - getOperationalPolicySupportedPdpGroup(name) { - var opConfig = this.getOperationalPolicyForName(name); - if (opConfig !== null) { - if (opConfig["policyModel"]["policyPdpGroup"] !== undefined && opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"] !== undefined) { - return opConfig["policyModel"]["policyPdpGroup"]["supportedPdpGroups"]; - } - } - return []; - } - - getOperationalPolicyPdpGroup(name) { - var opConfig = this.getOperationalPolicyForName(name); - if (opConfig !== null) { - return opConfig["pdpGroup"]; - } - return null; - } - - getOperationalPolicyPdpSubgroup(name) { - var opConfig = this.getOperationalPolicyForName(name); - if (opConfig !== null) { - return opConfig["pdpSubgroup"]; - } - return null; - } - - getMicroServiceSupportedPdpGroup(name) { - var microService = this.getMicroServiceForName(name); - if (microService !== null) { - if (microService["policyModel"]["policyPdpGroup"] !== undefined && microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"] !== undefined) { - return microService["policyModel"]["policyPdpGroup"]["supportedPdpGroups"]; - } - } - return []; - } - - getMicroServicePdpGroup(name) { - var microService = this.getMicroServiceForName(name); - if (microService !== null) { - return microService["pdpGroup"]; - } - return null; - } - - getMicroServicePdpSubgroup(name) { - var microService = this.getMicroServiceForName(name); - if (microService !== null) { - return microService["pdpSubgroup"]; - } - return null; - } - - getMicroServiceForName(name) { - var msProperties = this.getMicroServicePolicies(); - for (var policy in msProperties) { - if (msProperties[policy]["name"] === name) { - return msProperties[policy]; - } - } - return null; - } - - getMicroServicePropertiesForName(name) { - var msConfig = this.getMicroServiceForName(name); - if (msConfig !== null) { - return msConfig["configurationsJson"]; - } - return null; - } - - getMicroServiceJsonRepresentationForName(name) { - var msConfig = this.getMicroServiceForName(name); - if (msConfig !== null) { - return msConfig["jsonRepresentation"]; - } - return null; - } - - getResourceDetailsVfProperty() { - return this.loopJsonCache["modelService"]["resourceDetails"]["VF"]; - } - - getResourceDetailsVfModuleProperty() { - return this.loopJsonCache["modelService"]["resourceDetails"]["VFModule"]; - } - - getLoopLogsArray() { - return this.loopJsonCache.loopLogs; - } - - getComputedState() { - return this.loopJsonCache.lastComputedState; - } - - getComponentStates() { - return this.loopJsonCache.components; - } - - getTemplateName() { - if (this.getLoopTemplate() !== undefined) { - return this.getLoopTemplate().name; - } - return null; - } - - getLoopTemplate() { - return this.loopJsonCache["loopTemplate"]; - } - - isOpenLoopTemplate() { - var loopTemplate = this.getLoopTemplate(); - if (loopTemplate != null && loopTemplate["allowedLoopType"] === "OPEN") { - return true; - } - return false; - } - - getAllLoopElementModels() { - var loopTemplate = this.getLoopTemplate(); - var loopElementModels = []; - if (loopTemplate != null) { - for (var element of loopTemplate['loopElementModelsUsed']) { - loopElementModels.push(element['loopElementModel']) - } - } - return loopElementModels; - } -} diff --git a/gui-clamp/ui-react/src/api/LoopCache.test.js b/gui-clamp/ui-react/src/api/LoopCache.test.js deleted file mode 100644 index eff2e65..0000000 --- a/gui-clamp/ui-react/src/api/LoopCache.test.js +++ /dev/null @@ -1,305 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ -import LoopCache from '../api/LoopCache'; - -const json = require('./LoopCacheMockFile.json'); - -describe('Verify LoopCache functions', () => { - const loopCache = new LoopCache(json); - it('getLoopName', () => { - expect(loopCache.getLoopName()).toBe("LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca"); - }); - - it('getOperationalPolicies', () => { - const opPolicy = [{ - "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", - "configurationsJson": { - "operational_policy": { - "acm": {}, - "policies": [] - } - }, - "pdpGroup": "pdpGroupTest", - "pdpSubgroup": "pdpSubgroupTest", - "jsonRepresentation": { - "schema": {} - } - }]; - expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy); - }); - - it('getOperationalPoliciesNoJsonSchema', () => { - const opPolicy = [{ - "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", - "configurationsJson": { - "operational_policy": { - "acm": {}, - "policies": [] - } - }, - "pdpGroup": "pdpGroupTest", - "pdpSubgroup": "pdpSubgroupTest", - }]; - expect(loopCache.getOperationalPoliciesNoJsonSchema()).toStrictEqual(opPolicy); - }); - - it('getOperationalPolicyJsonSchema', () => { - const jsonSchema = { - "schema": {} - }; - - expect(loopCache.getOperationalPolicyJsonSchema()).toStrictEqual(jsonSchema); - }); - it('getGlobalProperties', () => { - const globelProp = { - "dcaeDeployParameters": { - "location_id": "", - "service_id": "", - "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" - } - }; - expect(loopCache.getGlobalProperties()).toStrictEqual(globelProp); - }); - - it('getDcaeDeploymentProperties', () => { - const deploymentProp = { - "location_id": "", - "service_id": "", - "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" - }; - expect(loopCache.getDcaeDeploymentProperties()).toStrictEqual(deploymentProp); - }); - - it('getMicroServiceForName', () => { - const msJson = { - "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca", - "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app", - "configurationsJson": {"domain": "measurementsForVfScaling"}, - "shared": false, - "pdpGroup": "pdpGroupTest", - "pdpSubgroup": "pdpSubgroupTest", - "policyModel": {"policyPdpGroup": {"supportedPdpGroups": "supportedPdpGroupsTest"}}, - "jsonRepresentation": {"schema": {}} - }; - expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson); - expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull(); - }); - - it('getMicroServicePropertiesForName', () => { - const msProp = {"domain": "measurementsForVfScaling"}; - expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp); - expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull(); - }); - - it('getMicroServiceJsonRepresentationForName', () => { - const msJsonRepresentation = {"schema": {}}; - expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation); - }); - - it('getResourceDetailsVfProperty', () => { - const resourceVF = { - "vLoadBalancerMS 0": { - "resourceVendor": "Test", - "resourceVendorModelNumber": "", - "name": "vLoadBalancerMS", - "description": "vLBMS", - "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506", - "subcategory": "Load Balancer", - "category": "Application L4+", - "type": "VF", - "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6", - "version": "1.0", - "resourceVendorRelease": "1.0", - "customizationUUID": "465246dc-7748-45f4-a013-308d92922552" - } - }; - expect(loopCache.getResourceDetailsVfProperty()).toStrictEqual(resourceVF); - }); - - it('getResourceDetailsVfModuleProperty', () => { - const vfModule = { - "Vloadbalancerms..vpkg..module-1": { - "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043", - "vfModuleModelVersion": "1", - "vfModuleModelName": "Vloadbalancerms..vpkg..module-1", - "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc", - "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52", - "min_vf_module_instances": 0, - "vf_module_label": "vpkg", - "max_vf_module_instances": 1, - "vf_module_type": "Expansion", - "isBase": false, - "initial_count": 0, - "volume_group": false - } - }; - expect(loopCache.getResourceDetailsVfModuleProperty()).toStrictEqual(vfModule); - }); - - it('getLoopLogsArray', () => { - const logs = [ - { - "id": 1, - "logType": "INFO", - "logComponent": "CLAMP", - "message": "Operational policies UPDATED", - "logInstant": "2019-07-08T09:44:37Z" - } - ]; - expect(loopCache.getLoopLogsArray()).toStrictEqual(logs); - }); - - it('getComponentStates', () => { - const component = { - "POLICY": { - "componentState": { - "stateName": "NOT_SENT", - "description": "The policies defined have NOT yet been created on the policy engine" - } - }, - "DCAE": { - "componentState": { - "stateName": "BLUEPRINT_DEPLOYED", - "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop" - } - } - }; - expect(loopCache.getComponentStates()).toStrictEqual(component); - }); - - it('getOperationalPolicyForName', () => { - const opPolicy = { - "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", - "configurationsJson": { - "operational_policy": { - "acm": {}, - "policies": [] - } - }, - "pdpGroup": "pdpGroupTest", - "pdpSubgroup": "pdpSubgroupTest", - "jsonRepresentation": { - "schema": {} - } - }; - expect(loopCache.getOperationalPolicyForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicy); - expect(loopCache.getOperationalPolicyForName("Not_Exist")).toBeNull(); - }); - - it('getOperationalPolicyPropertiesForName', () => { - const opPolicyJson = { - "operational_policy": { - "acm": {}, - "policies": [] - }}; - expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicyJson); - expect(loopCache.getOperationalPolicyPropertiesForName("Not_Exist")).toBeNull(); - }); - - it('getOperationalPolicyJsonRepresentationForName', () => { - const opPolicySchema = { - "schema": {} - }; - expect(loopCache.getOperationalPolicyJsonRepresentationForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicySchema); - expect(loopCache.getOperationalPolicyJsonRepresentationForName("Not_Exist")).toBeNull(); - }); - - it('getOperationalPolicySupportedPdpGroup', () => { - expect(loopCache.getOperationalPolicySupportedPdpGroup("Not_Exist")).toStrictEqual([]); - }); - - it('getOperationalPolicyPdpGroup', () => { - expect(loopCache.getOperationalPolicyPdpGroup("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest"); - expect(loopCache.getOperationalPolicyPdpGroup("Not_Exist")).toBeNull(); - }); - - it('getOperationalPolicyPdpSubgroup', () => { - expect(loopCache.getOperationalPolicyPdpSubgroup("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest"); - expect(loopCache.getOperationalPolicyPdpSubgroup("Not_Exist")).toBeNull(); - }); - - it('getMicroServiceSupportedPdpGroup', () => { - expect(loopCache.getMicroServiceSupportedPdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("supportedPdpGroupsTest"); - expect(loopCache.getMicroServiceSupportedPdpGroup("Not_Exist")).toStrictEqual([]); - }); - - it('getMicroServicePdpGroup', () => { - expect(loopCache.getMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest"); - expect(loopCache.getMicroServicePdpGroup("Not_Exist")).toBeNull(); - }); - - it('getMicroServicePdpSubgroup', () => { - expect(loopCache.getMicroServicePdpSubgroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest"); - expect(loopCache.getMicroServicePdpSubgroup("Not_Exist")).toBeNull(); - }); - - it('getMicroServiceJsonRepresentationForName', () => { - const msPolicySchema = { - "schema": {} - }; - expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msPolicySchema); - expect(loopCache.getMicroServiceJsonRepresentationForName("Not_Exist")).toBeNull(); - }); - - it('getTemplateName', () => { - expect(loopCache.getTemplateName()).toStrictEqual("loopTemplateTest"); - }); - - it('updateGlobalProperties', () => { - const newGlobalProps = { - "dcaeDeployParameters": { - "location_id": "newLocation", - "service_id": "newServiceId", - "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2" - } - }; - loopCache.updateGlobalProperties(newGlobalProps); - expect(loopCache.getGlobalProperties()).toStrictEqual(newGlobalProps); - }); - - it('updateOperationalPolicyProperties', () => { - const newOpPolicy = { - "operational_policy": { - "acm": {}, - "policies": [] - } - }; - loopCache.updateOperationalPolicyProperties("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",newOpPolicy); - expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newOpPolicy); - }); - - it('updateMicroServiceProperties', () => { - const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"}; - loopCache.updateMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", newMsPolicyProperties); - expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newMsPolicyProperties); - }); - - it('updateMicroServicePdpGroup', () => { - const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"}; - loopCache.updateMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", "pdpGroupTest1", "pdpSubgroupTest1"); - expect(loopCache.getMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest1"); - expect(loopCache.getMicroServicePdpGroup("Not_Exist")).toBeNull(); - expect(loopCache.getMicroServicePdpSubgroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest1"); - expect(loopCache.getMicroServicePdpSubgroup("Not_Exist")).toBeNull(); - }); - }); diff --git a/gui-clamp/ui-react/src/api/LoopCacheMockFile.json b/gui-clamp/ui-react/src/api/LoopCacheMockFile.json deleted file mode 100644 index 733fcaa..0000000 --- a/gui-clamp/ui-react/src/api/LoopCacheMockFile.json +++ /dev/null @@ -1,135 +0,0 @@ -{ - "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca", - "dcaeBlueprintId": "typeId-3a942643-a8f7-4e54-b2c1-eea8daba2b17", - "globalPropertiesJson": { - "dcaeDeployParameters": { - "location_id": "", - "service_id": "", - "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" - } - }, - "loopTemplate": { - "name": "loopTemplateTest" - }, - "modelService": { - "serviceDetails": { - "serviceType": "", - "namingPolicy": "", - "environmentContext": "General_Revenue-Bearing", - "serviceEcompNaming": "true", - "serviceRole": "", - "name": "vLoadBalancerMS", - "description": "vLBMS", - "invariantUUID": "30ec5b59-4799-48d8-ac5f-1058a6b0e48f", - "ecompGeneratedNaming": "true", - "category": "Network L4+", - "type": "Service", - "UUID": "63cac700-ab9a-4115-a74f-7eac85e3fce0", - "instantiationType": "A-la-carte" - }, - "resourceDetails": { - "CP": {}, - "VL": {}, - "VF": { - "vLoadBalancerMS 0": { - "resourceVendor": "Test", - "resourceVendorModelNumber": "", - "name": "vLoadBalancerMS", - "description": "vLBMS", - "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506", - "subcategory": "Load Balancer", - "category": "Application L4+", - "type": "VF", - "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6", - "version": "1.0", - "resourceVendorRelease": "1.0", - "customizationUUID": "465246dc-7748-45f4-a013-308d92922552" - } - }, - "CR": {}, - "VFC": {}, - "PNF": {}, - "Service": {}, - "CVFC": {}, - "Service Proxy": {}, - "Configuration": {}, - "AllottedResource": {}, - "VFModule": { - "Vloadbalancerms..vpkg..module-1": { - "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043", - "vfModuleModelVersion": "1", - "vfModuleModelName": "Vloadbalancerms..vpkg..module-1", - "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc", - "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52", - "min_vf_module_instances": 0, - "vf_module_label": "vpkg", - "max_vf_module_instances": 1, - "vf_module_type": "Expansion", - "isBase": false, - "initial_count": 0, - "volume_group": false - } - } - } - }, - "lastComputedState": "DESIGN", - "components": { - "POLICY": { - "componentState": { - "stateName": "NOT_SENT", - "description": "The policies defined have NOT yet been created on the policy engine" - } - }, - "DCAE": { - "componentState": { - "stateName": "BLUEPRINT_DEPLOYED", - "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop" - } - } - }, - "operationalPolicies": [ - { - "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", - "configurationsJson": { - "operational_policy": { - "acm": {}, - "policies": [] - } - }, - "pdpGroup": "pdpGroupTest", - "pdpSubgroup": "pdpSubgroupTest", - "jsonRepresentation": { - "schema": {} - } - } - ], - "microServicePolicies": [ - { - "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca", - "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app", - "configurationsJson": { - "domain": "measurementsForVfScaling" - }, - "shared": false, - "pdpGroup": "pdpGroupTest", - "pdpSubgroup": "pdpSubgroupTest", - "policyModel": { - "policyPdpGroup": { - "supportedPdpGroups": "supportedPdpGroupsTest" - } - }, - "jsonRepresentation": { - "schema": {} - } - } - ], - "loopLogs": [ - { - "id": 1, - "logType": "INFO", - "logComponent": "CLAMP", - "message": "Operational policies UPDATED", - "logInstant": "2019-07-08T09:44:37Z" - } - ] -} diff --git a/gui-clamp/ui-react/src/api/LoopService.js b/gui-clamp/ui-react/src/api/LoopService.js deleted file mode 100644 index 16f1bec..0000000 --- a/gui-clamp/ui-react/src/api/LoopService.js +++ /dev/null @@ -1,244 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -export default class LoopService { - static getLoopNames() { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/getAllNames', { method: 'GET', credentials: 'same-origin' }) - .then(function (response) { - console.debug("GetLoopNames response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("GetLoopNames query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("GetLoopNames error received", error); - return {}; - }); - } - - static createLoop(loopName, templateName) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/create/' + loopName + '?templateName=' + templateName, { - method: 'POST', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("CreateLoop response received: ", response.status); - return response.json(); - }) - .catch(function (error) { - console.error("CreateLoop error received", error); - return ""; - }); - } - - static getLoop(loopName) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/' + loopName, { - method: 'GET', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("GetLoop response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("GetLoop query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("GetLoop error received", error); - return {}; - }); - } - - static setMicroServiceProperties(loopName, jsonData) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateMicroservicePolicy/' + loopName, { - method: 'POST', - credentials: 'same-origin', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(jsonData) - }) - .then(function (response) { - console.debug("updateMicroservicePolicy response received: ", response.status); - if (response.ok) { - return response.text(); - } else { - console.error("updateMicroservicePolicy query failed"); - return ""; - } - }) - .catch(function (error) { - console.error("updateMicroservicePolicy error received", error); - return ""; - }); - } - - static setOperationalPolicyProperties(loopName, jsonData) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateOperationalPolicies/' + loopName, { - method: 'POST', - credentials: 'same-origin', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(jsonData) - }) - .then(function (response) { - console.debug("updateOperationalPolicies response received: ", response.status); - if (response.ok) { - return response.text(); - } else { - console.error("updateOperationalPolicies query failed"); - return ""; - } - }) - .catch(function (error) { - console.error("updateOperationalPolicies error received", error); - return ""; - }); - } - - static updateGlobalProperties(loopName, jsonData) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateGlobalProperties/' + loopName, { - method: 'POST', - credentials: 'same-origin', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(jsonData) - }) - .then(function (response) { - console.debug("updateGlobalProperties response received: ", response.status); - if (response.ok) { - return response.text(); - } else { - console.error("updateGlobalProperties query failed"); - return ""; - } - }) - .catch(function (error) { - console.error("updateGlobalProperties error received", error); - return ""; - }); - } - - static refreshOperationalPolicyJson(loopName, operationalPolicyName) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/refreshOperationalPolicyJsonSchema/' + loopName + '/' + operationalPolicyName, { - method: 'PUT', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("Refresh Operational Policy Json Schema response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("Refresh Operational Policy Json Schema query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("Refresh Operational Policy Json Schema error received", error); - return {}; - }); - } - - static refreshMicroServicePolicyJson(loopName, microServicePolicyName) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/refreshMicroServicePolicyJsonSchema/' + loopName + '/' + microServicePolicyName, { - method: 'PUT', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("Refresh Operational Policy Json Schema response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("Refresh Operational Policy Json Schema query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("Refresh Operational Policy Json Schema error received", error); - return {}; - }); - } - - static addOperationalPolicyType(loopName, policyType, policyVersion) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/addOperationaPolicy/' + loopName + '/policyModel/' + policyType + '/' + policyVersion, { - method: 'PUT', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("Add Operational Policy response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - return response.text(); - } - }) - .catch(function (error) { - console.error("Add Operational Policy query failed"); - throw new Error(error); - }) - } - - static removeOperationalPolicyType(loopName, policyType, policyVersion, policyName) { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/removeOperationaPolicy/' + loopName + '/policyModel/' + policyType + '/' + policyVersion + '/' + policyName, { - method: 'PUT', - headers: { - "Content-Type": "application/json" - }, - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("Remove Operational Policy response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("Remove Operational Policy query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("Remove Operational Policy error received", error); - return {}; - }); - } -} diff --git a/gui-clamp/ui-react/src/api/LoopService.test.js b/gui-clamp/ui-react/src/api/LoopService.test.js deleted file mode 100644 index bd68582..0000000 --- a/gui-clamp/ui-react/src/api/LoopService.test.js +++ /dev/null @@ -1,443 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -import LoopService from "./LoopService"; - -describe("Verify GetLoopNames", () => { - let response; - let loopNameJson; - describe("Non-Empty Json Check", () => { - loopNameJson = { name: "loop1" }; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - beforeEach(async () => { - response = await LoopService.getLoopNames(); - }); - it("Test getLoopNames returns correct json", () => { - expect(response).toEqual(loopNameJson); - }); - }); - describe("Empty Json Check", () => { - loopNameJson = {}; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({}), - status: "Failed", - ok: false, - }) - ); - beforeEach(async () => { - response = await LoopService.getLoopNames(); - }); - it("Test getLoopNames returns empty json", () => { - expect(response).toEqual(loopNameJson); - }); - }); - describe("Error during API call", () => { - loopNameJson = {}; - beforeEach(async () => { - response = await LoopService.getLoopNames(); - }); - it("Test getLoopNames returns empty json", () => { - expect(response).toEqual(loopNameJson); - }); - }); -}); - -describe("Verify CreateLoop", () => { - let response; - let loopNameJson; - let loopName = "loop1"; - let templateName = "template1"; - describe("Non-Empty Json Check", () => { - loopNameJson = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await LoopService.createLoop(loopName, templateName); - }); - - it("Test createLoop returns correct json", () => { - expect(response).toEqual(loopNameJson); - }); - }); - describe("Error during API call", () => { - let emptyResponse = ""; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve(""), - }) - ); - response = await LoopService.createLoop("", ""); - }); - it("Test createLoop returns empty", () => { - expect(response).toEqual(emptyResponse); - }); - }); -}); -describe("Verify GetLoop", () => { - let actualResponse; - let expected; - let name = "loop1"; - describe("Non-Empty Json Check", () => { - beforeEach(async () => { - expected = { name: "loop1" }; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - actualResponse = await LoopService.getLoop(name); - }); - - it("Test getLoop returns correct json", () => { - expect(actualResponse).toEqual(expected); - }); - }); - describe("Error during API call", () => { - beforeEach(async () => { - expected = {}; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({}), - }) - ); - actualResponse = await LoopService.getLoop(name); - }); - it("Test getLoop returns empty", () => { - expect(actualResponse).toEqual(expected); - }); - }); -}); -describe("Verify SetMicroServiceProperties", () => { - let actualResponse; - let expected; - let name = "loop1"; - let jsonData = {}; - describe("Non-Empty Text Check", () => { - beforeEach(async () => { - expected = "data"; - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve("data"), - status: "Success", - ok: true, - }) - ); - actualResponse = await LoopService.setMicroServiceProperties( - name, - jsonData - ); - }); - - it("Test setMicroServiceProperties returns correct text", () => { - expect(actualResponse).toEqual(expected); - }); - }); - describe("Error during API call", () => { - beforeEach(async () => { - expected = ""; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve(""), - }) - ); - actualResponse = await LoopService.setMicroServiceProperties( - name, - jsonData - ); - }); - it("Test setMicroServiceProperties returns empty", () => { - expect(actualResponse).toEqual(expected); - }); - }); -}); -describe("Verify SetOperationalPolicyProperties", () => { - let actualResponse; - let expected; - let name = "loop1"; - let jsonData = {}; - describe("Non-Empty Text Check", () => { - beforeEach(async () => { - expected = "data"; - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve("data"), - status: "Success", - ok: true, - }) - ); - actualResponse = await LoopService.setOperationalPolicyProperties( - name, - jsonData - ); - }); - - it("Test setOperationalPolicyProperties returns correct text", () => { - expect(actualResponse).toEqual(expected); - }); - }); - describe("Error during API call", () => { - beforeEach(async () => { - expected = ""; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve(""), - }) - ); - actualResponse = await LoopService.setOperationalPolicyProperties( - name, - jsonData - ); - }); - it("Test setOperationalPolicyProperties returns empty", () => { - expect(actualResponse).toEqual(expected); - }); - }); -}); -describe("Verify UpdateGlobalProperties", () => { - let actualResponse; - let expected; - let name = "loop1"; - let jsonData = {}; - describe("Non-Empty Text Check", () => { - beforeEach(async () => { - expected = "data"; - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve("data"), - status: "Success", - ok: true, - }) - ); - actualResponse = await LoopService.updateGlobalProperties(name, jsonData); - }); - - it("Test updateGlobalProperties returns correct text", () => { - expect(actualResponse).toEqual(expected); - }); - }); - describe("Error during API call", () => { - beforeEach(async () => { - expected = ""; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve(""), - }) - ); - actualResponse = await LoopService.updateGlobalProperties(name, jsonData); - }); - it("Test updateGlobalProperties returns empty", () => { - expect(actualResponse).toEqual(expected); - }); - }); -}); -describe("Verify RefreshOperationalPolicyJson", () => { - let actualResponse; - let expected; - let name = "loop1"; - let policyName = "policy"; - describe("Non-Empty Json Check", () => { - beforeEach(async () => { - expected = { name: "loop1" }; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - actualResponse = await LoopService.refreshOperationalPolicyJson( - name, - policyName - ); - }); - - it("Test refreshOperationalPolicyJson returns correct json", () => { - expect(actualResponse).toEqual(expected); - }); - }); - describe("Error during API call", () => { - beforeEach(async () => { - expected = {}; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({}), - }) - ); - actualResponse = await LoopService.refreshOperationalPolicyJson( - name, - policyName - ); - }); - it("Test refreshOperationalPolicyJson returns empty", () => { - expect(actualResponse).toEqual(expected); - }); - }); -}); -describe("Verify RefreshMicroServicePolicyJson", () => { - let actualResponse; - let expected; - let name = "loop1"; - let policyName = "policy"; - describe("Non-Empty Json Check", () => { - beforeEach(async () => { - expected = { name: "loop1" }; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - actualResponse = await LoopService.refreshMicroServicePolicyJson( - name, - policyName - ); - }); - - it("Test refreshMicroServicePolicyJson returns correct json", () => { - expect(actualResponse).toEqual(expected); - }); - }); - describe("Error during API call", () => { - beforeEach(async () => { - expected = {}; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({}), - }) - ); - actualResponse = await LoopService.refreshMicroServicePolicyJson( - name, - policyName - ); - }); - it("Test refreshMicroServicePolicyJson returns empty", () => { - expect(actualResponse).toEqual(expected); - }); - }); -}); -describe("Verify AddOperationalPolicyType", () => { - let actualResponse; - let expected; - let name = "loop1"; - let type = "type"; - let version = "version"; - describe("Non-Empty Json Check", () => { - beforeEach(async () => { - expected = { name: "loop1" }; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - actualResponse = await LoopService.addOperationalPolicyType( - name, - type, - version - ); - }); - - it("Test addOperationalPolicyType returns correct json", () => { - expect(actualResponse).toEqual(expected); - }); - }); - describe("Error during API call", () => { - beforeEach(async () => { - expected = new Error("error"); - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve(expected), - }) - ); - actualResponse = await LoopService.addOperationalPolicyType( - name, - type, - version - ); - }); - it("Test addOperationalPolicyType returns empty", () => { - expect(actualResponse).toEqual(expected); - }); - }); -}); -describe("Verify RemoveOperationalPolicyType", () => { - let actualResponse; - let expected; - let name = "loop1"; - let type = "type"; - let version = "version"; - let policyName = "policy"; - describe("Non-Empty Json Check", () => { - beforeEach(async () => { - expected = { name: "loop1" }; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - actualResponse = await LoopService.removeOperationalPolicyType( - name, - type, - version, - policyName - ); - }); - - it("Test removeOperationalPolicyType returns correct json", () => { - expect(actualResponse).toEqual(expected); - }); - }); - describe("Error during API call", () => { - beforeEach(async () => { - expected = {}; - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({}), - }) - ); - actualResponse = await LoopService.removeOperationalPolicyType( - name, - type, - version, - policyName - ); - }); - it("Test removeOperationalPolicyType returns empty", () => { - expect(actualResponse).toEqual(expected); - }); - }); -}); diff --git a/gui-clamp/ui-react/src/api/PoliciesListCacheMockFile.json b/gui-clamp/ui-react/src/api/PoliciesListCacheMockFile.json deleted file mode 100644 index 14d5cc6..0000000 --- a/gui-clamp/ui-react/src/api/PoliciesListCacheMockFile.json +++ /dev/null @@ -1,215 +0,0 @@ -{ - "policies": [ - { - "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0": { - "type": "onap.policies.monitoring.tcagen2", - "type_version": "1.0.0", - "properties": { - "tca.policy": { - "domain": "measurementsForVfScaling", - "metricsPerEventName": [ - { - "policyScope": "DCAE", - "thresholds": [ - { - "version": "1.0.2", - "severity": "MAJOR", - "thresholdValue": 200, - "closedLoopEventStatus": "ONSET", - "closedLoopControlName": "LOOP_test", - "direction": "LESS_OR_EQUAL", - "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta" - } - ], - "eventName": "vLoadBalancer", - "policyVersion": "v0.0.1", - "controlLoopSchemaType": "VM", - "policyName": "DCAE.Config_tca-hi-lo" - } - ] - } - }, - "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", - "version": "1.0.0", - "metadata": { - "policy-id": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", - "policy-version": "1.0.0" - }, - "pdpGroupInfo": { - "pdpGroup": "pdpGroup2", - "pdpSubGroup": "subGroup2" - }, - "supportedPdpGroups": [ - { - "pdpGroup2": [ - "subGroup2", - "subGroup3" - ] - } - ] - } - }, - { - "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd": { - "type": "onap.policies.controlloop.operational.common.Drools", - "type_version": "1.0.0", - "properties": { - "abatement": false, - "operations": [ - { - "failure_retries": "final_failure_retries", - "id": "test1", - "failure_timeout": "final_failure_timeout", - "failure": "final_failure", - "operation": { - "payload": { - "artifact_name": "baseconfiguration", - "artifact_version": "1.0.0", - "mode": "async", - "data": "{\"resource-assignment-properties\":{\"request-id\":\"\",\"service-instance-id\":\"\",\"hostname\":\"\",\"request-info\":{\"prop1\":\"\",\"prop2\":\"\"}}}" - }, - "target": { - "entityIds": { - "resourceID": "Vloadbalancerms..vdns..module-3", - "modelInvariantId": "4c10ba9b-f88f-415e-9de3-5d33336047fa", - "modelVersionId": "4fa73b49-8a6c-493e-816b-eb401567b720", - "modelName": "Vloadbalancerms..vdns..module-3", - "modelVersion": "1", - "modelCustomizationId": "bafcdab0-801d-4d81-9ead-f464640a38b1" - }, - "targetType": "VNF" - }, - "actor": "SDNR", - "operation": "BandwidthOnDemand" - }, - "failure_guard": "final_failure_guard", - "retries": 0, - "timeout": 0, - "failure_exception": "final_failure_exception", - "description": "test", - "success": "final_success" - } - ], - "trigger": "test1", - "timeout": 0, - "id": "LOOP_test" - }, - "name": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", - "version": "1.0.0", - "metadata": { - "policy-id": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", - "policy-version": "1.0.0" - }, - "pdpGroupInfo": { - "pdpGroup": "pdpGroup2", - "pdpSubGroup": "subGroup3" - }, - "supportedPdpGroups": [ - { - "pdpGroup2": [ - "subGroup2", - "subGroup3" - ] - } - ] - } - }, - { - "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP": { - "type": "onap.policies.Naming", - "type_version": "1.0.0", - "properties": { - "naming-models": [ - { - "naming-type": "VNF", - "naming-recipe": "AIC_CLOUD_REGION|DELIMITER|CONSTANT|DELIMITER|TIMESTAMP", - "name-operation": "to_lower_case()", - "naming-properties": [ - { - "property-name": "AIC_CLOUD_REGION" - }, - { - "property-name": "CONSTANT", - "property-value": "onap-nf" - }, - { - "property-name": "TIMESTAMP" - }, - { - "property-value": "-", - "property-name": "DELIMITER" - } - ] - }, - { - "naming-type": "VNFC", - "naming-recipe": "VNF_NAME|DELIMITER|NFC_NAMING_CODE|DELIMITER|SEQUENCE", - "name-operation": "to_lower_case()", - "naming-properties": [ - { - "property-name": "VNF_NAME" - }, - { - "property-name": "SEQUENCE", - "increment-sequence": { - "max": "zzz", - "scope": "ENTIRETY", - "start-value": "1", - "length": "3", - "increment": "1", - "sequence-type": "alpha-numeric" - } - }, - { - "property-name": "NFC_NAMING_CODE" - }, - { - "property-value": "-", - "property-name": "DELIMITER" - } - ] - }, - { - "naming-type": "VF-MODULE", - "naming-recipe": "VNF_NAME|DELIMITER|VF_MODULE_LABEL|DELIMITER|VF_MODULE_TYPE|DELIMITER|SEQUENCE", - "name-operation": "to_lower_case()", - "naming-properties": [ - { - "property-name": "VNF_NAME" - }, - { - "property-value": "-", - "property-name": "DELIMITER" - }, - { - "property-name": "VF_MODULE_LABEL" - }, - { - "property-name": "VF_MODULE_TYPE" - }, - { - "property-name": "SEQUENCE", - "increment-sequence": { - "max": "zzz", - "scope": "PRECEEDING", - "start-value": "1", - "length": "3", - "increment": "1", - "sequence-type": "alpha-numeric" - } - } - ] - } - ], - "policy-instance-name": "ONAP_NF_NAMING_TIMESTAMP" - }, - "name": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", - "version": "1.0.0", - "metadata": { - "policy-id": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", - "policy-version": "1.0.0" - } - } - } - ] -} diff --git a/gui-clamp/ui-react/src/api/PolicyService.js b/gui-clamp/ui-react/src/api/PolicyService.js deleted file mode 100644 index cf4f0fd..0000000 --- a/gui-clamp/ui-react/src/api/PolicyService.js +++ /dev/null @@ -1,152 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP POLICY-CLAMP - * ================================================================================ - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -export default class PolicyService { - static getPoliciesList() { - return fetch(window.location.pathname + 'restservices/clds/v2/policies', { - method: 'GET', - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("getPoliciesList response received: ", response.status); - if (response.ok) { - console.info("getPoliciesList query successful"); - return response.json(); - } else { - return response.text().then(responseBody => { - throw new Error("HTTP " + response.status + "," + responseBody); - }) - } - }) - .catch(function (error) { - console.error("getPoliciesList error occurred ", error); - alert("getPoliciesList error occurred " + error); - return undefined; - }); - } - - static createNewPolicy(policyModelType, policyModelVersion, policyName, policyVersion, policyJson) { - return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/' - + policyModelVersion + '/' + policyName + '/' + policyVersion, { - method: 'POST', - credentials: 'same-origin', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(policyJson) - }) - .then(function (response) { - console.debug("createNewPolicy response received: ", response.status); - if (response.ok) { - console.info("createNewPolicy query successful"); - return response.text(); - } else { - return response.text().then(responseBody => { - throw new Error("HTTP " + response.status + "," + responseBody); - }) - } - }) - .catch(function (error) { - console.error("createNewPolicy error occurred ", error); - alert("createNewPolicy error occurred " + error); - return undefined; - }); - } - - static deletePolicy(policyModelType, policyModelVersion, policyName, policyVersion) { - return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/' - + policyModelVersion + '/' + policyName + '/' + policyVersion, { - method: 'DELETE', - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("deletePolicy response received: ", response.status); - if (response.ok) { - console.info("deletePolicy query successful"); - return response.text(); - } else { - return response.text().then(responseBody => { - throw new Error("HTTP " + response.status + "," + responseBody); - }) - } - }) - .catch(function (error) { - console.error("deletePolicy error occurred ", error); - alert("deletePolicy error occurred " + error); - return undefined; - }); - } - - static updatePdpDeployment(pdpOperationsList) { - return fetch(window.location.pathname + 'restservices/clds/v2/policies/pdpDeployment', { - method: 'PUT', - credentials: 'same-origin', - headers: { - "Content-Type": "application/json" - }, - body: JSON.stringify(pdpOperationsList) - }) - .then(function (response) { - console.debug("updatePdpDeployment response received: ", response.status); - if (response.ok) { - console.info("updatePdpDeployment query successful"); - return response.text(); - } else { - return response.text().then(responseBody => { - throw new Error("HTTP " + response.status + "," + responseBody); - }) - } - }) - .catch(function (error) { - console.error("updatePdpDeployment error occurred ", error); - alert("updatePdpDeployment error occurred " + error); - return undefined; - }); - } - - static sendNewPolicyModel(newPolicyModel) { - return fetch(window.location.pathname + 'restservices/clds/v2/policies/policytype', { - method: 'POST', - credentials: 'same-origin', - headers: { - "Content-Type": "plain/text" - }, - body: newPolicyModel - }) - .then(function (response) { - console.debug("sendNewPolicyModel response received: ", response.status); - if (response.ok) { - console.info("sendNewPolicyModel query successful"); - return response.text(); - } else { - return response.text().then(responseBody => { - throw new Error("HTTP " + response.status + "," + responseBody); - }) - } - }) - .catch(function (error) { - console.error("sendNewPolicyModel error occurred ", error); - alert("sendNewPolicyModel error occurred " + error); - return undefined; - }); - } -} diff --git a/gui-clamp/ui-react/src/api/PolicyService.test.js b/gui-clamp/ui-react/src/api/PolicyService.test.js deleted file mode 100644 index 3a491f9..0000000 --- a/gui-clamp/ui-react/src/api/PolicyService.test.js +++ /dev/null @@ -1,238 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -import PolicyService from "./PolicyService"; - -describe("Verify GetPoliciesList", () => { - let response; - let expectedResponse; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await PolicyService.getPoliciesList(); - }); - it("Test getPoliciesList returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Error Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Failed", - ok: false, - }) - ); - response = PolicyService.getPoliciesList(); - }); - it("Test getPoliciesList returns correct error", () => { - expect(response).rejects.toEqual( - new Error("HTTP Failed," + { name: "loop1" }) - ); - }); - }); -}); -describe("Verify CreateNewPolicy", () => { - let response; - let expectedResponse; - let modelType = "modelType"; - let modelVersion = "modelVersion"; - let policyName = "policyName"; - let policyVersion = "policyVersion"; - let json = {}; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await PolicyService.createNewPolicy( - modelType, - modelVersion, - policyName, - policyVersion, - json - ); - }); - it("Test createNewPolicy returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Error Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Failed", - ok: false, - }) - ); - response = PolicyService.createNewPolicy( - modelType, - modelVersion, - policyName, - policyVersion, - json - ); - }); - it("Test getPoliciesList returns correct error", () => { - expect(response).rejects.toEqual( - new Error("HTTP Failed," + { name: "loop1" }) - ); - }); - }); -}); -describe("Verify DeletePolicy", () => { - let response; - let expectedResponse; - let modelType = "modelType"; - let modelVersion = "modelVersion"; - let policyName = "policyName"; - let policyVersion = "policyVersion"; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await PolicyService.deletePolicy( - modelType, - modelVersion, - policyName, - policyVersion - ); - }); - it("Test deletePolicy returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Error Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Failed", - ok: false, - }) - ); - response = PolicyService.deletePolicy( - modelType, - modelVersion, - policyName, - policyVersion - ); - }); - it("Test deletePolicy returns correct error", () => { - expect(response).rejects.toEqual( - new Error("HTTP Failed," + { name: "loop1" }) - ); - }); - }); -}); -describe("Verify UpdatePdpDeployment", () => { - let response; - let expectedResponse; - let operationList = "operation"; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await PolicyService.updatePdpDeployment(operationList); - }); - it("Test updatePdpDeployment returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Error Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Failed", - ok: false, - }) - ); - response = PolicyService.updatePdpDeployment(operationList); - }); - it("Test updatePdpDeployment returns correct error", () => { - expect(response).rejects.toEqual( - new Error("HTTP Failed," + { name: "loop1" }) - ); - }); - }); -}); -describe("Verify SendNewPolicyModel", () => { - let response; - let expectedResponse; - let policyModel = "model"; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await PolicyService.sendNewPolicyModel(policyModel); - }); - it("Test sendNewPolicyModel returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Error Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "loop1" }), - status: "Failed", - ok: false, - }) - ); - response = PolicyService.sendNewPolicyModel(policyModel); - }); - it("Test sendNewPolicyModel returns correct error", () => { - expect(response).rejects.toEqual( - new Error("HTTP Failed," + { name: "loop1" }) - ); - }); - }); -}); diff --git a/gui-clamp/ui-react/src/api/PolicyToscaService.js b/gui-clamp/ui-react/src/api/PolicyToscaService.js deleted file mode 100644 index 6c74149..0000000 --- a/gui-clamp/ui-react/src/api/PolicyToscaService.js +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -export default class PolicyToscaService { - static getToscaPolicyModels() { - return fetch(window.location.pathname + 'restservices/clds/v2/policyToscaModels', { method: 'GET', credentials: 'same-origin' }) - .then(function (response) { - console.debug("getToscaPolicyModels response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("getToscaPolicyModels query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("getToscaPolicyModels error received", error); - return {}; - }); - } - - static getToscaPolicyModelYaml(policyModelType, policyModelVersion) { - return fetch(window.location.pathname + 'restservices/clds/v2/policyToscaModels/yaml/' + policyModelType + "/" + policyModelVersion, { - method: 'GET', - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("getToscaPolicyModelYaml response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("getToscaPolicyModelYaml query failed"); - return ""; - } - }) - .catch(function (error) { - console.error("getToscaPolicyModelYaml error received", error); - return ""; - }); - } - - static getToscaPolicyModel(policyModelType, policyModelVersion) { - return fetch(window.location.pathname + 'restservices/clds/v2/policyToscaModels/' + policyModelType + "/" + policyModelVersion, { - method: 'GET', - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("getToscaPolicyModel response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("getToscaPolicyModel query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("getToscaPolicyModel error received", error); - return {}; - }); - } -} diff --git a/gui-clamp/ui-react/src/api/PolicyToscaService.test.js b/gui-clamp/ui-react/src/api/PolicyToscaService.test.js deleted file mode 100644 index b6ed4bd..0000000 --- a/gui-clamp/ui-react/src/api/PolicyToscaService.test.js +++ /dev/null @@ -1,138 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -import PolicyToscaService from "./PolicyToscaService"; - -describe("Verify GetToscaPolicyModels", () => { - let response; - let expectedResponse; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await PolicyToscaService.getToscaPolicyModels(); - }); - it("Test getToscaPolicyModels returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Empty Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await PolicyToscaService.getToscaPolicyModels(); - }); - it("Test getToscaPolicyModels returns empty response", () => { - expect(response).toEqual({}); - }); - }); -}); -describe("Verify GetToscaPolicyModelYaml", () => { - let response; - let expectedResponse; - let modelType = "type"; - let version = "version"; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await PolicyToscaService.getToscaPolicyModelYaml( - modelType, - version - ); - }); - it("Test getToscaPolicyModelYaml returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Empty Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await PolicyToscaService.getToscaPolicyModelYaml( - modelType, - version - ); - }); - it("Test getToscaPolicyModelYaml returns empty response", () => { - expect(response).toEqual(""); - }); - }); -}); -describe("Verify GetToscaPolicyModel", () => { - let response; - let expectedResponse; - let modelType = "type"; - let version = "version"; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await PolicyToscaService.getToscaPolicyModel( - modelType, - version - ); - }); - it("Test getToscaPolicyModel returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Empty Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await PolicyToscaService.getToscaPolicyModel( - modelType, - version - ); - }); - it("Test getToscaPolicyModel returns empty response", () => { - expect(response).toEqual({}); - }); - }); -}); diff --git a/gui-clamp/ui-react/src/api/TemplateService.js b/gui-clamp/ui-react/src/api/TemplateService.js deleted file mode 100644 index a6e386e..0000000 --- a/gui-clamp/ui-react/src/api/TemplateService.js +++ /dev/null @@ -1,197 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -export default class TemplateService { - - static getLoopNames() { - return fetch(window.location.pathname + 'restservices/clds/v2/loop/getAllNames', { method: 'GET', credentials: 'same-origin' }) - .then(function (response) { - console.debug("getLoopNames response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("getLoopNames query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("getLoopNames error received", error); - return {}; - }); - } - - static getAllLoopTemplates() { - return fetch(window.location.pathname + 'restservices/clds/v2/templates', { method: 'GET', credentials: 'same-origin', }) - .then(function (response) { - console.debug("getAllLoopTemplates response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("getAllLoopTemplates query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("getAllLoopTemplates error received", error); - return {}; - }); - } - - static getDictionary() { - return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/', { method: 'GET', credentials: 'same-origin', }) - .then(function (response) { - console.debug("getDictionary response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("getDictionary query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("getDictionary error received", error); - return {}; - }); - } - - static getDictionaryElements(dictionaryName) { - return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/' + dictionaryName, { - method: 'GET', - headers: { - "Content-Type": "application/json", - }, - credentials: 'same-origin', - }) - .then(function (response) { - console.debug("getDictionaryElements response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("getDictionaryElements query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("getDictionaryElements error received", error); - return {}; - }); - } - - static insDictionary(jsonData) { - console.log("dictionaryName is", jsonData.name) - return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/', { - method: 'PUT', - credentials: 'same-origin', - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(jsonData) - }) - .then(function (response) { - console.debug("insDictionary response received: ", response.status); - if (response.ok) { - return response.status; - } else { - var errorMessage = response.status; - console.error("insDictionary query failed", response.status); - return errorMessage; - } - }) - .catch(function (error) { - console.error("insDictionary error received", error); - return ""; - }); - } - - static insDictionaryElements(jsonData) { - console.log("dictionaryName is", jsonData.name) - return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/' + jsonData.name, { - method: 'PUT', - credentials: 'same-origin', - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(jsonData) - }) - .then(function (response) { - console.debug("insDictionary response received: ", response.status); - if (response.ok) { - return response.status; - } else { - var errorMessage = response.status; - console.error("insDictionary query failed", response.status); - return errorMessage; - } - }) - .catch(function (error) { - console.error("insDictionary error received", error); - return ""; - }); - } - - static deleteDictionary(dictionaryName) { - console.log("inside templaemenu service", dictionaryName) - return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/' + dictionaryName, { - method: 'DELETE', - headers: { - "Content-Type": "application/json", - }, - credentials: 'same-origin', - }) - .then(function (response) { - console.debug("deleteDictionary response received: ", response.status); - if (response.ok) { - return response.status; - } else { - console.error("deleteDictionary query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("deleteDictionary error received", error); - return {}; - }); - } - - static deleteDictionaryElements(dictionaryData) { - return fetch(window.location.pathname + 'restservices/clds/v2/dictionary/' + dictionaryData.name + '/elements/' + dictionaryData.shortName, { - method: 'DELETE', - headers: { - "Content-Type": "application/json", - }, - credentials: 'same-origin', - }) - .then(function (response) { - console.debug("deleteDictionary response received: ", response.status); - if (response.ok) { - return response.status; - } else { - console.error("deleteDictionary query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("deleteDictionary error received", error); - return {}; - }); - } -} diff --git a/gui-clamp/ui-react/src/api/TemplateService.test.js b/gui-clamp/ui-react/src/api/TemplateService.test.js deleted file mode 100644 index 6899ef3..0000000 --- a/gui-clamp/ui-react/src/api/TemplateService.test.js +++ /dev/null @@ -1,289 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -import TemplateService from "./TemplateService"; - -describe("Verify GetLoopNames", () => { - let response; - let expectedResponse; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await TemplateService.getLoopNames(); - }); - it("Test getLoopNames returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Empty Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await TemplateService.getLoopNames(); - }); - it("Test getLoopNames returns empty response", () => { - expect(response).toEqual({}); - }); - }); -}); -describe("Verify GetAllLoopTemplates", () => { - let response; - let expectedResponse; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await TemplateService.getAllLoopTemplates(); - }); - it("Test getAllLoopTemplates returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Empty Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await TemplateService.getAllLoopTemplates(); - }); - it("Test getAllLoopTemplates returns empty response", () => { - expect(response).toEqual({}); - }); - }); -}); -describe("Verify GetDictionary", () => { - let response; - let expectedResponse; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await TemplateService.getDictionary(); - }); - it("Test getDictionary returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Empty Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await TemplateService.getDictionary(); - }); - it("Test getDictionary returns empty response", () => { - expect(response).toEqual({}); - }); - }); -}); -describe("Verify GetDictionaryElements", () => { - let response; - let expectedResponse; - let dictionaryName = "name"; - describe("Non-Empty Json Check", () => { - expectedResponse = { name: "loop1" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await TemplateService.getDictionaryElements(dictionaryName); - }); - it("Test getDictionaryElements returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Empty Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await TemplateService.getDictionaryElements(dictionaryName); - }); - it("Test getDictionaryElements returns empty response", () => { - expect(response).toEqual({}); - }); - }); -}); -describe("Verify InsDictionary", () => { - let response; - let expectedResponse; - let json = "{}"; - describe("Return Success Response Check", () => { - expectedResponse = "Success"; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "loop1" }), - status: "Success", - ok: true, - }) - ); - response = await TemplateService.insDictionary(json); - }); - it("Test insDictionary returns correct json", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Return Failed Response Check", () => { - beforeEach(async () => { - expectedResponse = "Failed"; - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await TemplateService.insDictionary(json); - }); - it("Test insDictionary returns empty response", () => { - expect(response).toEqual(expectedResponse); - }); - }); -}); -describe("Verify InsDictionaryElements", () => { - let response; - let json = "{}"; - describe("Return Success Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Success", - ok: true, - }) - ); - response = await TemplateService.insDictionaryElements(json); - }); - it("Test insDictionaryElements returns success response", () => { - expect(response).toEqual("Success"); - }); - }); - describe("Return Failed Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await TemplateService.insDictionaryElements(json); - }); - it("Test insDictionaryElements returns failed response", () => { - expect(response).toEqual("Failed"); - }); - }); -}); -describe("Verify DeleteDictionary", () => { - let response; - let dictionaryName = "name"; - describe("Return Success Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Success", - ok: true, - }) - ); - response = await TemplateService.deleteDictionary(dictionaryName); - }); - it("Test deleteDictionary returns success response", () => { - expect(response).toEqual("Success"); - }); - }); - describe("Return Failed Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await TemplateService.deleteDictionary(dictionaryName); - }); - it("Test deleteDictionary returns failed response", () => { - expect(response).toEqual({}); - }); - }); -}); -describe("Verify DeleteDictionaryElements", () => { - let response; - let dictionaryData = "name"; - describe("Return Success Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Success", - ok: true, - }) - ); - response = await TemplateService.deleteDictionaryElements(dictionaryData); - }); - it("Test deleteDictionaryElements returns success response", () => { - expect(response).toEqual("Success"); - }); - }); - describe("Return Failed Response Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await TemplateService.deleteDictionaryElements(dictionaryData); - }); - it("Test deleteDictionaryElements returns failed response", () => { - expect(response).toEqual({}); - }); - }); -}); diff --git a/gui-clamp/ui-react/src/api/UserService.js b/gui-clamp/ui-react/src/api/UserService.js deleted file mode 100644 index bcf46ea..0000000 --- a/gui-clamp/ui-react/src/api/UserService.js +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END============================================ - * =================================================================== - * - */ - -export default class UserService { - static notLoggedUserName = 'Anonymous'; - - static login() { - return fetch(window.location.pathname + 'restservices/clds/v1/user/getUser', { - method: 'GET', - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("getUser response received, status code:", response.status); - if (response.ok) { - return response.text(); - } else { - console.error("getUser response is nok"); - return UserService.notLoggedUserName; - } - }) - .then(function (data) { - console.info("User connected:", data) - return data; - }) - .catch(function (error) { - console.warn("getUser error received, user set to: ", UserService.notLoggedUserName); - console.error("getUser error:", error); - return UserService.notLoggedUserName; - }); - } - - static getUserInfo() { - return fetch(window.location.pathname + 'restservices/clds/v2/clampInformation', { - method: 'GET', - credentials: 'same-origin' - }) - .then(function (response) { - console.debug("getUserInfo response received, status code:", response.status); - if (response.ok) { - return response.json(); - } else { - return {} - } - }) - .then(function (data) { - console.info("User info received:", data) - return data; - }) - .catch(function (error) { - console.warn("getUserInfo error received, user set to: ", UserService.notLoggedUserName); - console.error("getUserInfo error:", error); - return {}; - }); - } -} diff --git a/gui-clamp/ui-react/src/api/UserService.test.js b/gui-clamp/ui-react/src/api/UserService.test.js deleted file mode 100644 index ede5446..0000000 --- a/gui-clamp/ui-react/src/api/UserService.test.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -import UserService from "./UserService"; - -describe("Verify Login", () => { - let response; - let expectedResponse; - describe("Login Username Check", () => { - expectedResponse = { name: "name" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - text: () => Promise.resolve({ name: "name" }), - status: "Success", - ok: true, - }) - ); - response = await UserService.login(); - }); - it("Test login returns correct username", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Anonymouse Login Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await UserService.login(); - }); - it("Test login returns Anonymous user", () => { - expect(response).toEqual("Anonymous"); - }); - }); -}); -describe("Verify GetUserInfo", () => { - let response; - let expectedResponse; - describe("Test Correct Username", () => { - expectedResponse = { name: "name" }; - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - json: () => Promise.resolve({ name: "name" }), - status: "Success", - ok: true, - }) - ); - response = await UserService.getUserInfo(); - }); - it("Test getUserInfo returns correct username", () => { - expect(response).toEqual(expectedResponse); - }); - }); - describe("Empty User Check", () => { - beforeEach(async () => { - global.fetch = jest.fn(() => - Promise.resolve({ - status: "Failed", - ok: false, - }) - ); - response = await UserService.getUserInfo(); - }); - it("Test getUserInfo returns empty response", () => { - expect(response).toEqual({}); - }); - }); -}); |