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