aboutsummaryrefslogtreecommitdiffstats
path: root/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/PropertiesAssignmentUpdateFlow.java
blob: 26bfbac55c52ab183219c19c5a2aee184e296014 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */

package org.onap.sdc.frontend.ci.tests.execute.sanity;

import com.aventstack.extentreports.Status;
import fj.data.Either;
import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.backend.ci.tests.datatypes.enums.NormativeTypesEnum;
import org.onap.sdc.backend.ci.tests.datatypes.enums.ResourceCategoryEnum;
import org.onap.sdc.backend.ci.tests.datatypes.http.RestResponse;
import org.onap.sdc.frontend.ci.tests.utilities.CatalogUIUtilitis;
import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
import org.onap.sdc.frontend.ci.tests.utilities.ResourceUIUtils;
import org.onap.sdc.frontend.ci.tests.verificator.PropertiesAssignmentVerificator;
import org.onap.sdc.frontend.ci.tests.verificator.VfVerificator;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
import org.onap.sdc.frontend.ci.tests.datatypes.CanvasElement;
import org.onap.sdc.frontend.ci.tests.datatypes.CanvasManager;
import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
import org.onap.sdc.backend.ci.tests.datatypes.ResourceReqDetails;
import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
import org.onap.sdc.frontend.ci.tests.datatypes.TopMenuButtonsEnum;
import org.onap.sdc.backend.ci.tests.datatypes.VendorLicenseModel;
import org.onap.sdc.backend.ci.tests.datatypes.VendorSoftwareProductObject;
import org.onap.sdc.backend.ci.tests.datatypes.enums.LifeCycleStatesEnum;
import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
import org.onap.sdc.frontend.ci.tests.pages.CompositionPage;
import org.onap.sdc.frontend.ci.tests.pages.DeploymentArtifactPage;
import org.onap.sdc.frontend.ci.tests.pages.GeneralPageElements;
import org.onap.sdc.frontend.ci.tests.pages.HeatParamNameBuilder;
import org.onap.sdc.frontend.ci.tests.pages.HomePage;
import org.onap.sdc.frontend.ci.tests.pages.PropertiesAssignmentPage;
import org.onap.sdc.frontend.ci.tests.pages.PropertiesPage;
import org.onap.sdc.frontend.ci.tests.pages.PropertyNameBuilder;
import org.onap.sdc.frontend.ci.tests.pages.ResourceGeneralPage;
import org.onap.sdc.backend.ci.tests.utils.general.AtomicOperationUtils;
import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
import org.onap.sdc.backend.ci.tests.utils.general.OnboardingUtillViaApis;
import org.onap.sdc.backend.ci.tests.utils.general.VendorLicenseModelRestUtils;
import org.onap.sdc.backend.ci.tests.utils.general.VendorSoftwareProductRestUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.List;

import static org.testng.Assert.assertTrue;

public class PropertiesAssignmentUpdateFlow extends SetupCDTest {

    private static String filePath;
    private static String origFile = "virc_fe_be.csar";
    private static String origFile1 = "virc.csar";
    protected User sdncDesignerDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);


    @BeforeClass
    public void beforeClass() {
        filePath = FileHandling.getFilePath("");
    }

    @BeforeMethod
    public void beforeTest() {
        System.out.println("File repository is : " + filePath);
    }

    @DataProvider(name = "assetFilesInputs", parallel = false)
    public Object[][] createDataInputs() {
        return new Object[][]{
                {"editInputValueTopChange.csar", ""},
                {"editInputValueNoTopChange.csar", "Updated-SRE-Mgt"}};
    }

    /**
     * Topoplogy change in updated file - designer changes in inputs values are not kept after update
     * No topoplogy change in updated file - designer changes in inputs values are kept after update
     *
     * @param updFileName     - csar for update
     * @param validationValue - expected property value after update
     * @throws Exception
     */
    @Test(dataProvider = "assetFilesInputs")
    public void updateInputDefaultValueTest(String updFileName, String validationValue) throws Exception {
        setLog(updFileName);

        String origTestFile = origFile;
        String componentName = "abstract_virc_fe_be_0";
        String inputName = "management_net_name";
        String inputUpdValue = "Updated-SRE-Mgt";

        //Import csar
        ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType("ciRes", NormativeTypesEnum.ROOT,
                ResourceCategoryEnum.APPLICATION_L4_DATABASE, getUser().getUserId(), ResourceTypeEnum.VF.toString());
        resourceMetaData.setVersion("0.1");
        ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, origTestFile, getUser());

        //Edit Input value
        ResourceGeneralPage.getLeftMenu().moveToPropertiesAssignmentScreen();
        PropertiesAssignmentPage.clickOnComponentInComposition(componentName);
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentPage.editPropertyValue(PropertyNameBuilder.buildInputField(inputName), inputUpdValue);
        PropertiesAssignmentPage.clickOnSaveButton();

        //Certify  VF via API
        Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();


        HomePage.navigateToHomePage();
        CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
        GeneralUIUtils.findComponentAndClick(resourceMetaData.getName());

        //Update VF
        ResourceGeneralPage.getLeftMenu().moveToGeneralScreen();
        GeneralPageElements.clickCheckoutButton();
        SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating VF with new file"));
        ResourceUIUtils.updateVfWithCsar(filePath, updFileName);

        //Validate Input value - 1) empty in case of topology change; 2) user value is kept if no topology change
        ResourceGeneralPage.getLeftMenu().moveToPropertiesAssignmentScreen();
        PropertiesAssignmentPage.clickOnComponentInComposition(componentName);
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildInputField(inputName), validationValue);

    }


    @DataProvider(name = "assetFilesProperties", parallel = false)
    public Object[][] createDataProp() {
        return new Object[][]{
                {"editedPropValueToEmpty.csar", "value-prop-vm_type_tag", "updated_by_designer"},
                {"newPropValueToEmpty.csar", "value-prop-high_availablity", "updated_by_designer"},
                {"editedPropValueToNew.csar", "value-prop-vm_type_tag", "updated_by_file"},
                {"editedPropValueToEmptyTopChange.csar", "value-prop-vm_type_tag", ""},
                {"newPropValueToEmptyTopChange.csar", "value-prop-high_availablity", ""},
                {"editedPropValueToNewTopChange.csar", "value-prop-vm_type_tag", "updated_by_file"}};

    }

    /**
     * No topoplogy change in updated file - designer changes in properties values are kept after update
     * OrigFile       Designer       UpdFile       Result After Update
     * ---------------------------------------------------------------
     * prop1=value1   prop1=value2   prop1=null    prop1=value2
     * prop1=null     prop1=value1   prop1=null    prop1=value1
     * prop1=value1   prop1=value2   prop1=value3  prop1=value3
     *
     *
     * Topoplogy change in updated file - designer changes in properties values are not kept after update
     * OrigFile       Designer       UpdFile       Result After Update
     * ---------------------------------------------------------------
     * prop1=value1   prop1=value2   prop1=null    prop1=null
     * prop1=null     prop1=value1   prop1=null    prop1=null
     * prop1=value1   prop1=value2   prop1=value3  prop1=value3
     *
     * @param updFileName     - csar for update
     * @param propertyName
     * @param validationValue - expected property value after update
     * @throws Exception
     */
    @Test(dataProvider = "assetFilesProperties")
    public void updatePropertyDefaultValueTest(String updFileName, String propertyName, String validationValue) throws Exception {
        setLog(updFileName);
        String origTestFile = origFile;
        String componentName = "abstract_virc_fe_be_0";
        String propertyUpdValue = "updated_by_designer";

        //Import csar
        ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType("ciRes", NormativeTypesEnum.ROOT,
                ResourceCategoryEnum.APPLICATION_L4_DATABASE, getUser().getUserId(), ResourceTypeEnum.VF.toString());
        resourceMetaData.setVersion("0.1");
        ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, origTestFile, getUser());

        //Edit Input value
        ResourceGeneralPage.getLeftMenu().moveToPropertiesAssignmentScreen();
        PropertiesAssignmentPage.clickOnComponentInComposition(componentName);
        PropertiesAssignmentPage.editPropertyValue(propertyName, propertyUpdValue);
        PropertiesAssignmentPage.clickOnSaveButton();

        //Certify  VF via API
        Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1");
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();


        HomePage.navigateToHomePage();
        CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
        GeneralUIUtils.findComponentAndClick(resourceMetaData.getName());

        //Update VF
        ResourceGeneralPage.getLeftMenu().moveToGeneralScreen();
        GeneralPageElements.clickCheckoutButton();
        SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating VF with new file"));
        ResourceUIUtils.updateVfWithCsar(filePath, updFileName);

        //Validate Input value
        ResourceGeneralPage.getLeftMenu().moveToPropertiesAssignmentScreen();
        PropertiesAssignmentPage.clickOnComponentInComposition(componentName);
        PropertiesAssignmentVerificator.validatePropertyValue(propertyName, validationValue);
    }


    @Test
    public void updatePropertyChangeVfiVersionTest() throws Throwable {
        String vnfFile = "vIRC_FE_BE.zip";
        String componentName = "virc_fe_be_volume_0";
        String propertyName = "disk_bus";
        String propertyValue = "added_by_designer";
        String propertyValueUpd = "updated_by_designer";
        String inputName = componentName + "_" + propertyName;

        //Import VSP, create VF - v0.1
        String filePath = FileHandling.getVnfRepositoryPath();
        getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
        VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
        ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
        VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
            vendorLicenseModel, null);
        resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
        Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);

        //Edit Property Value and declare as input
        CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
        GeneralUIUtils.findComponentAndClick(resourceReqDetails.getName());
        ResourceGeneralPage.getLeftMenu().moveToPropertiesAssignmentScreen();
        PropertiesAssignmentPage.clickOnComponentInComposition(componentName);
        PropertiesAssignmentPage.editPropertyValue(PropertyNameBuilder.buildSimpleField(propertyName), propertyValue);
        PropertiesAssignmentPage.clickOnSaveButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(propertyName);
        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildInputField(inputName), propertyValue);

        //Check in VF and add VFi to Service
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
        ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(sdncDesignerDetails);
        getExtendTest().log(Status.INFO, "Create Service: " + serviceReqDetails.getName());
        org.openecomp.sdc.be.model.Service service = AtomicOperationUtils.createCustomService(serviceReqDetails, UserRoleEnum.DESIGNER, true).left().value();
        Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
        ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();

        //Find the VF input in Service properties, declare it as service input
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(serviceReqDetails.getName());
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildSimpleField(inputName), propertyValue);
        PropertiesAssignmentPage.findSearchBoxAndClick(inputName);
        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentVerificator.validatePropertyValue(
                PropertyNameBuilder.buildServiceDeclaredFieldVfLevel(componentInstance, componentName, propertyName),
                propertyValue
        );

        //Checkout VF, update input value and check in - v0.2
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(resourceReqDetails.getName());
        ResourceGeneralPage.getLeftMenu().moveToPropertiesAssignmentScreen();
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentPage.editPropertyValue(
                PropertyNameBuilder.buildDeclaredInputField(componentName, propertyName),
                propertyValueUpd
        );
//        PropertiesAssignmentPage.deletePropertyValue(PropertyNameBuilder.buildDeclaredInputField(componentName, propertyName));
        PropertiesAssignmentPage.clickOnSaveButton();
        ResourceGeneralPage.clickCheckinButton(resourceReqDetails.getName());

        //Change resource version on service
        resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resource.getName(), "0.2");
        AtomicOperationUtils.changeComponentInstanceVersion(service, componentInstance, resource, UserRoleEnum.DESIGNER, true);

        //Validate that service contains property with "get_input" value and input with the updated value
        GeneralUIUtils.findComponentAndClick(serviceReqDetails.getName());
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentPage.isPropertyChecked(inputName);
        PropertiesAssignmentVerificator.validatePropertyValue(
                PropertyNameBuilder.buildServicePropertyValue(componentName, propertyName),
                PropertyNameBuilder.buildServiceDeclaredPropertyValue(componentInstance, componentName, propertyName)
        );
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentVerificator.validatePropertyValue(
                PropertyNameBuilder.buildServiceDeclaredFieldVfLevel(componentInstance, componentName, propertyName),
                propertyValueUpd
        );
    }

    @Test
    public void updateServicePropertyChangeVfiVersionTest() throws Throwable {
        String vnfFile = "vIRC_FE_BE.zip";
        String componentName = "virc_fe_be_volume_0";
        String propertyName = "multi_stage_design";
        String propertyValueBoolean = "TRUE";

        //Import VSP, create VF - v0.1
        String filePath = FileHandling.getVnfRepositoryPath();
        getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
        VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
        ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
        VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
            vendorLicenseModel, null);
        resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
        Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);

        //Check in VF and add VFi to Service
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
        ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(sdncDesignerDetails);
        getExtendTest().log(Status.INFO, "Create Service: " + serviceReqDetails.getName());
        org.openecomp.sdc.be.model.Service service = AtomicOperationUtils.createCustomService(
                serviceReqDetails,
                UserRoleEnum.DESIGNER, true
        ).left().value();
        Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
        ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();

        //Find the VF input in Service properties, declare it as service input
        CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
        GeneralUIUtils.findComponentAndClick(serviceReqDetails.getName());
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentPage.findSearchBoxAndClick(propertyName);
        String defaultPropertyValueBoolean = PropertiesAssignmentPage.selectBooleanPropertyValue(PropertyNameBuilder.buildSimpleField(propertyName), propertyValueBoolean);
        PropertiesAssignmentPage.clickOnSaveButton();
        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentVerificator.validateBooleanPropertyValue(
                PropertyNameBuilder.buildServiceDeclaredFieldServiceLevel(componentInstance, propertyName),
                propertyValueBoolean
        );

//        //Checkout VF and check in - v0.2
        AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
        AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();

//        //Change resource version on service
        resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resource.getName(), "0.2");
        AtomicOperationUtils.changeComponentInstanceVersion(service, componentInstance, resource, UserRoleEnum.DESIGNER, true);

//        //Validate that service contains property with "get_input" value and input with the updated value
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(serviceReqDetails.getName());
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildSimpleField(propertyName),
                PropertyNameBuilder.buildServiceDeclaredPropValueServiceLevel(componentInstance, propertyName));
        PropertiesAssignmentPage.isPropertyChecked(propertyName);
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentVerificator.validateBooleanPropertyValue(
                PropertyNameBuilder.buildServiceDeclaredFieldServiceLevel(componentInstance, propertyName),
                StringUtils.isEmpty(defaultPropertyValueBoolean) ? propertyValueBoolean : defaultPropertyValueBoolean
        );
    }

    @Test
    public void deletePropertyChangeVfiVersionTest() throws Throwable {
        String vnfFile = "vIRC_FE_BE.zip";
        String componentName = "abstract_virc_fe_be_1";
        String propertyNameProp1 = "max_instances"; //empty property
        String propertyNameProp2 = "nfc_naming_code"; //non-empty property
        String propertyNameProp3 = "min_instances"; //non-empty property
        String propertyNameProp4 = "nf_type";
        String propertyValueProp2 = "virc_fe_be";
        String propertyValueProp3 = "0";
        String propertyValueUpd1 = "111";
        String propertyValueUpd2 = "updated_by_designer";
        String propertyValueUpd4 = "added_by_designer_on_service";
        String inputName1 = componentName + "_" + propertyNameProp1;
        String inputName2 = componentName + "_" + propertyNameProp2;
        String inputName3 = componentName + "_" + propertyNameProp3;

        //Import VSP, create VF - v0.1
        String filePath = FileHandling.getVnfRepositoryPath();
        getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
        VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
        ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
        VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
            vendorLicenseModel, null);
        resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
        Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);

        //VF - Declare properties as inputs
        CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
        GeneralUIUtils.findComponentAndClick(resourceReqDetails.getName());
        ResourceGeneralPage.getLeftMenu().moveToPropertiesAssignmentScreen();
        PropertiesAssignmentPage.clickOnComponentInComposition(componentName);
        PropertiesAssignmentPage.findSearchBoxAndClick(propertyNameProp1);
        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(propertyNameProp2);
        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(propertyNameProp3);
        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildInputField(inputName1), "");
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildInputField(inputName2), propertyValueProp2);
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildInputField(inputName3), propertyValueProp3);

        //Check in VF, create Service and add VFi to Service
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
        ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(sdncDesignerDetails);
        getExtendTest().log(Status.INFO, "Create Service: " + serviceReqDetails.getName());
        org.openecomp.sdc.be.model.Service service = AtomicOperationUtils.createCustomService(
                serviceReqDetails, UserRoleEnum.DESIGNER,
                true
        ).left().value();
        Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer = AtomicOperationUtils.addComponentInstanceToComponentContainer(resource, service, UserRoleEnum.DESIGNER, true);
        ComponentInstance componentInstance = addComponentInstanceToComponentContainer.left().value();

        //Find the VF inputs in Service properties, add or edit properties values
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(serviceReqDetails.getName());
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentPage.findSearchBoxAndClick(inputName1);
        PropertiesAssignmentPage.editPropertyValue(PropertyNameBuilder.buildSimpleField(inputName1), propertyValueUpd1);
        PropertiesAssignmentPage.clickOnSaveButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(inputName2);
        PropertiesAssignmentPage.editPropertyValue(PropertyNameBuilder.buildSimpleField(inputName2), propertyValueUpd2);
        PropertiesAssignmentPage.clickOnSaveButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(inputName3);
        PropertiesAssignmentPage.deletePropertyValue(PropertyNameBuilder.buildSimpleField(inputName3));
        PropertiesAssignmentPage.clickOnSaveButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(propertyNameProp4);
        PropertiesAssignmentPage.editPropertyValue(PropertyNameBuilder.buildSimpleField(propertyNameProp4), propertyValueUpd4);
        PropertiesAssignmentPage.clickOnSaveButton();

        //Checkout and check in VF, change VFi version on Service to 0.2
        AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
        AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
        AtomicOperationUtils.changeComponentInstanceVersion(service, componentInstance, resource, UserRoleEnum.DESIGNER, true);

        //Service - Validate properties values
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(serviceReqDetails.getName());
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildSimpleField(inputName1), propertyValueUpd1);
//        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildSimpleField(inputName2), propertyValueProp2);
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildSimpleField(inputName3), propertyValueProp3);
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildSimpleField(propertyNameProp4), propertyValueUpd4);

        //Service - Declare properties as inputs
        PropertiesAssignmentPage.findSearchBoxAndClick(inputName1);
        PropertiesAssignmentPage.clickOnDeclareButton();
//        PropertiesAssignmentPage.findSearchBoxAndClick(inputName2);
//        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(inputName3);
        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(propertyNameProp4);
        PropertiesAssignmentPage.clickOnDeclareButton();
        // TODO: 5/9/2018 Add validation for input values

        //VF - delete some declared inputs
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(resourceReqDetails.getName());
        GeneralPageElements.clickCheckoutButton();
        ResourceGeneralPage.getLeftMenu().moveToPropertiesAssignmentScreen();
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentPage.findInput(componentName, propertyNameProp1);
        PropertiesAssignmentPage.clickOnDeleteInputButton();
        PropertiesAssignmentPage.clickOnDeleteInputDialogConfirmationButton();
////        PropertiesAssignmentPage.findInput(componentName, propertyNameProp2);
//        PropertiesAssignmentPage.clickOnDeleteInputButton();
//        PropertiesAssignmentPage.clickOnDeleteInputDialogConfirmationButton();

        //VF - check in VF, change VFi version on Service to 0.3
        ResourceGeneralPage.clickCheckinButton(resourceReqDetails.getName());
        resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resource.getName(), "0.3");
        AtomicOperationUtils.changeComponentInstanceVersion(service, componentInstance, resource, UserRoleEnum.DESIGNER, true);

        //Service - Validate that deleted inputs are not found in Service properties, others are found
        CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
        GeneralUIUtils.findComponentAndClick(serviceReqDetails.getName());
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentPage.findProperty(inputName1);
        assertTrue(GeneralUIUtils.isElementInvisibleByTestId(PropertyNameBuilder.buildSimpleField(inputName1)));
//        PropertiesAssignmentPage.findProperty(inputName2);
//        assertTrue(GeneralUIUtils.isElementInvisibleByTestId(PropertyNameBuilder.buildSimpleField(inputName2)));
        PropertiesAssignmentPage.findProperty(inputName3);
        assertTrue(GeneralUIUtils.isElementVisibleByTestId(PropertyNameBuilder.buildSimpleField(inputName3)));
        PropertiesAssignmentPage.findProperty(propertyNameProp4);
        assertTrue(GeneralUIUtils.isElementVisibleByTestId(PropertyNameBuilder.buildSimpleField(propertyNameProp4)));

        //Service - Validate that Service inputs that were declared from deleted properties are not found
        //        - Validate that other inputs remain - Currently input of min_instances disappears - BUG 411833!!!
    }

    @Test
    public void updateVFCPropertyChangeVFCiVersionTest() throws Throwable {
        ResourceReqDetails atomicResourceMetaData;
        String prop1 = "network_role";
        String propValue1 = "added_value_1";
        String prop2 = "is_default";
        String propValue2 = "TRUE";

        //Import VFC, certify VFC
        String fileName = "importVFC_VFC23.yml";
        atomicResourceMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.ROOT,
                ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
        ResourceUIUtils.importVfc(atomicResourceMetaData, filePath, fileName, getUser());
        String vfcName = atomicResourceMetaData.getName();
        ResourceGeneralPage.clickCheckinButton(vfcName);

        //Create VF
        ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
        ResourceUIUtils.createVF(vfMetaData, getUser());

        //Add VFCi to VF canvas
        ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
        CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
        CanvasElement vfcElement = vfCanvasManager.createElementOnCanvas(vfcName);

        //VF Properties Assignment - edit properties values and declare as input
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentPage.findSearchBoxAndClick(prop1);
        PropertiesAssignmentPage.editPropertyValue(PropertyNameBuilder.buildSimpleField(prop1), propValue1);
        PropertiesAssignmentPage.clickOnSaveButton();
        PropertiesAssignmentPage.clickOnDeclareButton();
        PropertiesAssignmentPage.findSearchBoxAndClick(prop2);
        String propDefaultValue2 = PropertiesAssignmentPage.selectBooleanPropertyValue(PropertyNameBuilder.buildSimpleField(prop2), propValue2);
        PropertiesAssignmentPage.clickOnSaveButton();
        PropertiesAssignmentPage.clickOnDeclareButton();

        //Check out and check in VFC - v0.2
        HomePage.navigateToHomePage();
        GeneralUIUtils.findComponentAndClick(vfcName);
        ResourceGeneralPage.clickCheckoutButton();
        ResourceGeneralPage.clickCheckinButton(vfcName);

        //Change VFCi version in VF
        GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
        ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
        vfCanvasManager = CanvasManager.getCanvasManager();
        CompositionPage.changeComponentVersion(vfCanvasManager, vfcElement, "0.2");
        VfVerificator.verifyInstanceVersion(vfMetaData, getUser(), atomicResourceMetaData.getName(), "0.2");

        Resource resource = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, vfMetaData.getName(), "0.1");
        List<ComponentInstance> components = resource.getComponentInstances();
        String normalizedName = components.get(0).getNormalizedName();
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentPage.clickOnInputTab();
        //Verify that input value of the declared property that is EMPTY by default hasn't changed
//        PropertiesAssignmentVerificator.validateBooleanPropertyValue(PropertyNameBuilder.buildDeclaredInputField(normalizedName, prop2), propValue2);
        PropertiesAssignmentVerificator.validatePropertyValue(PropertyNameBuilder.buildDeclaredInputField(normalizedName, prop1), propValue1);
        //Verify that input value of the declared property that is NOT EMPTY by default has been changed
        PropertiesAssignmentVerificator.validateBooleanPropertyValue(PropertyNameBuilder.buildDeclaredInputField(normalizedName, prop2),
                StringUtils.isEmpty(propDefaultValue2) ? propValue2 : propDefaultValue2);

        //Check out VFC - v0.3, delete a property, check in VFC
        HomePage.navigateToHomePage();
        GeneralUIUtils.findComponentAndClick(vfcName);
        ResourceGeneralPage.clickCheckoutButton();
        ResourceGeneralPage.getLeftMenu().moveToPropertiesScreen();
        PropertiesPage.clickDeletePropertyFromPopup(prop1);
        PropertiesPage.clickDeletePropertyFromPopup(prop2);
        ResourceGeneralPage.clickCheckinButton(vfcName);

        //Change VFCi version in VF
        GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
        ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
        vfCanvasManager = CanvasManager.getCanvasManager();
        CompositionPage.changeComponentVersion(vfCanvasManager, vfcElement, "0.3");
        VfVerificator.verifyInstanceVersion(vfMetaData, getUser(), atomicResourceMetaData.getName(), "0.3");

        //Verify that properties and inputs were removed
        CompositionPage.moveToPropertiesScreen();
        PropertiesAssignmentPage.findProperty(prop1);
        assertTrue(GeneralUIUtils.isElementInvisibleByTestId(PropertyNameBuilder.buildSimpleField(prop1)));
        PropertiesAssignmentPage.findProperty(prop2);
        assertTrue(GeneralUIUtils.isElementInvisibleByTestId(PropertyNameBuilder.buildSimpleField(prop2)));
        PropertiesAssignmentPage.clickOnInputTab();
        PropertiesAssignmentPage.findProperty(normalizedName + "_" + prop1);
        assertTrue(GeneralUIUtils.isElementInvisibleByTestId(PropertyNameBuilder.buildDeclaredInputField(normalizedName, prop1)));
        PropertiesAssignmentPage.findProperty(normalizedName + "_" + prop2);
        assertTrue(GeneralUIUtils.isElementInvisibleByTestId(PropertyNameBuilder.buildDeclaredInputField(normalizedName, prop2)));
    }

    @Test
    public void updateHeatParamChangeVfiVersionTest() throws Throwable {
        String vnfFile = "vIRC_FE_BE.zip";
        String artifactName = "base_fe_be";
        String heatParamName = "availability_zone_0";
        String heatParamUpdValue = "Updated_ZoneA";

        //Import VSP, create VF - v0.1
        String filePath = FileHandling.getVnfRepositoryPath();
        getExtendTest().log(Status.INFO, "Going to upload VNF " + vnfFile);
        VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
        ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
        VendorSoftwareProductObject vendorSoftwareProductObject = VendorSoftwareProductRestUtils.createAndFillVendorSoftwareProduct(resourceReqDetails, vnfFile, filePath, sdncDesignerDetails,
            vendorLicenseModel, null);
        resourceReqDetails = OnboardingUtillViaApis.prepareOnboardedResourceDetailsBeforeCreate(resourceReqDetails, vendorSoftwareProductObject);
        Resource resource = OnboardingUtillViaApis.createResourceFromVSP(resourceReqDetails);

        //Check in VF and add VFi to Service
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
        ServiceReqDetails serviceReqDetails = OnboardingUtillViaApis.prepareServiceDetailsBeforeCreate(sdncDesignerDetails);
        getExtendTest().log(Status.INFO, "Create Service: " + serviceReqDetails.getName());
        org.openecomp.sdc.be.model.Service service = AtomicOperationUtils.createCustomService(
                serviceReqDetails,
                UserRoleEnum.DESIGNER, true
        ).left().value();
        CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
        GeneralUIUtils.findComponentAndClick(service.getName());
        ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
        CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
        CanvasElement vfElement = vfCanvasManager.createElementOnCanvas(resource.getName());

        //Select VFi on canvas, open Deployment Artifacts tab
        vfCanvasManager.clickOnCanvaElement(vfElement);
        CompositionPage.showDeploymentArtifactTab();
        DeploymentArtifactPage.hoverArtifact(artifactName);
        DeploymentArtifactPage.clickEditEnvArtifact(artifactName);
        DeploymentArtifactPage.editHeatParamValue(HeatParamNameBuilder.buildCurrentHeatParamValue(heatParamName), heatParamUpdValue);
        DeploymentArtifactPage.clickSaveEnvParameters();

        //Checkout and check in VF - v0.2
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();

        //Change VFi version on Service canvas - v0.2
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(service.getName());
        ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
        vfCanvasManager = CanvasManager.getCanvasManager();
        CompositionPage.changeComponentVersion(vfCanvasManager, vfElement, "0.2");
//        VfVerificator.verifyInstanceVersion(service, getUser(), resource.getName(), "0.2");

        //Validate that edited heatparam value is kept
        CompositionPage.showDeploymentArtifactTab();
        DeploymentArtifactPage.hoverArtifact(artifactName);
        DeploymentArtifactPage.clickEditEnvArtifact(artifactName);
        PropertiesAssignmentVerificator.validatePropertyValue(HeatParamNameBuilder.buildCurrentHeatParamValue(heatParamName), heatParamUpdValue);
        DeploymentArtifactPage.clickCloseEnvParameters();

        //Check out VF, delete heatparam value, check in VF - v0.3
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKOUT, true).getLeft();
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(resource.getName());
        ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
        DeploymentArtifactPage.clickEditEnvArtifact(artifactName);
        DeploymentArtifactPage.clickOnDeleteHeatParamValue(heatParamName);
        DeploymentArtifactPage.clickSaveEnvParameters();
        resource = (Resource) AtomicOperationUtils.changeComponentState(resource, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();

        //Change VFi version on Service canvas - v0.3
        GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
        GeneralUIUtils.findComponentAndClick(service.getName());
        ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
        vfCanvasManager = CanvasManager.getCanvasManager();
        CompositionPage.changeComponentVersion(vfCanvasManager, vfElement, "0.3");

        //Validate that edited heatparam value is kept, default value is empty
        CompositionPage.showDeploymentArtifactTab();
        DeploymentArtifactPage.hoverArtifact(artifactName);
        DeploymentArtifactPage.clickEditEnvArtifact(artifactName);
        PropertiesAssignmentVerificator.validatePropertyValue(HeatParamNameBuilder.buildCurrentHeatParamValue(heatParamName), heatParamUpdValue);
        PropertiesAssignmentVerificator.validatePropertyValueIsNull(HeatParamNameBuilder.buildDefaultHeatParamValue(heatParamName));
        DeploymentArtifactPage.clickCloseEnvParameters();
    }

}