[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci-dev / src / main / java / org / openecomp / sdc / uici / tests / utilities / ArtifactUIUtils.java
1 package org.openecomp.sdc.uici.tests.utilities;
2
3 import static org.openecomp.sdc.common.datastructure.FunctionalInterfaces.retryMethodOnException;
4
5 import java.util.Map;
6
7 import org.json.simple.JSONObject;
8 import org.json.simple.JSONValue;
9 import org.openecomp.sdc.uici.tests.datatypes.CreateAndUpdateStepsEnum;
10 import org.openecomp.sdc.uici.tests.datatypes.DataTestIdEnum;
11 import org.openecomp.sdc.uici.tests.datatypes.DataTestIdEnum.Artifatcs;
12 import org.openecomp.sdc.uici.tests.datatypes.DataTestIdEnum.InformationalArtifatcs;
13 import org.openqa.selenium.WebElement;
14
15 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
16 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
17 import org.openecomp.sdc.common.datastructure.FunctionalInterfaces;
18
19 public final class ArtifactUIUtils {
20
21         private ArtifactUIUtils() {
22                 throw new UnsupportedOperationException();
23         }
24
25         public static void addInformationArtifact(ArtifactReqDetails artifact, String filePath,
26                         final InformationalArtifatcs dataTestEnum) {
27                 GeneralUIUtils.waitForLoader();
28                 GeneralUIUtils.sleep(2000);
29                 GeneralUIUtils.getWebElementWaitForVisible(dataTestEnum.getValue()).click();
30
31                 final WebElement browseWebElement = FunctionalInterfaces.retryMethodOnException(
32                                 () -> GeneralUIUtils.getWebElementWaitForVisible(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue()));
33                 browseWebElement.sendKeys(filePath);
34
35                 GeneralUIUtils.getWebElementWaitForVisible(DataTestIdEnum.ModalItems.DESCRIPTION.getValue())
36                                 .sendKeys(artifact.getDescription());
37                 GeneralUIUtils.getWebElementWaitForVisible(DataTestIdEnum.ModalItems.DONE.getValue()).click();
38
39         }
40
41         public static Map<String, Map<String, Object>> getArtifactsListFromResponse(String jsonResponse,
42                         String fieldOfArtifactList) {
43                 JSONObject object = (JSONObject) JSONValue.parse(jsonResponse);
44                 Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) object.get(fieldOfArtifactList);
45                 return map;
46         }
47
48         /**
49          * Creates a deployment artifact on the vf. <br>
50          * Moves automatically to DeploymentArtifact Section
51          * 
52          * @param artifactPayloadPath
53          * @param artifactType
54          */
55         public static void createDeploymentArtifactOnVf(final String artifactPayloadPath,
56                         final ArtifactTypeEnum artifactType) {
57                 GeneralUIUtils.moveToStep(CreateAndUpdateStepsEnum.DEPLOYMENT_ARTIFACT);
58                 GeneralUIUtils.getWebElementWaitForClickable(Artifatcs.ADD_DEPLOYMENT_ARTIFACT.getValue()).click();
59                 GeneralUIUtils.getSelectList("Create New Artifact", Artifatcs.SELECT_ARTIFACT_DROPDOWN.getValue());
60                 GeneralUIUtils.getSelectList(artifactType.getType(), Artifatcs.ARTIFACT_TYPE_DROPDOWN.getValue());
61                 GeneralUIUtils.getWebElementWaitForVisible(Artifatcs.ARTIFACT_DESCRIPTION.getValue())
62                                 .sendKeys("Artifact Description");
63                 GeneralUIUtils.getWebElementWaitForVisible(Artifatcs.ARTIFACT_LABEL.getValue()).sendKeys("MyArtifactLabel");
64                 retryMethodOnException(() -> GeneralUIUtils.getWebElementByDataTestId(Artifatcs.BROWSE_BUTTON.getValue())
65                                 .sendKeys(artifactPayloadPath));
66                 GeneralUIUtils.getWebElementWaitForVisible(Artifatcs.ADD_BUTTON.getValue()).click();
67                 GeneralUIUtils.waitForLoader();
68         }
69
70 }