diff --git a/testgenerator-web/testgenerator-web/src/app/components/test/test.component.html b/testgenerator-web/testgenerator-web/src/app/components/test/test.component.html index 09b217d2948bdb8ff7d5ab0a06394cc6459dbec9..443775716d9d15f7c662c4fc6787d501e5c5edb1 100644 --- a/testgenerator-web/testgenerator-web/src/app/components/test/test.component.html +++ b/testgenerator-web/testgenerator-web/src/app/components/test/test.component.html @@ -15,8 +15,8 @@ </div> <br> <div class="col"> - <label for="priority" i18n="testcase priority">Test priority</label> - <input mdbInput type="number" class="form-control" id="priority" value="{{testcase.priority}}"> + <label for="testPriority" i18n="testcase priority">Test priority</label> + <input mdbInput type="number" class="form-control" id="testPriority" value="{{testcase.priority}}"> </div> </div> diff --git a/testgenerator-web/testgenerator-web/src/app/components/test/test.component.ts b/testgenerator-web/testgenerator-web/src/app/components/test/test.component.ts index 95bab8b75477fd9b9759fd70e92dd77494789e74..fdad27cf0054a7f7e1fedca3f9349d90b0539218 100644 --- a/testgenerator-web/testgenerator-web/src/app/components/test/test.component.ts +++ b/testgenerator-web/testgenerator-web/src/app/components/test/test.component.ts @@ -1,477 +1,478 @@ -import { Component, OnInit } from '@angular/core'; -import { BPMNTestcase } from 'src/app/models/bpmn-testcase'; -import { Router, ActivatedRoute } from '@angular/router'; -import { TestService } from 'src/app/services/test.service'; -import { FlowInfo } from 'src/app/models/flow-info'; -import { TaskVariables } from 'src/app/models/task-variables'; -import { VariableValue } from 'src/app/models/variable-value'; -import { FormGroup, FormBuilder, FormArray, Validators, FormControl } from '@angular/forms'; -import ValidationUtils from 'src/app/utils/validation'; -import { DataType } from 'src/app/models/data-type'; -import { VariableProposals } from 'src/app/models/variable-proposals'; -import { VariableValueEndCheck } from 'src/app/models/variable-value-endcheck'; -import { ServiceWithMock } from 'src/app/models/service-with-mock'; -import { ExternalTopicWithMocks } from 'src/app/models/external-topic-with-mocks'; - -@Component({ - selector: 'app-test', - templateUrl: './test.component.html', - styleUrls: ['./test.component.css'] -}) -export class TestComponent implements OnInit { - - isTestLoading: boolean; - testcase: BPMNTestcase; - actualProject: number; - actualFlow: string; - actualTest: string; - - isInfoLoading: boolean; - flowInfo: FlowInfo; - - isEdit: boolean; - - isLoading: boolean; - - dataTypes = new Map<string, string>(); - dataTypesEnum: typeof DataType = DataType; - - mocks = new Map<string, Array<string>>(); - - proposals: Array<Array<VariableProposals>>; - - public formGroup: FormGroup; - - constructor(private _fb: FormBuilder, private testService: TestService, private router: Router, private route: ActivatedRoute) { - this.route.params.subscribe(params => { - this.actualProject = params['projectId']; - this.actualFlow = params['flowId']; - this.actualTest = params['testId']; - }) - - this.initFormGroup(); - } - - async ngOnInit() { - this.isLoading = true; - - await this.loadInfo(); - - if (this.actualTest) { - this.isEdit = true; - await this.loadTest(); - } else { - this.isEdit = false; - } - - this.initTestcase(); - - this.isLoading = false; - } - - /** - * Because the structure of the underlying bpmn-process-model isn't known during development, - * the creation of the formGroup and testcase needs to be dynamic. This method creates the formGroup - * on a basis of flowInfo (variables, userTasks) and pushs the corresponding testcase values to this formGroup. - * The testcase has two sections. - * 1. Input of variable values for user tasks - * 2. End checking concrete values at the end of the process instance - * - * Both sections are going to be prepared in this method. - */ - initTestcase() { - if (!this.testcase) { - this.testcase = this.createTestcase(this.actualFlow); - } - - //1. Preparing formGroup and testcase-values for user task - this.proposals = []; - let taskVariableValueList = []; - let taskVariableList = []; - for (let userInputs of this.flowInfo.userInputs) { - - if (userInputs.inputVariables.length > 0) { - let inputProposals = []; - let valueObj = {}; - let variableList = []; - for (let variables of userInputs.inputVariables) { - inputProposals.push(this.getVariableProposals(variables)); - let countVariableFrequency = this.countVariable(variables, taskVariableValueList); - let value = this.getVariableValueOrDefault(userInputs.name, variables, countVariableFrequency); - valueObj[variables] = value; - - let newVariable = this.createVariableValue(variables, value); - variableList.push(newVariable); - } - - this.proposals.push(inputProposals); - taskVariableValueList.push(valueObj); - let newTaskVariable = this.createTaskVariables(userInputs.name, variableList); - this.addTaskVariableFormGroup(variableList); - taskVariableList.push(newTaskVariable); - } - } - - //2. Preparing formGroup and testcase-values for end check - let endCheckVariableList = []; - let endCheckValueObj = {}; - let valueObj = {}; - for (let endCheckVariable of this.flowInfo.variables) { - let value = this.getEndCheckValueOrDefault(endCheckVariable.variable); - let compareOperator = this.getEndCheckCompareOperatorOrDefault(endCheckVariable.variable); - let newVariable = this.createVariableValueEndCheck(endCheckVariable.variable, value, compareOperator); - - valueObj[endCheckVariable.variable] = value; - endCheckVariableList.push(newVariable); - endCheckValueObj[endCheckVariable.variable] = value; - let endCheckCompareField = endCheckVariable.variable + "Compare"; - endCheckValueObj[endCheckCompareField] = newVariable.compareOperator; - this.addEndVariableFormGroup(newVariable); - } - - - //3. Preparing formGroup and testcase-values for mock - let mockObj = {}; - for(let service of this.flowInfo.delegateServices) { - this.addMockFormGroupDelegate(service); - - let mockValue = this.getServiceMockOrNull(service.mocks); - - mockObj[service.serviceName] = mockValue; - } - for(let externalTopic of this.flowInfo.externalTopics) { - this.addMockFormGroupExternal(externalTopic); - - let mockValue = this.getServiceMockOrNull(externalTopic.mocks); - - mockObj[externalTopic.externalTopicName] = mockValue; - } - - //Patching all values to formGroup bound object - this.testcase.taskVariableList = taskVariableList; - this.testcase.endChecks = endCheckVariableList; - - let formObj = {}; - formObj['name'] = this.testcase.name; - formObj['priority'] = this.testcase.priority; - formObj['taskVariableList'] = taskVariableValueList; - formObj['endChecks'] = endCheckValueObj; - formObj['mocks'] = mockObj; - - console.log(formObj); - - this.formGroup.patchValue(formObj); - } - - async loadTest() { - this.isTestLoading = true; - try { - let result = await this.testService.getTest(this.actualProject, this.actualTest); - this.testcase = result; - } finally { - this.isTestLoading = false; - } - } - - async loadInfo() { - this.isInfoLoading = true; - try { - let result = await this.testService.getInfo(this.actualProject, this.actualFlow); - this.flowInfo = result; - this.cleanUpServiceWithMocks(); - this.initVariableDataTypes(); - } finally { - this.isInfoLoading = false; - } - } - - async save() { - if (!this.formGroup.invalid) { - - this.extractForm(); - - if (this.isEdit) { - await this.updateTestcase(); - } else { - await this.saveTestcase(); - } - } else { - ValidationUtils.validateAllFormFields(this.formGroup); - } - } - - async saveTestcase() { - try { - await this.testService.createTest(this.actualProject, this.testcase); - this.router.navigate(['../'], { relativeTo: this.route }); - } catch (err) { - if (err.status === 409) { - this.formGroup.controls['name'].setErrors({ 'testIdTaken': true }); - } else { - throw err; - } - } finally { - // - } - } - - async updateTestcase() { - try { - await this.testService.updateTest(this.actualProject, this.actualTest, this.testcase); - this.router.navigate(['../../'], { relativeTo: this.route }); - } catch (err) { - if (err.status === 409) { - this.formGroup.controls['name'].setErrors({ 'testIdTaken': true }); - } else { - throw err; - } - } finally { - // - } - } - - createVariableValue(variable: string, value: Object): VariableValue { - return { - variable: variable, - value: value - } - } - - createVariableValueEndCheck(variable: string, value: Object, compareOperator: string): VariableValueEndCheck { - return { - variable: variable, - value: value, - compareOperator: compareOperator - } - } - - createTaskVariables(id: string, variableList: Array<VariableValue>): TaskVariables { - return { - task: id, - variableValues: variableList - } - } - - createTestcase(flow: string): BPMNTestcase { - return { - name: "", - flow: flow, - taskVariableList: [], - endChecks: [], - mocks: [], - priority: 0 - } - } - - countVariable(variable: string, taskVariableValueList: any[]) { - let count = 0; - for(let taskVariable of taskVariableValueList) { - if(taskVariable[variable]) { - count++; - } - } - - return count; - } - - getVariableValueOrDefault(task: string, variable: string, count: number) { - for (let taskVariables of this.testcase.taskVariableList) { - if (taskVariables.task == task) { - for (let variableValue of taskVariables.variableValues) { - if (variableValue.variable == variable) { - if(count == 0) { - if (this.dataTypes.get(variable) == 'java.lang.Boolean') { - return variableValue.value.toString(); - } else { - return variableValue.value; - } - } else { - count--; - } - } - } - } - } - - if (this.dataTypes.get(variable) == 'java.lang.Boolean') { - return 'null'; - } - - return null; - } - - getEndCheckValueOrDefault(variable: string) { - for (let endCheck of this.testcase.endChecks) { - if (endCheck.variable == variable) { - if (this.dataTypes.get(variable) == 'java.lang.Boolean') { - return endCheck.value.toString(); - } else { - return endCheck.value; - } - } - } - - if (this.dataTypes.get(variable) == 'java.lang.Boolean') { - return 'null'; - } - - return null; - } - - getEndCheckCompareOperatorOrDefault(variable: string) { - for (let endCheck of this.testcase.endChecks) { - if (endCheck.variable == variable) { - return endCheck.compareOperator; - } - } - - return "=="; - } - - getVariableProposals(variable: string): VariableProposals { - for (let infoVariable of this.flowInfo.variables) { - if (infoVariable.variable == variable) { - return infoVariable; - } - } - - return null; - } - - initFormGroup() { - this.formGroup = this._fb.group({ - name: ['', Validators.compose([Validators.required])], - taskVariableList: this._fb.array([ - ]), - endChecks: this._fb.group({}), - mocks: this._fb.group({}) - }); - } - - private addTaskVariableFormGroup(variableList: Array<VariableValue>) { - - let controls = {}; - for (let v of variableList) { - controls[v.variable] = ['']; - } - let formGroup = this._fb.group(controls); - - this.taskVariableList.push(formGroup); - } - - get taskVariableList(): FormArray { - return <FormArray>this.formGroup.get('taskVariableList'); - } - - private addEndVariableFormGroup(variableObj: VariableValueEndCheck) { - this.endChecks.addControl(variableObj.variable, new FormControl('')); - this.endChecks.addControl(variableObj.variable + "Compare", new FormControl('')); - } - - private addMockFormGroupDelegate(serviceWithMocks: ServiceWithMock) { - this.mocksForm.addControl(serviceWithMocks.serviceName, new FormControl('')); - } - - private addMockFormGroupExternal(externalTopicMocks: ExternalTopicWithMocks) { - this.mocksForm.addControl(externalTopicMocks.externalTopicName, new FormControl('')); - } - - get endChecks(): FormGroup { - return <FormGroup>this.formGroup.get('endChecks'); - } - - get mocksForm(): FormGroup { - return <FormGroup>this.formGroup.get('mocks'); - } - - private extractForm() { - const formValue = this.formGroup.value; - console.log(formValue); - - //Extract name - this.testcase.name = formValue.name; - - //Extract priority - this.testcase.priority = formValue.priority; - - //Extract task-variables - for (var _i = 0; _i < formValue.taskVariableList.length; _i++) { - let variableValue = formValue.taskVariableList[_i]; - for (let v of this.testcase.taskVariableList[_i].variableValues) { - if (this.dataTypes.get(v.variable) == 'java.lang.Boolean') { - v.value = JSON.parse(variableValue[v.variable]); - } else { - v.value = variableValue[v.variable]; - } - } - this.testcase.taskVariableList[_i].variableValues = this.testcase.taskVariableList[_i].variableValues - .filter(v => v.value !== null); - } - - this.testcase.taskVariableList = this.testcase.taskVariableList - .filter(v => v.variableValues.length > 0); - - //Extract endchecks - for (var _i = 0; _i < this.testcase.endChecks.length; _i++) { - let value = formValue.endChecks[this.testcase.endChecks[_i].variable]; - if (this.dataTypes.get(this.testcase.endChecks[_i].variable) == 'java.lang.Boolean') { - this.testcase.endChecks[_i].value = JSON.parse(value); - } else { - this.testcase.endChecks[_i].value = value; - } - - let variableCompareField = this.testcase.endChecks[_i].variable + "Compare"; - this.testcase.endChecks[_i].compareOperator = formValue.endChecks[variableCompareField]; - } - - this.testcase.endChecks = this.testcase.endChecks - .filter(v => v.value != null); - - //Extract mocks - this.testcase.mocks = []; - for(let serviceName of this.mocks.keys()) { - let mockName = formValue.mocks[serviceName]; - if(mockName) { - this.testcase.mocks.push(mockName); - } - } - - console.log(this.testcase); - } - - private cleanUpServiceWithMocks() { - this.flowInfo.delegateServices = this.flowInfo.delegateServices - .filter(delegateService => delegateService.mocks.length > 0); - - this.flowInfo.externalTopics = this.flowInfo.externalTopics - .filter(externalTopic => externalTopic.mocks.length > 0); - - this.flowInfo.delegateServices.forEach(service => { - let mockNames = service.mocks; - mockNames.unshift(null); - this.mocks.set(service.serviceName, mockNames); - }); - - this.flowInfo.externalTopics.forEach(service => { - let mockNames = service.mocks; - mockNames.unshift(null); - this.mocks.set(service.externalTopicName, mockNames); - }); - } - - private initVariableDataTypes() { - for (let variableValue of this.flowInfo.variables) { - this.dataTypes.set(variableValue.variable, variableValue.type); - } - } - - private getServiceMockOrNull(serviceMocks: Array<string>) { - for(let serviceMockName of serviceMocks) { - if(this.testcase.mocks.indexOf(serviceMockName) >= 0) { - return serviceMockName; - } - } - - return null; - } -} +import { Component, OnInit } from '@angular/core'; +import { BPMNTestcase } from 'src/app/models/bpmn-testcase'; +import { Router, ActivatedRoute } from '@angular/router'; +import { TestService } from 'src/app/services/test.service'; +import { FlowInfo } from 'src/app/models/flow-info'; +import { TaskVariables } from 'src/app/models/task-variables'; +import { VariableValue } from 'src/app/models/variable-value'; +import { FormGroup, FormBuilder, FormArray, Validators, FormControl } from '@angular/forms'; +import ValidationUtils from 'src/app/utils/validation'; +import { DataType } from 'src/app/models/data-type'; +import { VariableProposals } from 'src/app/models/variable-proposals'; +import { VariableValueEndCheck } from 'src/app/models/variable-value-endcheck'; +import { ServiceWithMock } from 'src/app/models/service-with-mock'; +import { ExternalTopicWithMocks } from 'src/app/models/external-topic-with-mocks'; + +@Component({ + selector: 'app-test', + templateUrl: './test.component.html', + styleUrls: ['./test.component.css'] +}) +export class TestComponent implements OnInit { + + isTestLoading: boolean; + testcase: BPMNTestcase; + actualProject: number; + actualFlow: string; + actualTest: string; + + isInfoLoading: boolean; + flowInfo: FlowInfo; + + isEdit: boolean; + + isLoading: boolean; + + dataTypes = new Map<string, string>(); + dataTypesEnum: typeof DataType = DataType; + + mocks = new Map<string, Array<string>>(); + + proposals: Array<Array<VariableProposals>>; + + public formGroup: FormGroup; + + constructor(private _fb: FormBuilder, private testService: TestService, private router: Router, private route: ActivatedRoute) { + this.route.params.subscribe(params => { + this.actualProject = params['projectId']; + this.actualFlow = params['flowId']; + this.actualTest = params['testId']; + }) + + this.initFormGroup(); + } + + async ngOnInit() { + this.isLoading = true; + + await this.loadInfo(); + + if (this.actualTest) { + this.isEdit = true; + await this.loadTest(); + } else { + this.isEdit = false; + } + + this.initTestcase(); + + this.isLoading = false; + } + + /** + * Because the structure of the underlying bpmn-process-model isn't known during development, + * the creation of the formGroup and testcase needs to be dynamic. This method creates the formGroup + * on a basis of flowInfo (variables, userTasks) and pushs the corresponding testcase values to this formGroup. + * The testcase has two sections. + * 1. Input of variable values for user tasks + * 2. End checking concrete values at the end of the process instance + * + * Both sections are going to be prepared in this method. + */ + initTestcase() { + if (!this.testcase) { + this.testcase = this.createTestcase(this.actualFlow); + } + + //1. Preparing formGroup and testcase-values for user task + this.proposals = []; + let taskVariableValueList = []; + let taskVariableList = []; + for (let userInputs of this.flowInfo.userInputs) { + + if (userInputs.inputVariables.length > 0) { + let inputProposals = []; + let valueObj = {}; + let variableList = []; + for (let variables of userInputs.inputVariables) { + inputProposals.push(this.getVariableProposals(variables)); + let countVariableFrequency = this.countVariable(variables, taskVariableValueList); + let value = this.getVariableValueOrDefault(userInputs.name, variables, countVariableFrequency); + valueObj[variables] = value; + + let newVariable = this.createVariableValue(variables, value); + variableList.push(newVariable); + } + + this.proposals.push(inputProposals); + taskVariableValueList.push(valueObj); + let newTaskVariable = this.createTaskVariables(userInputs.name, variableList); + this.addTaskVariableFormGroup(variableList); + taskVariableList.push(newTaskVariable); + } + } + + //2. Preparing formGroup and testcase-values for end check + let endCheckVariableList = []; + let endCheckValueObj = {}; + let valueObj = {}; + for (let endCheckVariable of this.flowInfo.variables) { + let value = this.getEndCheckValueOrDefault(endCheckVariable.variable); + let compareOperator = this.getEndCheckCompareOperatorOrDefault(endCheckVariable.variable); + let newVariable = this.createVariableValueEndCheck(endCheckVariable.variable, value, compareOperator); + + valueObj[endCheckVariable.variable] = value; + endCheckVariableList.push(newVariable); + endCheckValueObj[endCheckVariable.variable] = value; + let endCheckCompareField = endCheckVariable.variable + "Compare"; + endCheckValueObj[endCheckCompareField] = newVariable.compareOperator; + this.addEndVariableFormGroup(newVariable); + } + + + //3. Preparing formGroup and testcase-values for mock + let mockObj = {}; + for(let service of this.flowInfo.delegateServices) { + this.addMockFormGroupDelegate(service); + + let mockValue = this.getServiceMockOrNull(service.mocks); + + mockObj[service.serviceName] = mockValue; + } + for(let externalTopic of this.flowInfo.externalTopics) { + this.addMockFormGroupExternal(externalTopic); + + let mockValue = this.getServiceMockOrNull(externalTopic.mocks); + + mockObj[externalTopic.externalTopicName] = mockValue; + } + + //Patching all values to formGroup bound object + this.testcase.taskVariableList = taskVariableList; + this.testcase.endChecks = endCheckVariableList; + + let formObj = {}; + formObj['name'] = this.testcase.name; + formObj['priority'] = this.testcase.priority; + formObj['taskVariableList'] = taskVariableValueList; + formObj['endChecks'] = endCheckValueObj; + formObj['mocks'] = mockObj; + this.formGroup.patchValue(formObj); + } + + async loadTest() { + this.isTestLoading = true; + try { + let result = await this.testService.getTest(this.actualProject, this.actualTest); + this.testcase = result; + } finally { + this.isTestLoading = false; + } + } + + async loadInfo() { + this.isInfoLoading = true; + try { + let result = await this.testService.getInfo(this.actualProject, this.actualFlow); + this.flowInfo = result; + this.cleanUpServiceWithMocks(); + this.initVariableDataTypes(); + } finally { + this.isInfoLoading = false; + } + } + + async save() { + if (!this.formGroup.invalid) { + + this.extractForm(); + + /** + * Add Priority to the test case + * @info wenn die Priorität über ein FormGroupName/NgModel hinzugefügt wird, + * initialisiert der Test nicht. Daher gehen wir über die ID + */ + this.testcase.priority = parseInt((<HTMLInputElement>document.getElementById("testPriority")).value); + + if (this.isEdit) { + await this.updateTestcase(); + } else { + await this.saveTestcase(); + } + } else { + ValidationUtils.validateAllFormFields(this.formGroup); + } + } + + async saveTestcase() { + try { + await this.testService.createTest(this.actualProject, this.testcase); + this.router.navigate(['../'], { relativeTo: this.route }); + } catch (err) { + if (err.status === 409) { + this.formGroup.controls['name'].setErrors({ 'testIdTaken': true }); + } else { + throw err; + } + } finally { + // + } + } + + async updateTestcase() { + try { + // TODO + await this.testService.updateTest(this.actualProject, this.actualTest, this.testcase); + this.router.navigate(['../../'], { relativeTo: this.route }); + } catch (err) { + if (err.status === 409) { + this.formGroup.controls['name'].setErrors({ 'testIdTaken': true }); + } else { + throw err; + } + } finally { + // + } + } + + createVariableValue(variable: string, value: Object): VariableValue { + return { + variable: variable, + value: value + } + } + + createVariableValueEndCheck(variable: string, value: Object, compareOperator: string): VariableValueEndCheck { + return { + variable: variable, + value: value, + compareOperator: compareOperator + } + } + + createTaskVariables(id: string, variableList: Array<VariableValue>): TaskVariables { + return { + task: id, + variableValues: variableList + } + } + + createTestcase(flow: string): BPMNTestcase { + return { + name: "", + flow: flow, + taskVariableList: [], + endChecks: [], + mocks: [], + priority: 0 + } + } + + countVariable(variable: string, taskVariableValueList: any[]) { + let count = 0; + for(let taskVariable of taskVariableValueList) { + if(taskVariable[variable]) { + count++; + } + } + + return count; + } + + getVariableValueOrDefault(task: string, variable: string, count: number) { + for (let taskVariables of this.testcase.taskVariableList) { + if (taskVariables.task == task) { + for (let variableValue of taskVariables.variableValues) { + if (variableValue.variable == variable) { + if(count == 0) { + if (this.dataTypes.get(variable) == 'java.lang.Boolean') { + return variableValue.value.toString(); + } else { + return variableValue.value; + } + } else { + count--; + } + } + } + } + } + + if (this.dataTypes.get(variable) == 'java.lang.Boolean') { + return 'null'; + } + + return null; + } + + getEndCheckValueOrDefault(variable: string) { + for (let endCheck of this.testcase.endChecks) { + if (endCheck.variable == variable) { + if (this.dataTypes.get(variable) == 'java.lang.Boolean') { + return endCheck.value.toString(); + } else { + return endCheck.value; + } + } + } + + if (this.dataTypes.get(variable) == 'java.lang.Boolean') { + return 'null'; + } + + return null; + } + + getEndCheckCompareOperatorOrDefault(variable: string) { + for (let endCheck of this.testcase.endChecks) { + if (endCheck.variable == variable) { + return endCheck.compareOperator; + } + } + + return "=="; + } + + getVariableProposals(variable: string): VariableProposals { + for (let infoVariable of this.flowInfo.variables) { + if (infoVariable.variable == variable) { + return infoVariable; + } + } + + return null; + } + + initFormGroup() { + this.formGroup = this._fb.group({ + name: ['', Validators.compose([Validators.required])], + taskVariableList: this._fb.array([ + ]), + endChecks: this._fb.group({}), + mocks: this._fb.group({}) + }); + } + + private addTaskVariableFormGroup(variableList: Array<VariableValue>) { + + let controls = {}; + for (let v of variableList) { + controls[v.variable] = ['']; + } + let formGroup = this._fb.group(controls); + + this.taskVariableList.push(formGroup); + } + + get taskVariableList(): FormArray { + return <FormArray>this.formGroup.get('taskVariableList'); + } + + private addEndVariableFormGroup(variableObj: VariableValueEndCheck) { + this.endChecks.addControl(variableObj.variable, new FormControl('')); + this.endChecks.addControl(variableObj.variable + "Compare", new FormControl('')); + } + + private addMockFormGroupDelegate(serviceWithMocks: ServiceWithMock) { + this.mocksForm.addControl(serviceWithMocks.serviceName, new FormControl('')); + } + + private addMockFormGroupExternal(externalTopicMocks: ExternalTopicWithMocks) { + this.mocksForm.addControl(externalTopicMocks.externalTopicName, new FormControl('')); + } + + get endChecks(): FormGroup { + return <FormGroup>this.formGroup.get('endChecks'); + } + + get mocksForm(): FormGroup { + return <FormGroup>this.formGroup.get('mocks'); + } + + private extractForm() { + const formValue = this.formGroup.value; + + //Extract name + this.testcase.name = formValue.name; + + //Extract task-variables + for (var _i = 0; _i < formValue.taskVariableList.length; _i++) { + let variableValue = formValue.taskVariableList[_i]; + for (let v of this.testcase.taskVariableList[_i].variableValues) { + if (this.dataTypes.get(v.variable) == 'java.lang.Boolean') { + v.value = JSON.parse(variableValue[v.variable]); + } else { + v.value = variableValue[v.variable]; + } + } + this.testcase.taskVariableList[_i].variableValues = this.testcase.taskVariableList[_i].variableValues + .filter(v => v.value !== null); + } + + this.testcase.taskVariableList = this.testcase.taskVariableList + .filter(v => v.variableValues.length > 0); + + //Extract endchecks + for (var _i = 0; _i < this.testcase.endChecks.length; _i++) { + let value = formValue.endChecks[this.testcase.endChecks[_i].variable]; + if (this.dataTypes.get(this.testcase.endChecks[_i].variable) == 'java.lang.Boolean') { + this.testcase.endChecks[_i].value = JSON.parse(value); + } else { + this.testcase.endChecks[_i].value = value; + } + + let variableCompareField = this.testcase.endChecks[_i].variable + "Compare"; + this.testcase.endChecks[_i].compareOperator = formValue.endChecks[variableCompareField]; + } + + this.testcase.endChecks = this.testcase.endChecks + .filter(v => v.value != null); + + //Extract mocks + this.testcase.mocks = []; + for(let serviceName of this.mocks.keys()) { + let mockName = formValue.mocks[serviceName]; + if(mockName) { + this.testcase.mocks.push(mockName); + } + } + + console.log(this.testcase); + } + + private cleanUpServiceWithMocks() { + this.flowInfo.delegateServices = this.flowInfo.delegateServices + .filter(delegateService => delegateService.mocks.length > 0); + + this.flowInfo.externalTopics = this.flowInfo.externalTopics + .filter(externalTopic => externalTopic.mocks.length > 0); + + this.flowInfo.delegateServices.forEach(service => { + let mockNames = service.mocks; + mockNames.unshift(null); + this.mocks.set(service.serviceName, mockNames); + }); + + this.flowInfo.externalTopics.forEach(service => { + let mockNames = service.mocks; + mockNames.unshift(null); + this.mocks.set(service.externalTopicName, mockNames); + }); + } + + private initVariableDataTypes() { + for (let variableValue of this.flowInfo.variables) { + this.dataTypes.set(variableValue.variable, variableValue.type); + } + } + + private getServiceMockOrNull(serviceMocks: Array<string>) { + for(let serviceMockName of serviceMocks) { + if(this.testcase.mocks.indexOf(serviceMockName) >= 0) { + return serviceMockName; + } + } + + return null; + } +}