From 36e91d5f969f22424509c112e154bdcdffa99521 Mon Sep 17 00:00:00 2001 From: "Mohamed Asgar Samiulla(ma926a)" Date: Tue, 20 Mar 2018 21:31:56 +0530 Subject: Removing INSTAR functionality from CDT for ONAP. Removed license form package.json. Issue-ID: APPC-750 Change-Id: If20087a24fc0cf42977e1b1149d6be0ff1387689 Signed-off-by: Mohamed Asgar Samiulla(ma926a) --- package.json | 1 - src/app/CDTProperties.json | 1 - .../parameter-definition.service.ts | 40 +------- .../parameter-definitions/parameter.component.html | 2 +- .../parameter-definitions/parameter.component.ts | 7 +- .../param-name-value.component.spec.ts | 48 ++++++++-- .../template-configuration.component.spec.ts | 106 +++++++++++++++++---- 7 files changed, 135 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index 5602ed2..244e1de 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "appc_self_service_tool", "version": "1.0.1", - "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve --port 8080", diff --git a/src/app/CDTProperties.json b/src/app/CDTProperties.json index b395923..2c63c08 100644 --- a/src/app/CDTProperties.json +++ b/src/app/CDTProperties.json @@ -1,3 +1,2 @@ { - "source": "INSTAR" } diff --git a/src/app/vnfs/build-artifacts/parameter-definitions/parameter-definition.service.ts b/src/app/vnfs/build-artifacts/parameter-definitions/parameter-definition.service.ts index cfcab03..2c13e4f 100644 --- a/src/app/vnfs/build-artifacts/parameter-definitions/parameter-definition.service.ts +++ b/src/app/vnfs/build-artifacts/parameter-definitions/parameter-definition.service.ts @@ -63,7 +63,6 @@ export class ParameterDefinitionService { private selectedActionReference: any; private apiToken = localStorage['apiToken']; private userId = localStorage['userId']; - public configurable_source = require('../../../CDTProperties.json').source; constructor(private mappingEditorService: MappingEditorService, private paramShareService: ParamShareService, private nService: NotificationsService, @@ -307,21 +306,7 @@ export class ParameterDefinitionService { return result; } - //========================== End of clearSessionStorageForParam() Method============================================ - isValidateSourceAndResponseKeys(objs: any[]) { - let isValid = true; - if (undefined != objs || null != objs) { - for (var i = 0; i < objs.length; i++) { - if (objs[i].source == this.configurable_source && (null == objs[i]['response-keys'] || undefined == objs[i]['response-keys'])) { - isValid = false; - return isValid; - } - } - } - return isValid; - } - - + public prepareFileName(): any { let fileNameObject: any = this.mappingEditorService.latestAction; this.appDataObject = this.mappingEditorService.appDataObject; @@ -354,7 +339,6 @@ export class ParameterDefinitionService { jsonString = jsonString.replace(/"null"/g, 'null'); let saveModel = JSON.parse(jsonString); let pdFileObject = this.processResponseKeys(saveModel); - if (this.isValidateSourceAndResponseKeys(pdFileObject)) { let yamlObject = { 'kind': 'Property Definition', 'version': 'V1', @@ -379,14 +363,7 @@ export class ParameterDefinitionService { else { this.sendPD(JSON.stringify(yamlString)); } - } - else { - for (var i = 0; i < this.modelParamDefinitionObjects.length; i++) { - this.formatKeys(this.modelParamDefinitionObjects[i]); - } - this.nService.error('Error', 'Response Keys cannot be empty if source is '+this.configurable_source); - return; - } + //Restore Keys for display for (var i = 0; i < this.modelParamDefinitionObjects.length; i++) { this.formatKeys(this.modelParamDefinitionObjects[i]); @@ -434,18 +411,7 @@ export class ParameterDefinitionService { } parameterDefinitionObject['source'] = fields[0]; parameterDefinitionObject['rule-type'] = fields[1]; - } else { - if (parameterDefinitionObject['source'] === this.configurable_source) { - parameterDefinitionObject['source'] = 'Manual'; - parameterDefinitionObject['ruleTypeValues'] = [null]; - parameterDefinitionObject['rule-type'] = null; - parameterDefinitionObject['showFilterFields'] = false; - for (let x = 0; x < 5; x++) { - parameterDefinitionObject['response-keys'][x]['key-name'] = null; - parameterDefinitionObject['response-keys'][x]['key-value'] = null; - } - } - } + } this.formatKeys(parameterDefinitionObject); //Ensure there are 3 elements for response-keys, request-keys for display purposes if (!result.present) { //only push if not present this.modelParamDefinitionObjects.push(parameterDefinitionObject); diff --git a/src/app/vnfs/build-artifacts/parameter-definitions/parameter.component.html b/src/app/vnfs/build-artifacts/parameter-definitions/parameter.component.html index 1130c94..74c503a 100644 --- a/src/app/vnfs/build-artifacts/parameter-definitions/parameter.component.html +++ b/src/app/vnfs/build-artifacts/parameter-definitions/parameter.component.html @@ -135,7 +135,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. diff --git a/src/app/vnfs/build-artifacts/parameter-definitions/parameter.component.ts b/src/app/vnfs/build-artifacts/parameter-definitions/parameter.component.ts index ea22634..effd854 100644 --- a/src/app/vnfs/build-artifacts/parameter-definitions/parameter.component.ts +++ b/src/app/vnfs/build-artifacts/parameter-definitions/parameter.component.ts @@ -122,9 +122,8 @@ export class ParameterComponent implements OnInit { } ] }; - public configurable_source = require('../../../CDTProperties.json').source; public requiredValues: boolean[] = [null, true, false]; - public sourceValues = ['Manual', this.configurable_source, 'A&AI']; + public sourceValues = ['Manual', 'A&AI']; public ruleTypeValues = [null, 'vnf-name', 'vm-name-list', 'vnfc-name-list', 'vnf-oam-ipv4-address', 'vnfc-oam-ipv4-address-list']; public typeValues = [null, 'ipv4-address', 'ipv6-address', 'ipv4-prefix', 'ipv6-prefix']; public responseKeyNameValues = ['', 'unique-key-name', 'unique-key-value', 'field-key-name']; @@ -326,10 +325,6 @@ export class ParameterComponent implements OnInit { // Create the file reader let reader = new FileReader(); this.readFile(input.files[0], reader, (result) => { - if ('keyfile' === uploadType) { - this.myKeyFileName = input.files[0].name; - this.displayParamObjects = this.parameterDefinitionService.processKeyFile(this.myKeyFileName, result); - } if ('pdfile' === uploadType) { this.myPdFileName = input.files[0].name; this.displayParamObjects = this.parameterDefinitionService.processPDfile(this.myPdFileName, result); diff --git a/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.spec.ts b/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.spec.ts index 991ff45..c9a7c4d 100644 --- a/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.spec.ts +++ b/src/app/vnfs/build-artifacts/template-holder/param-name-value/param-name-value.component.spec.ts @@ -21,6 +21,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ */ +/* tslint:disable:no-unused-variable */ import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; import { By, BrowserModule } from '@angular/platform-browser'; import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; @@ -141,9 +142,9 @@ describe('GoldenConfigurationMappingComponent', () => { expect(component.ngAfterViewInit()); component.paramsContent = JSON.stringify({ - "sync_auto-pop_name1": "testIp1", + "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", - "node0_tacplus_server_name2": "testIp2" + "node0_tacplus_server_name2": "192.34.45.5" }); expect(component.ngOnInit()); @@ -180,9 +181,9 @@ describe('GoldenConfigurationMappingComponent', () => { fixture = TestBed.createComponent(GoldenConfigurationMappingComponent); component = fixture.componentInstance; var data = JSON.stringify({ - "sync_auto-pop_name1": "testIp1", + "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", - "node0_tacplus_server_name2": "testIp2" + "node0_tacplus_server_name2": "192.34.45.5" }); component.onParamChanges(data); expect(localStorage["paramsContent"]).toBe(data); @@ -195,7 +196,7 @@ describe('GoldenConfigurationMappingComponent', () => { var mockData = { "output": { "data": { - "block": "{\"userID\":null,\"designInfo\":null,\"statusInfo\":null,\"artifactInfo\":[{\"artifact-content\":\"[{\\\"node0_tacplus_server_name1\\\":\\\"testIp1\\\",\\\"node0_tacplus_server_source_address1\\\":\\\"testIp2\\\",\\\"node0_tacplus_server_name2\\\":\\\"testIp3\\\"}]\"}]}", + "block": "{\"userID\":null,\"designInfo\":null,\"statusInfo\":null,\"artifactInfo\":[{\"artifact-content\":\"[{\\\"node0_tacplus_server_name1\\\":\\\"199.37.184.211\\\",\\\"node0_tacplus_server_source_address1\\\":\\\"135.144.3.125\\\",\\\"node0_tacplus_server_name2\\\":\\\"199.37.184.242\\\"}]\"}]}", "requestId": "497085412083" }, "status": { @@ -231,12 +232,47 @@ describe('GoldenConfigurationMappingComponent', () => { fixture = TestBed.createComponent(GoldenConfigurationMappingComponent); component = fixture.componentInstance; localStorage['paramsContent'] = JSON.stringify({ - "node0_tacplus_server_name1": "testIp1", "node0_tacplus_server_source_address1": "testIp2", "node0_tacplus_server_name2": "testIp3" + "node0_tacplus_server_name1": "199.37.184.211", "node0_tacplus_server_source_address1": "135.144.3.125", "node0_tacplus_server_name2": "199.37.184.242" }); var pdData = [{ "name": "sync_auto-pop_name1", "type": null, "description": null, "required": null, "default": null, "source": "A&AI", "rule-type": "vnfc-oam-ipv4-address-list", "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": "unique-key-name", "key-value": "parent-name" }, { "key-name": "unique-key-value", "key-value": "vnfc" }, { "key-name": "field-key-name", "key-value": "ipaddress-v4-oam-vip" }, { "key-name": null, "key-value": "vm-number" }, { "key-name": null, "key-value": "test" }], "ruleTypeValues": [null, "vnf-name", "vm-name-list", "vnfc-name-list", "vnf-oam-ipv4-address", "vnfc-oam-ipv4-address-list"], "showFilterFields": true, "enableFilterByValue": true }, { "name": "sync_auto-pop_address1", "type": null, "description": null, "required": null, "default": null, "source": "A&AI", "rule-type": "vm-name-list", "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": "unique-key-name", "key-value": "parent-name" }, { "key-name": "unique-key-value", "key-value": "vserver" }, { "key-name": "field-key-name", "key-value": "vserver-name" }, { "key-name": null, "key-value": "vnfc-function-code" }, { "key-name": null, "key-value": null }], "ruleTypeValues": [null, "vnf-name", "vm-name-list", "vnfc-name-list", "vnf-oam-ipv4-address", "vnfc-oam-ipv4-address-list"], "showFilterFields": true, "enableFilterByValue": true }, { "name": "node0_tacplus_server_name2", "type": null, "description": null, "required": null, "default": null, "source": "Manual", "rule-type": null, "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "ruleTypeValues": [null] }]; paramShareService.setSessionParamData([pdData]); component.syncParam(); })); + // fileChange method + it('Should validatte fileChange method if file type is json', async(() => { + let reader = new FileReader(); + let obj = {"e": " "}; + let data = JSON.stringify(obj); + let file = new File([data], "foo.json", {type: "text/json"}); + let input = {files: [file]}; + + component.fileParamChange(input); + + component.readFile(input.files[0], reader,(res) => { + let jsonObject = JSON.parse(res); + expect(component.selectedUploadType).toEqual('Mapping Data'); + expect(component.artifactRequest.paramsContent).toEqual(JSON.stringify(jsonObject, null, 1)); + }); + })); + + + it('Should validatte fileChange method if file type is not json', () => { + let spy = spyOn(NotificationsService.prototype, 'error'); + let file = new File(["testing"], "foo.txt", {type: "text/txt"}); + let input = {files: [file]}; + component.fileParamChange(input); + + expect(spy).toHaveBeenCalled(); + }); + + it('Should validatte fileChange method if file is false', () => { + let spy = spyOn(NotificationsService.prototype, 'error'); + let input = {files: []}; + + component.fileParamChange(input); + + expect(spy).toHaveBeenCalled(); + }); }); \ No newline at end of file diff --git a/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.spec.ts b/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.spec.ts index d2412a0..da422c3 100644 --- a/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.spec.ts +++ b/src/app/vnfs/build-artifacts/template-holder/template-configuration/template-configuration.component.spec.ts @@ -21,7 +21,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ */ - +/* tslint:disable:no-unused-variable */ import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing'; import { By, BrowserModule } from '@angular/platform-browser'; import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; @@ -153,7 +153,6 @@ describe('GoldenConfigurationComponent', () => { it('check if variables are empty when reference data object is empty', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { fixture = TestBed.createComponent(GoldenConfigurationComponent); component = fixture.componentInstance; - // mappingEditorService.latestAction = { "action": "", "scope": { "vnf-type": "", "vnfc-type": "" }, "vm": [], "protocol": "", "download-dg-reference": "", "user-name": "", "port-number": "", "artifact-list": [], "deviceTemplate": "", "scopeType": "" }; mappingEditorService.latestAction = undefined; expect(component.ngAfterViewInit()); expect(component.action).toEqual(''); @@ -182,9 +181,9 @@ describe('GoldenConfigurationComponent', () => { var pdData = [{ "name": "sync_auto-pop_name1", "type": null, "description": null, "required": null, "default": null, "source": "A&AI", "rule-type": "vnfc-oam-ipv4-address-list", "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": "unique-key-name", "key-value": "parent-name" }, { "key-name": "unique-key-value", "key-value": "vnfc" }, { "key-name": "field-key-name", "key-value": "ipaddress-v4-oam-vip" }, { "key-name": null, "key-value": "vm-number" }, { "key-name": null, "key-value": "test" }], "ruleTypeValues": [null, "vnf-name", "vm-name-list", "vnfc-name-list", "vnf-oam-ipv4-address", "vnfc-oam-ipv4-address-list"], "showFilterFields": true, "enableFilterByValue": true }, { "name": "sync_auto-pop_address1", "type": null, "description": null, "required": null, "default": null, "source": "A&AI", "rule-type": "vm-name-list", "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": "unique-key-name", "key-value": "parent-name" }, { "key-name": "unique-key-value", "key-value": "vserver" }, { "key-name": "field-key-name", "key-value": "vserver-name" }, { "key-name": null, "key-value": "vnfc-function-code" }, { "key-name": null, "key-value": null }], "ruleTypeValues": [null, "vnf-name", "vm-name-list", "vnfc-name-list", "vnf-oam-ipv4-address", "vnfc-oam-ipv4-address-list"], "showFilterFields": true, "enableFilterByValue": true }, { "name": "node0_tacplus_server_name2", "type": null, "description": null, "required": null, "default": null, "source": "Manual", "rule-type": null, "request-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "response-keys": [{ "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }, { "key-name": null, "key-value": null }], "ruleTypeValues": [null] }]; paramShareService.setSessionParamData([pdData]); localStorage["paramsContent"] = { - "sync_auto-pop_name1": "testIp1", + "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", - "node0_tacplus_server_name2": "testIp2" + "node0_tacplus_server_name2": "192.34.45.5" }; expect(component.syncTemplate()); @@ -215,13 +214,13 @@ describe('GoldenConfigurationComponent', () => { component.appDataObject = { reference: {}, template: { templateData: {}, nameValueData: {} }, pd: {} }; component.configMappingEditorContent = "\n 15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n " mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); - localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "testIp1", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "testIp2" }); + localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" }); - component.userId = "testuser"; + component.userId = "sj108s"; component.apiToken = "87264736473"; component.prepareAppData(); - var paramData = { "input": ({ "design-request": ({ "request-id": '87264736473', "action": 'uploadArtifact', "payload": '{"userID":"testuser","vnf-type":"testVnf","action":"Configure","artifact-name":"param_Configure_testVnf_0.0.1V.json","artifact-type":"APPC-CONFIG","artifact-version":"0.0.1","artifact-contents":"[{\"sync_auto-pop_name1\":\"10.0.1.34\",\"sync_auto-pop_address1\":\"\",\"node0_tacplus_server_name2\":\"192.34.45.5\"}]"}' }) }) }; - var templateData = { input: ({ "design-request": ({ "request-id": '87264736473', "action": 'uploadArtifact', "payload": '{"userID":"testuser","vnf-type":"testVnf","action":"Configure","artifact-name":"template_Configure_test_0.0.1V.json","artifact-type":"APPC-CONFIG","artifact-version":"0.0.1","artifact-contents":"\n15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "}' }) }) }; + var paramData = { "input": ({ "design-request": ({ "request-id": '87264736473', "action": 'uploadArtifact', "payload": '{"userID":"sj108s","vnf-type":"testVnf","action":"Configure","artifact-name":"param_Configure_testVnf_0.0.1V.json","artifact-type":"APPC-CONFIG","artifact-version":"0.0.1","artifact-contents":"[{\"sync_auto-pop_name1\":\"10.0.1.34\",\"sync_auto-pop_address1\":\"\",\"node0_tacplus_server_name2\":\"192.34.45.5\"}]"}' }) }) }; + var templateData = { input: ({ "design-request": ({ "request-id": '87264736473', "action": 'uploadArtifact', "payload": '{"userID":"sj108s","vnf-type":"testVnf","action":"Configure","artifact-name":"template_Configure_test_0.0.1V.json","artifact-type":"APPC-CONFIG","artifact-version":"0.0.1","artifact-contents":"\n15.1X49-D50.3\n \n node0\n \n \n ${sync_auto-pop_name1}\n ${sync_auto-pop_address1}\n \n \n ${node0_tacplus_server_name2}\n ${sync_auto-pop_address1}\n \n \n \n "}' }) }) }; expect(component.appDataObject.template.nameValueData["payload"]).toBe(JSON.stringify(paramData["payload"])); expect(component.appDataObject.template.templateData["payload"]).toBe(JSON.stringify(templateData["payload"])); })); @@ -238,13 +237,13 @@ describe('GoldenConfigurationComponent', () => { template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' }, pd: { pdData: '', pdFileName: '' } }; - localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "testIp1", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "testIp2" }); + localStorage["paramsContent"] = JSON.stringify({ "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", "node0_tacplus_server_name2": "192.34.45.5" }); component.onDownloadParameter(); var nameValueData = { - "sync_auto-pop_name1": "testIp1", + "sync_auto-pop_name1": "10.0.1.34", "sync_auto-pop_address1": "", - "node0_tacplus_server_name2": "testIp2" + "node0_tacplus_server_name2": "192.34.45.5" }; expect(component.downloadDataObject.template.nameValueData).toBe(JSON.stringify(nameValueData, null, "\t")); expect(component.downloadDataObject.template.nameValueFileName).toBe("param_Configure_testVnf_0.0.1V.json"); @@ -273,7 +272,7 @@ describe('GoldenConfigurationComponent', () => { component.fileNameForTempSave = "Configure_testVnf_0.0.1V.json" component.onDownloadTemplate('Template'); expect(component.downloadDataObject.template.templateData).toBe(component.configMappingEditorContent.replace(/\(([^()]|(R))*\)=\(/g, '').replace(/\)}/g, '}')); - })); + })); it('test merge status for golden config template and uploaded parameter data', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { @@ -287,12 +286,12 @@ describe('GoldenConfigurationComponent', () => { template: { templateData: {}, nameValueData: {}, templateFileName: '', nameValueFileName: '' }, pd: { pdData: '', pdFileName: '' } }; - component.configMappingEditorContent = "\r\n 15.1X49-D50.3\r\n \r\n node0\r\n \r\n \r\n testIp1\r\n 135.144.3.125\r\n \r\n \r\n 199.37.184.242\r\n testIp2\r\n \r\n \r\n \r\n "; + component.configMappingEditorContent = "\r\n 15.1X49-D50.3\r\n \r\n node0\r\n \r\n \r\n 199.37.184.211\r\n 135.144.3.125\r\n \r\n \r\n 199.37.184.242\r\n 135.144.3.125\r\n \r\n \r\n \r\n "; mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); localStorage["paramsContent"] = JSON.stringify({ - "node0_tacplus_server_name1": "testIp1", - "node0_tacplus_server_source_address1": "675453432", - "node0_tacplus_server_name2": "testIp2" + "node0_tacplus_server_name1": "199.37.184.211", + "node0_tacplus_server_source_address1": "135.144.3.125", + "node0_tacplus_server_name2": "199.37.184.242" }); component.mergeParams(); expect(component.mergeStatus).toBe(true); @@ -311,7 +310,7 @@ describe('GoldenConfigurationComponent', () => { component.ngOnInit(); component.ngAfterViewInit(); - component.configMappingEditorContent = "\r\n 15.1X49-D50.3\r\n \r\n node0\r\n \r\n \r\n 199.37.184.211\r\n 675453432\r\n \r\n \r\n 199.37.184.242\r\n 675453432\r\n \r\n \r\n \r\n "; + component.configMappingEditorContent = "\r\n 15.1X49-D50.3\r\n \r\n node0\r\n \r\n \r\n 199.37.184.211\r\n 135.144.3.125\r\n \r\n \r\n 199.37.184.242\r\n 135.144.3.125\r\n \r\n \r\n \r\n "; mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); component.selectedWord = "node0"; expect(component.handleAnnotation(component.modal)); @@ -324,7 +323,7 @@ describe('GoldenConfigurationComponent', () => { component.ngOnInit(); component.ngAfterViewInit(); - component.configMappingEditorContent = "\r\n 15.1X49-D50.3\r\n \r\n node0\r\n \r\n \r\n {(node1)=(name1)}\r\n 675453432\r\n \r\n \r\n 199.37.184.242\r\n 675453432\r\n \r\n \r\n \r\n "; + component.configMappingEditorContent = "\r\n 15.1X49-D50.3\r\n \r\n node0\r\n \r\n \r\n {(node1)=(name1)}\r\n 135.144.3.125\r\n \r\n \r\n 199.37.184.242\r\n 135.144.3.125\r\n \r\n \r\n \r\n "; mappingEditorService.initialise(component.templateeditor.getEditor(), component.configMappingEditorContent, component.modal); component.selectedWord = "node0"; component.tempName = "name0"; @@ -373,4 +372,75 @@ describe('GoldenConfigurationComponent', () => { })); + // fileChange method + it('Should validatte fileChange method if file type is xml', async(() => { + let reader = new FileReader(); + let file = new File(["testing"], "foo.xml", {type: "text/xml"}); + let input = {files: [file]}; + component.refObj = true; + + component.fileChange(input); + + component.readFile(input.files[0], reader,(res) => { + expect(component.selectedUploadType).toEqual('Generated Template'); + expect(component.configMappingEditorContent).toEqual(res); + expect(component.artifactRequest.templateContent).toEqual(res); + }); + })); + + it('Should validatte fileChange method if file type is json', async(() => { + let reader = new FileReader(); + let file = new File(["testing"], "foo.json", {type: "text/json"}); + let input = {files: [file]}; + component.refObj = true; + + component.fileChange(input); + + component.readFile(input.files[0], reader,(res) => { + expect(component.selectedUploadType).toEqual('Generated Template'); + expect(component.configMappingEditorContent).toEqual(res); + expect(component.artifactRequest.templateContent).toEqual(res); + }); + })); + + it('Should validatte fileChange method if file type is none ', async(() => { + let reader = new FileReader(); + let file = new File(["testing"], "foo", {type: ""}); + let input = {files: [file]}; + component.refObj = true; + + component.fileChange(input); + + component.readFile(input.files[0], reader,(res) => { + expect(typeof sessionStorage.getItem('fileType')).toEqual('string') + expect(component.selectedUploadType).toEqual('Generated Template'); + expect(component.configMappingEditorContent).toEqual(res); + expect(component.artifactRequest.templateContent).toEqual(res); + }); + })); + + it('Should validate if files is false', () => { + let spy = spyOn(NotificationsService.prototype, 'error'); + let reader = new FileReader(); + let input = {files: []}; + component.refObj = true; + + component.fileChange(input); + + expect(spy).toHaveBeenCalled(); + }); + + it('Should validate if refObj is undefined', () => { + let spy = spyOn(NotificationsService.prototype, 'error'); + let reader = new FileReader(); + let input = {files: []}; + component.refObj = undefined; + + component.fileChange(input); + + expect(spy).toHaveBeenCalled(); + }); + + // End fileChange method + }); -- cgit 1.2.3-korg