aboutsummaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/US/MIBsArtifactsOnResourceInstance.java
blob: 59c18fe31128645bbb0f24a6210a7911458cf22c (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
/*-
 * ============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.openecomp.sdc.ci.tests.US;

import org.apache.commons.io.FileUtils;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.ci.tests.datatypes.ArtifactInfo;
import org.openecomp.sdc.ci.tests.datatypes.CanvasElement;
import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
import org.openecomp.sdc.ci.tests.pages.CompositionPage;
import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
import org.openecomp.sdc.ci.tests.pages.UploadArtifactPopup;
import org.openecomp.sdc.ci.tests.utilities.ArtifactUIUtils;
import org.openecomp.sdc.ci.tests.utilities.FileHandling;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static org.testng.AssertJUnit.assertTrue;


public class MIBsArtifactsOnResourceInstance extends SetupCDTest {

    private String folder = "";

    @DataProvider(name = "mibsArtifactCRUDUi")
    public static Object[][] dataProviderMibsArtifactCRUDUi() {
        return new Object[][]{
                {"mibsvFW_VFC.yml", ResourceTypeEnum.VFC},
                {"mibsVL.yml", ResourceTypeEnum.VL},
                {"mibsCP.yml", ResourceTypeEnum.CP}
        };
    }

    // US820414
    // Artifact UI CRUD on VFC/VL/CP
    // TODO: Change download validation from download artifact via external API to UI
    @Test(dataProvider = "mibsArtifactCRUDUi")
    public void mibsArtifactCRUDUi(String fileName, ResourceTypeEnum resourceTypeEnum) throws Exception {
        setLog(fileName);
        String filePath = FileHandling.getFilePath(folder);

        // import Resource
        ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
        ResourceUIUtils.importVfc(resourceMetaData, filePath, fileName, getUser());

        // get resourceUUID from BE
        String resourceUUID = AtomicOperationUtils.getResourceObjectByNameAndVersion(UserRoleEnum.DESIGNER, resourceMetaData.getName(), "0.1").getUUID();

        // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
        ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();

        List<ArtifactInfo> deploymentArtifactList = new ArrayList<>();
        deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
        deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
        for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
            DeploymentArtifactPage.clickAddNewArtifact();
            ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));

            assertTrue("Only created artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(1));

            String artifactUUID = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText();
            ArtifactUIUtils.validateExistArtifactOnDeploymentInformationPage(deploymentArtifact.getArtifactLabel(), null, "1", deploymentArtifact.getArtifactType(), true, true, true, false);

            // Verify that uploaded correct file by download artifact via external api
            RestResponse restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), ComponentTypeEnum.RESOURCE.toString());
            File file = new File(deploymentArtifact.getFilepath() + deploymentArtifact.getFilename());

            String readFileToString = FileUtils.readFileToString(file);
            Assert.assertEquals(restResponse.getResponse(), readFileToString);

            DeploymentArtifactPage.clickEditArtifact(deploymentArtifact.getArtifactLabel());
            UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
            artifactPopup.loadFile(filePath, "CP.yml");
            artifactPopup.clickDoneButton();

            assertTrue("Only updated artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(1));
            Assert.assertNotEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText(), artifactUUID);
            ArtifactUIUtils.validateExistArtifactOnDeploymentInformationPage(deploymentArtifact.getArtifactLabel(), null, "2", deploymentArtifact.getArtifactType(), true, true, true, false);

            // Verify that updated correct file by download artifact via external api
            artifactUUID = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + deploymentArtifact.getArtifactLabel()).getText();
            restResponse = ArtifactRestUtils.getResourceDeploymentArtifactExternalAPI(resourceUUID, artifactUUID, ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER), ComponentTypeEnum.RESOURCE.toString());
            file = new File(deploymentArtifact.getFilepath() + "CP.yml");
            readFileToString = FileUtils.readFileToString(file);
            Assert.assertEquals(restResponse.getResponse(), readFileToString);

            DeploymentArtifactPage.clickDeleteArtifact(deploymentArtifact.getArtifactLabel());
            DeploymentArtifactPage.clickOK();

            assertTrue("No artifact need to be exist", DeploymentArtifactPage.checkElementsCountInTable(0));
        }

    }

    @DataProvider(name = "mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption")
    public static Object[][] dataProviderMibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption() {
        return new Object[][]{
//			{"mibs1vFW_VFC.yml", ResourceTypeEnum.VFC},
                // TODO: delete comment below when we will have support for VL on canvas
//			{"mibs1VL.yml", ResourceTypeEnum.VL},
                {"mibs1CP.yml", ResourceTypeEnum.CP}
        };
    }

    // US820414
    // Import VFC/VL/CP, upload MIBs artifacts then drag it on VF & verify that deployment artifact have only download option
    @Test(dataProvider = "mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption")
    public void mibsArtifacsOnResourceInstanceShouldOnlyHaveDownloadOption(String fileName, ResourceTypeEnum resourceTypeEnum) throws Exception {

//		if(resourceTypeEnum.equals(ResourceTypeEnum.CP)){
//			throw new SkipException("Open bug 322930");			
//		}

        setLog(fileName);

        String filePath = FileHandling.getFilePath(folder);

        // import Resource
        ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
        ResourceUIUtils.importVfc(resourceMetaData, filePath, fileName, getUser());

        // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
        ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();

        List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
        deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
        deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
        for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
            DeploymentArtifactPage.clickAddNewArtifact();
            ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));
        }
        assertTrue("artifact table does not contain artifacts uploaded", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size()));

        // 3. Check-in DataProvider resource.
        ResourceGeneralPage.clickCheckinButton(resourceMetaData.getName());

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

        // 5. Click on composition.
        ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();

        // 6. Drag created DataProvider resource to canvas.
        CanvasManager vfCanvasManager = CanvasManager.getCanvasManager();
        CompositionPage.searchForElement(resourceMetaData.getName());
        CanvasElement resourceInstance = vfCanvasManager.createElementOnCanvas(resourceMetaData.getName());

        // 7. Click on DataProvider resource.
        vfCanvasManager.clickOnCanvaElement(resourceInstance);

        // 8. Click on deployment artifacts in right menu.
        CompositionPage.showDeploymentArtifactTab();

        // 9. Verify that each uploaded MIBs artifacts shows in deployment artifacts.
        // 10. Verify that only have download option.
        for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
            // Hover over webelement -> check that only dowload button displayed
            GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
            Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + deploymentArtifact.getArtifactLabel()).isDisplayed(), true);
            Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + deploymentArtifact.getArtifactLabel()), false);
            GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
            Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), false);
        }


    }

    // US820414
    // Create VF, upload MIBs artifacts then drag it on service & verify that deployment artifact have only download option
    @Test
    public void mibsArtifacsOnVFInstanceShouldOnlyHaveDownloadOption() throws Exception {
        String filePath = FileHandling.getFilePath(folder);

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

        // 2. Upload MIBs artifacts - SNMP_TRAP & SNMP_POLL.
        ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();

        List<ArtifactInfo> deploymentArtifactList = new ArrayList<ArtifactInfo>();
        deploymentArtifactList.add(new ArtifactInfo(filePath, "asc_heat 0 2.yaml", "kuku", "artifact1", "SNMP_TRAP"));
        deploymentArtifactList.add(new ArtifactInfo(filePath, "sample-xml-alldata-1-1.xml", "cuku", "artifact2", "SNMP_POLL"));
        for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
            DeploymentArtifactPage.clickAddNewArtifact();
            ArtifactUIUtils.fillAndAddNewArtifactParameters(deploymentArtifact, new UploadArtifactPopup(true));
        }
        assertTrue("artifact table does not contain artifacts uploaded", DeploymentArtifactPage.checkElementsCountInTable(deploymentArtifactList.size()));

        // 3. Check-in VF.
        ResourceGeneralPage.clickCheckinButton(resourceMetaData.getName());

        // 4. Create service.
        ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
        ServiceUIUtils.createService(serviceMetadata);

        // 5. Click on composition.
        ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();

        // 6. Drag created DataProvider s to canvas.
        CanvasManager canvasManager = CanvasManager.getCanvasManager();
        CompositionPage.searchForElement(resourceMetaData.getName());
        CanvasElement resourceInstance = canvasManager.createElementOnCanvas(resourceMetaData.getName());

        // 7. Click on DataProvider resource.
        canvasManager.clickOnCanvaElement(resourceInstance);

        // 8. Click on deployment artifacts in right menu.
        CompositionPage.showDeploymentArtifactTab();

        // 9. Verify that each uploaded MIBs artifacts shows in deployment artifacts.
        // 10. Verify that only have download option.
        for (ArtifactInfo deploymentArtifact : deploymentArtifactList) {
            // Hover over webelement -> check that only dowload button displayed
            GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
            Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + deploymentArtifact.getArtifactLabel()).isDisplayed(), true);
            Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + deploymentArtifact.getArtifactLabel()), false);
            GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + deploymentArtifact.getArtifactLabel());
            Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), false);
        }
    }


    @Override
    protected UserRoleEnum getRole() {
        return UserRoleEnum.DESIGNER;
    }

}