[SDC-29] rebase continue work to align source
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / devCI / ImportCsarValidateArtifacts.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.devCI;
22
23 import static org.testng.AssertJUnit.assertTrue;
24
25 import org.junit.Rule;
26 import org.junit.rules.TestName;
27 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
28 import org.openecomp.sdc.be.model.Component;
29 import org.openecomp.sdc.be.model.Resource;
30 import org.openecomp.sdc.be.model.Service;
31 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
32 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
33 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
35 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
36 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
37 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
38 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
39 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
40 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
41 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
42 import org.openecomp.sdc.ci.tests.utils.validation.CsarValidationUtils;
43 import org.testng.annotations.DataProvider;
44 import org.testng.annotations.Test;
45
46 public class ImportCsarValidateArtifacts extends ComponentBaseTest {
47
48         @Rule
49         public static TestName name = new TestName();
50
51         public ImportCsarValidateArtifacts() {
52                 super(name, ImportCsarValidateArtifacts.class.getName());
53         }
54
55         @DataProvider(name = "happyArts")
56         public Object[][] getHappyArtifacts() {
57
58                 return new Object[][] { { "happy_VF_RI2_G2_two_different_artifacts_under_heatBaseheatVolheatNet2" },
59                                 { "happy_VF_RI2_G2_two_different_artifacts_under_heatBaseheatVolheatNet" },
60                                 { "happy_VF_RI2_G2_two_identical_artifacts_under_heatBaseheatVolheatNet" },
61                                 { "happy_VF_RI2_G2_two_different_artifacts_under_nested" },
62                                 { "happy_VF_RI2_G2_two_indentical_nested_under_different_groups" },
63                                 { "happy_VF_RI2_G2_two_different_nested_under_different_groups" },
64                                 { "happy_VF_RI2_G2_two_different_nested_under_same_group" },
65
66                 };
67         }
68
69         @DataProvider(name = "negativeArts")
70         public Object[][] getNegativeArtifacts() {
71
72                 return new Object[][] {
73
74                                 { "negative_VF_RI2_G2_same_heatVol_different_groups" },
75                                 { "negative_VF_RI2_G2_same_heatBase_different_envs" },
76                                 { "negative_VF_RI2_G2_heatBaseHeatVolHeatNet_under_nested" },
77                                 { "negative_VF_RI2_G2_two_indentical_artifacts_under_nested" },
78                                 { "negative_VF_RI2_G2_nested_under_nested" }, { "negative_VF_RI2_G2_same_heatVol_different_groups" }, };
79         }
80
81         @Test(dataProvider = "happyArts")
82         public void createResourceFromCsarArtsHappy(String artifactName) throws Exception {
83
84                 ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
85                 resourceDetails.setCsarUUID(artifactName);
86                 resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
87                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails,
88                                 ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
89
90                 BaseRestUtils.checkCreateResponse(createResource);
91                 Resource resource = ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
92                 CsarValidationUtils.validateCsarVfArtifact(artifactName, resource);
93
94         }
95
96         @Test(dataProvider = "negativeArts")
97         public void createResourceFromCsarArtsNegative(String artifactName) throws Exception {
98
99                 ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
100                 resourceDetails.setCsarUUID(artifactName);
101                 resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
102                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails,
103                                 ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
104                 assertTrue(createResource.getErrorCode() != 201 && createResource.getErrorCode() != 500);
105
106         }
107
108 }