Merge "Clean up apex editor POM dependencies"
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js b/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js
index de29947..27eed22 100644
--- a/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js
@@ -72,6 +72,7 @@
}
createPdpGroupOperations(initialStates, newStates) {
+ console.log('createPdpGroupOperations called');
let commandsArray = [];
initialStates.forEach(initElem => {
let newStateFound = newStates.find(newElement => newElement.name === initElem.name);
@@ -89,6 +90,7 @@
}
handleUpdatePdpDeployment() {
+ console.log('handleUpdatePdpDeployment called');
let operationsList = this.createPdpGroupOperations(this.state.checkboxesInitialState,
this.state.checkboxesState);
if (typeof (operationsList) !== "undefined") {
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.test.js b/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.test.js
new file mode 100644
index 0000000..1ae73a2
--- /dev/null
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.test.js
@@ -0,0 +1,93 @@
+/*
+ * ============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 {shallow} from "enzyme";
+import toJson from "enzyme-to-json";
+import React from "react";
+import PolicyDeploymentEditor from "./PolicyDeploymentEditor";
+import fs from "fs";
+import LoopService from "../../../api/LoopService";
+
+describe('Verify PolicyDeploymentEditor', () => {
+ const toscaPolicyDeploymentEditor = fs.readFileSync('src/components/dialogs/Policy/toscaPolicyDeploymentEditor.test.json', {
+ encoding: 'utf8',
+ flag: 'r'
+ });
+
+ const toscaPolicyDeploymentEditorArray = JSON.parse(toscaPolicyDeploymentEditor);
+
+ const initialStateTrue = [
+ {
+ "name": "monitoring/xacml",
+ "value": true
+ }
+ ];
+
+ const initialStateFalse = [
+ {
+ "name": "monitoring/xacml",
+ "value": false
+ }
+ ];
+
+ const logSpy = jest.spyOn(console, 'log');
+
+ it("renders correctly", () => {
+ const component = shallow(<PolicyDeploymentEditor policyData={toscaPolicyDeploymentEditorArray}/>);
+ expect(toJson(component)).toMatchSnapshot();
+ });
+
+ it('Test createPdpGroupOperations', () => {
+ const component = shallow(<PolicyDeploymentEditor policyData={toscaPolicyDeploymentEditorArray} />);
+
+ const instance = component.instance();
+
+ instance.createPdpGroupOperations(initialStateTrue, initialStateTrue);
+
+ component.update();
+
+ expect(logSpy).toHaveBeenCalledWith('createPdpGroupOperations called');
+ });
+
+ it('Test handleUpdatePdpDeployment', () => {
+ LoopService.updatePdpDeployment = jest.fn().mockImplementation(() => {
+ return Promise.resolve(undefined);
+ });
+
+ const component = shallow(<PolicyDeploymentEditor policyData={toscaPolicyDeploymentEditorArray} />);
+ component.setState({checkboxesInitialState: initialStateTrue});
+ component.setState({checkboxesState: initialStateFalse});
+
+ const instance = component.instance();
+ instance.handleUpdatePdpDeployment();
+
+ expect(component.state('showFailAlert')).toEqual(false);
+ expect(component.state('showMessage')).toEqual(undefined);
+
+ component.update();
+
+ component.setState({showFailAlert: true});
+ component.setState({showMessage: 'Pdp Deployment update Failure'});
+
+ expect(logSpy).toHaveBeenCalledWith('handleUpdatePdpDeployment called');
+ expect(component.state('showFailAlert')).toEqual(true);
+ expect(component.state('showMessage')).toEqual('Pdp Deployment update Failure');
+ });
+
+});
\ No newline at end of file
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js b/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
index 0aed5f4..8f8bd51 100644
--- a/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
@@ -203,6 +203,8 @@
}
generateAdditionalPolicyColumns(policiesData) {
+ console.log('generateAdditionalPolicyColumns called');
+
policiesData.forEach(policy => {
let supportedPdpGroupsString = "";
if (typeof policy.supportedPdpGroups !== "undefined") {
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.test.js b/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.test.js
index d4a3fd9..c2ce731 100644
--- a/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.test.js
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.test.js
@@ -23,7 +23,6 @@
import fs from "fs";
import PolicyToscaService from "../../../api/PolicyToscaService";
import PolicyService from "../../../api/PolicyService";
-import CreateLoopModal from "../Loop/CreateLoopModal";
import toJson from "enzyme-to-json";
describe('Verify ViewAllPolicies', () => {
@@ -36,6 +35,12 @@
flag: 'r'
});
+ const toscaPolicyModelsArray = JSON.parse(toscaPolicyModels);
+
+ const toscaPoliciesListArray = JSON.parse(toscaPoliciesList);
+
+ const logSpy = jest.spyOn(console, 'log');
+
it("renders correctly", () => {
const component = shallow(<ViewAllPolicies />);
expect(toJson(component)).toMatchSnapshot();
@@ -127,15 +132,33 @@
});
const event = { target: {value: 'event'}}
- const component = shallow(<CreateLoopModal/>);
+ const renderPoliciesTab = jest.spyOn(ViewAllPolicies.prototype, 'renderPoliciesTab');
+
+ const component = shallow(<ViewAllPolicies />);
component.setState({showSuccessAlert: true});
component.setState({showMessage: 'Policy successfully Deleted'});
+ component.setState({policiesListDataFiltered: toscaPolicyModelsArray});
- component.find('input').simulate('click', event, rowData);
component.update();
+ const instance = component.instance();
+
+ instance.handleDeletePolicy(event, rowData);
+
+ expect(renderPoliciesTab).toHaveBeenCalledTimes(4);
expect(component.state('showSuccessAlert')).toEqual(true);
expect(component.state('showMessage')).toEqual('Policy successfully Deleted');
});
+
+ it('Test generateAdditionalPolicyColumns policiesData', async () => {
+ const component = shallow(<ViewAllPolicies />);
+
+ const instance = component.instance();
+ instance.generateAdditionalPolicyColumns(toscaPoliciesListArray.policies);
+
+ component.update();
+
+ expect(logSpy).toHaveBeenCalledWith('generateAdditionalPolicyColumns called');
+ });
});
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/__snapshots__/PolicyDeploymentEditor.test.js.snap b/gui-clamp/ui-react/src/components/dialogs/Policy/__snapshots__/PolicyDeploymentEditor.test.js.snap
new file mode 100644
index 0000000..7bf297a
--- /dev/null
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/__snapshots__/PolicyDeploymentEditor.test.js.snap
@@ -0,0 +1,71 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Verify PolicyDeploymentEditor renders correctly 1`] = `
+<styled.div>
+ <Alert
+ closeLabel="Close alert"
+ dismissible={true}
+ onClose={[Function]}
+ show={false}
+ transition={
+ Object {
+ "$$typeof": Symbol(react.forward_ref),
+ "defaultProps": Object {
+ "appear": false,
+ "in": false,
+ "mountOnEnter": false,
+ "timeout": 300,
+ "unmountOnExit": false,
+ },
+ "render": [Function],
+ }
+ }
+ variant="success"
+ >
+ <styled.div />
+ </Alert>
+ <Alert
+ closeLabel="Close alert"
+ dismissible={true}
+ onClose={[Function]}
+ show={false}
+ transition={
+ Object {
+ "$$typeof": Symbol(react.forward_ref),
+ "defaultProps": Object {
+ "appear": false,
+ "in": false,
+ "mountOnEnter": false,
+ "timeout": 300,
+ "unmountOnExit": false,
+ },
+ "render": [Function],
+ }
+ }
+ variant="danger"
+ >
+ <styled.div />
+ </Alert>
+ <Button
+ active={false}
+ disabled={false}
+ onClick={[Function]}
+ title="Update the policy to the specified PDP Groups/Subgroups"
+ variant="secondary"
+ >
+ Update PDP
+ </Button>
+ <WithStyles(ForwardRef(FormGroup))>
+ <WithStyles(ForwardRef(FormControlLabel))
+ control={
+ <WithStyles(ForwardRef(Checkbox))
+ checked={true}
+ name="monitoring/xacml"
+ onChange={[Function]}
+ />
+ }
+ label="monitoring/xacml"
+ />
+ </WithStyles(ForwardRef(FormGroup))>
+</styled.div>
+`;
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPolicyDeploymentEditor.test.json b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPolicyDeploymentEditor.test.json
new file mode 100644
index 0000000..f6907e5
--- /dev/null
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPolicyDeploymentEditor.test.json
@@ -0,0 +1,90 @@
+{
+ "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": [
+ {
+ "monitoring": {
+ "name": "monitoring",
+ "description": "This group should be used for managing all monitoring related policies and pdps",
+ "pdpGroupState": "ACTIVE",
+ "properties": {},
+ "pdpSubgroups": [
+ {
+ "pdpType": "xacml",
+ "supportedPolicyTypes": [
+ {
+ "name": "onap.policies.monitoring.*",
+ "version": "1.0.0"
+ },
+ {
+ "name": "onap.policies.Naming",
+ "version": "1.0.0"
+ }
+ ],
+ "policies": [
+ {
+ "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "version": "1.0.0"
+ }
+ ],
+ "currentInstanceCount": 0,
+ "desiredInstanceCount": 1,
+ "properties": {},
+ "pdpInstances": [
+ {
+ "instanceId": "monitoring-f8287777-5f3e-4f0f-b21b-d8829c93f57b",
+ "pdpState": "ACTIVE",
+ "healthy": "HEALTHY",
+ "message": "Pdp Heartbeat",
+ "lastUpdate": "2021-09-29T02:51:21Z"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ],
+ "supportedPdpGroups": [
+ {
+ "monitoring": [
+ "xacml"
+ ]
+ }
+ ],
+ "supportedPdpGroupsString": "monitoring/xacml\r\n",
+ "pdpGroupInfoString": "monitoring/xacml (ACTIVE)\r\n",
+ "tableData": {
+ "id": 0
+ }
+}
\ No newline at end of file