[SDC-29] rebase continue work to align source
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / devCI / test1.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 java.util.Arrays;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.junit.Rule;
28 import org.junit.rules.TestName;
29 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
30 import org.openecomp.sdc.be.model.Component;
31 import org.openecomp.sdc.be.model.Resource;
32 import org.openecomp.sdc.be.model.Service;
33 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
34 import org.openecomp.sdc.ci.tests.config.Config;
35 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
36 import org.openecomp.sdc.ci.tests.datatypes.enums.DistributionNotificationStatusEnum;
37 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
39 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
40 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
41 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
42 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
43 import org.openecomp.sdc.ci.tests.utils.Utils;
44 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
45 import org.openecomp.sdc.ci.tests.utils.validation.DistributionValidationUtils;
46 import org.openecomp.sdc.externalApis.CRUDExternalAPI;
47 import org.testng.annotations.Test;
48
49 import fj.data.Either;
50
51 public class test1 extends ComponentBaseTest{
52
53         @Rule 
54         public static TestName name = new TestName();
55
56         public test1() {
57                 super(name, CRUDExternalAPI.class.getName());
58
59         }
60         
61         @Test()
62         public void uploadArtifactOnServiceViaExternalAPI() throws Exception {
63                 Config config = Utils.getConfig();      
64                 
65                 Service service = AtomicOperationUtils.createServiceByCategory(ServiceCategoriesEnum.MOBILITY, UserRoleEnum.DESIGNER, true).left().value();
66                 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.MODEL_QUERY_SPEC, service, UserRoleEnum.DESIGNER, true, true);
67                 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
68                 if(config.getIsDistributionClientRunning()){
69                         List<String> distributionStatusList = Arrays.asList(DistributionNotificationStatusEnum.DOWNLOAD_OK.toString(), DistributionNotificationStatusEnum.DEPLOY_OK.toString(), DistributionNotificationStatusEnum.NOTIFIED.toString());
70                         DistributionValidationUtils.validateDistributedArtifactsByAudit(service, distributionStatusList);
71                 }
72         }
73
74         
75         public static Map<String, String> addVNF_ModuleDeploymentArtifactToMap(Service service, Map<String, String> distributionArtifactMap){
76                 
77                 
78                 return distributionArtifactMap;
79         }
80         
81         public Component getComponentInTargetLifeCycleState(String componentType, UserRoleEnum creatorUser, LifeCycleStatesEnum targetLifeCycleState) throws Exception {
82                 Component component = null;
83                 
84                 if(componentType.toLowerCase().equals("vf")) {
85                         Either<Resource, RestResponse> createdResource = AtomicOperationUtils.createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VF, NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, creatorUser, true);
86                         component = createdResource.left().value();
87                         component = AtomicOperationUtils.changeComponentState(component, creatorUser, targetLifeCycleState, true).getLeft();
88                 } else {
89                         Either<Service, RestResponse> createdResource = AtomicOperationUtils.createDefaultService(creatorUser, true);
90                         component = createdResource.left().value();
91                         component = AtomicOperationUtils.changeComponentState(component, creatorUser, targetLifeCycleState, true).getLeft();
92                 }
93                 
94                 return component;
95         }
96 }