From 4549fd92024cdadf3277d7cc364f33109ca22b59 Mon Sep 17 00:00:00 2001 From: xg353y Date: Tue, 12 Mar 2019 13:07:46 +0100 Subject: [PATCH] Add UI tests Add test cases for propertyController.js Issue-ID: CLAMP-310 Change-Id: I7ae2cc425d9a7343791bae9ab7704e09389f270a Signed-off-by: xg353y --- .../designer/scripts/propertyController.js | 19 ++++----- .../clds/it/AuthorizationControllerItCase.java | 3 +- src/test/javascript/propertyController.test.js | 45 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 src/test/javascript/propertyController.test.js diff --git a/src/main/resources/META-INF/resources/designer/scripts/propertyController.js b/src/main/resources/META-INF/resources/designer/scripts/propertyController.js index d4795650..c3f1aaf1 100644 --- a/src/main/resources/META-INF/resources/designer/scripts/propertyController.js +++ b/src/main/resources/META-INF/resources/designer/scripts/propertyController.js @@ -20,9 +20,9 @@ * =================================================================== * */ - function saveMsProperties(type, form) { + +function saveMsProperties(type, form) { var newMsProperties = cl_props["microServicePolicies"]; - for (p in newMsProperties) { if (newMsProperties[p]["name"] == type) { newMsProperties[p]["properties"] = form; @@ -40,9 +40,9 @@ def.resolve(data); }).error(function(data) { def.reject("Save Model not successful"); - return def.promise; - }; + }); cl_props["microServicePolicies"] = newMsProperties; + return def.promise; } function saveGlobalProperties(form) { @@ -57,9 +57,9 @@ function saveGlobalProperties(form) { def.resolve(data); }).error(function(data) { def.reject("Save Model not successful"); - return def.promise; - }; + }); cl_props["globalPropertiesJson"] = form; + return def.promise; } function saveOpPolicyProperties(form) { @@ -77,10 +77,10 @@ function saveOpPolicyProperties(form) { def.resolve(data); }).error(function(data) { def.reject("Save Model not successful"); - return def.promise; - }; + }); - cl_props["operationalPolicies"] = newOpProperties; + cl_props["operationalPolicies"] = newOpProperties; + return def.promise; } function getOperationalPolicyProperty() { @@ -122,3 +122,4 @@ function getDeploymentID() { function getDeploymentStatusURL() { return cl_props["dcaeDeploymentStatusUrl"]; } +module.exports = { getOperationalPolicyProperty,getGlobalProperty,getMsProperty,getMsUI,getStatus,getDeploymentID,getDeploymentStatusURL }; \ No newline at end of file diff --git a/src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java b/src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java index 477c71a0..a15c556e 100644 --- a/src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java @@ -25,6 +25,7 @@ package org.onap.clamp.clds.it; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -85,7 +86,7 @@ public class AuthorizationControllerItCase { Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); PrincipalUtils.setSecurityContext(securityContext); - AuthorizationController auth = new AuthorizationController (); + AuthorizationController auth = new AuthorizationController(); assertTrue(auth.isUserPermittedNoException(new SecureServicePermission("permission-type-cl","dev","read"))); assertTrue(auth.isUserPermittedNoException(new SecureServicePermission("permission-type-cl-manage","dev","DEPLOY"))); assertTrue(auth.isUserPermittedNoException(new SecureServicePermission("permission-type-filter-vf","dev","12345-55555-55555-5555"))); diff --git a/src/test/javascript/propertyController.test.js b/src/test/javascript/propertyController.test.js new file mode 100644 index 00000000..6cb77914 --- /dev/null +++ b/src/test/javascript/propertyController.test.js @@ -0,0 +1,45 @@ + +describe('Property controller tests', function() { + var clModel = '{"name": "ClosedLoopTest","dcaeDeploymentId":"testId","dcaeDeploymentStatusUrl":"testUrl","lastComputedState":"DESIGN","svgRepresentation": "representation","globalPropertiesJson": [{"name":"deployParameters","value":{"location_id":"","service_id":"","policy_id":"AUTO_GENERATED_POLICY_ID_AT_SUBMIT"}}], "blueprint": "yaml","lastComputedState": "DESIGN","operationalPolicies": [ {"name": "OpPolicyTest", "configurationsJson": { "policy1": [{"name": "pname","value": "policy1"}]}}],"microServicePolicies": [{"name": "tca","properties": "", "shared": true,"policyTosca": "tosca","jsonRepresentation": {"schema":{"title":"DCAE TCA Config","type":"object","required":["name"],"properties":{"name":{"propertyOrder":101,"title":"Name","type":"string"}}}}}],"loopLogs": [{ } ] }'; + cl_props = JSON.parse(clModel); + var propertyController = require('scripts/propertyController.js'); + + test('getOperationalPolicyProperty', () => { + var policyProp = '{"policy1": [{"name": "pname","value": "policy1"}]}'; + expect(propertyController.getOperationalPolicyProperty()).toEqual(JSON.parse(policyProp)); + }); + + test('getGlobalProperty', () => { + var globalProp = '[{"name":"deployParameters","value":{"location_id":"","service_id":"","policy_id":"AUTO_GENERATED_POLICY_ID_AT_SUBMIT"}}]'; + expect(propertyController.getGlobalProperty()).toEqual(JSON.parse(globalProp)); + }); + + test('getMsPropertyTca', () => { + expect(propertyController.getMsProperty("tca")).toEqual(''); + }); + + test('getMsUITca', () => { + var msUI = '{"schema":{"title":"DCAE TCA Config","type":"object","required":["name"],"properties":{"name":{"propertyOrder":101,"title":"Name","type":"string"}}}}'; + expect(propertyController.getMsUI("tca")).toEqual(JSON.parse(msUI)); + }); + + test('getMsPropertyNotExist', () => { + expect(propertyController.getMsProperty("test")).toEqual(null); + }); + + test('getMsUINotExist', () => { + expect(propertyController.getMsUI("test")).toEqual(null); + }); + + test('getStatus', () => { + expect(propertyController.getStatus()).toEqual('DESIGN'); + }); + + test('getDeploymentID', () => { + expect(propertyController.getDeploymentID()).toEqual('testId'); + }); + + test('getDeploymentStatusURL', () => { + expect(propertyController.getDeploymentStatusURL()).toEqual('testUrl'); + }); +}); \ No newline at end of file -- 2.16.6