Added oparent to sdc main
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / Annotation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.sanity;
22
23 import com.aventstack.extentreports.Status;
24 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
25 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.ToscaArtifactsScreenEnum;
26 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
27 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
28 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
29 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
30 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
31 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
32 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
33 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
34 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
35 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
36 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
37 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
38 import org.testng.annotations.BeforeMethod;
39 import org.testng.annotations.Test;
40
41 import java.io.File;
42
43 import static org.assertj.core.api.Assertions.assertThat;
44
45 public class Annotation extends SetupCDTest {
46         private String filePath;
47
48         @BeforeMethod
49         public void beforeTest() {
50                 filePath = FileHandling.getFilePath("SRIOV");
51         }
52
53         @Test
54         public void importCsarWithAnnotationVerifyDownloadYmlContainsAnnotationSection() throws Exception {
55                 String fileName = "SIROV_annotations_VSP.csar";
56                 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VF,
57                                 NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, getUser());
58                 ResourceUIUtils.importVfFromCsar(vfMetaData, filePath, fileName, getUser());
59                 getExtendTest().log(Status.INFO, "Csar with annotations imported successfully.");
60                 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
61                 GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_MODEL.getValue());
62                 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
63                 ToscaDefinition toscaMainVfDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(latestFilefromDir);
64                 assertTrueAnnotationTestSuite(toscaMainVfDefinition);
65                 getExtendTest().log(Status.INFO, "Success to validate the ToscaMainYaml contains annotation type source with properties.");
66         }
67
68         
69         public void assertTrueAnnotationTestSuite(ToscaDefinition toscaMainVfDefinition) {
70                 assertThat(toscaMainVfDefinition.getTopology_template().getInputs().get("availabilityzone_name").annotations).containsKey("source");
71                 assertThat(toscaMainVfDefinition.getTopology_template().getInputs().get("availabilityzone_name").getAnnotations().get("source").getType()).isEqualTo("org.openecomp.annotations.Source");
72                 assertThat(toscaMainVfDefinition.getTopology_template().getInputs().get("availabilityzone_name").getAnnotations().get("source").getProperties().get("source_type")).isEqualTo("HEAT");
73         }
74         
75         @Override
76         protected UserRoleEnum getRole() {
77                 return UserRoleEnum.DESIGNER;
78         }
79
80 }