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