aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLathish <lathishbabu.ganesan@est.tech>2022-01-11 15:53:39 +0530
committerLathish <lathishbabu.ganesan@est.tech>2022-01-14 15:53:49 +0530
commitf4f497d3d99b864b34837a00b9c9fe4839fd2082 (patch)
treedf906a8f1f70faaf947c368efa12fc5b30d98039
parentacd025f30f0005731c9b2894cb954bd31401ab76 (diff)
Improved Test coverage for Service Component
Issue-ID: POLICY-3351 Change-Id: I7d710a3fbd91d3c62fe29c4748244b480e7798e6 Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
-rw-r--r--gui-clamp/ui-react/src/api/ControlLoopService.test.js50
-rw-r--r--gui-clamp/ui-react/src/api/LoopActionService.test.js58
-rw-r--r--gui-clamp/ui-react/src/api/LoopService.test.js443
-rw-r--r--gui-clamp/ui-react/src/api/PolicyService.test.js238
-rw-r--r--gui-clamp/ui-react/src/api/PolicyToscaService.test.js138
-rw-r--r--gui-clamp/ui-react/src/api/TemplateService.test.js289
-rw-r--r--gui-clamp/ui-react/src/api/UserService.test.js88
7 files changed, 1304 insertions, 0 deletions
diff --git a/gui-clamp/ui-react/src/api/ControlLoopService.test.js b/gui-clamp/ui-react/src/api/ControlLoopService.test.js
new file mode 100644
index 0000000..a460225
--- /dev/null
+++ b/gui-clamp/ui-react/src/api/ControlLoopService.test.js
@@ -0,0 +1,50 @@
+/*
+ * ============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 ControlLoopService from "./ControlLoopService";
+
+describe("Verify GetControlLoopInstantiation", () => {
+ let response;
+ let name = "name";
+ let template = "template";
+ global.fetch = jest.fn(() =>
+ Promise.resolve({
+ status: "Success",
+ ok: true,
+ })
+ );
+ response = ControlLoopService.getControlLoopInstantiation(name, template);
+ it("Test getControlLoopInstantiation", () => {
+ expect(response.status).toEqual(response.status);
+ });
+});
+describe("Verify DeleteInstantiation", () => {
+ let response;
+ let name = "name";
+ let version = "version";
+ global.fetch = jest.fn(() =>
+ Promise.resolve({
+ status: "Success",
+ ok: true,
+ })
+ );
+ response = ControlLoopService.deleteInstantiation(name, version);
+ it("Test deleteInstantiation", () => {
+ expect(response.status).toEqual(response.status);
+ });
+});
diff --git a/gui-clamp/ui-react/src/api/LoopActionService.test.js b/gui-clamp/ui-react/src/api/LoopActionService.test.js
new file mode 100644
index 0000000..4253c8c
--- /dev/null
+++ b/gui-clamp/ui-react/src/api/LoopActionService.test.js
@@ -0,0 +1,58 @@
+/*
+ * ============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/LoopService.test.js b/gui-clamp/ui-react/src/api/LoopService.test.js
new file mode 100644
index 0000000..bd68582
--- /dev/null
+++ b/gui-clamp/ui-react/src/api/LoopService.test.js
@@ -0,0 +1,443 @@
+/*
+ * ============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/PolicyService.test.js b/gui-clamp/ui-react/src/api/PolicyService.test.js
new file mode 100644
index 0000000..3a491f9
--- /dev/null
+++ b/gui-clamp/ui-react/src/api/PolicyService.test.js
@@ -0,0 +1,238 @@
+/*
+ * ============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.test.js b/gui-clamp/ui-react/src/api/PolicyToscaService.test.js
new file mode 100644
index 0000000..b6ed4bd
--- /dev/null
+++ b/gui-clamp/ui-react/src/api/PolicyToscaService.test.js
@@ -0,0 +1,138 @@
+/*
+ * ============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.test.js b/gui-clamp/ui-react/src/api/TemplateService.test.js
new file mode 100644
index 0000000..6899ef3
--- /dev/null
+++ b/gui-clamp/ui-react/src/api/TemplateService.test.js
@@ -0,0 +1,289 @@
+/*
+ * ============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.test.js b/gui-clamp/ui-react/src/api/UserService.test.js
new file mode 100644
index 0000000..ede5446
--- /dev/null
+++ b/gui-clamp/ui-react/src/api/UserService.test.js
@@ -0,0 +1,88 @@
+/*
+ * ============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({});
+ });
+ });
+});