[SDC-29] rebase continue work to align source
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / execute / devCI / ValidateConformanceLevel.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.Assert.assertEquals;
24 import static org.testng.Assert.assertTrue;
25
26 import org.junit.Rule;
27 import org.junit.rules.TestName;
28 import org.openecomp.sdc.be.model.Component;
29 import org.openecomp.sdc.be.model.Service;
30 import org.openecomp.sdc.be.model.User;
31 import org.openecomp.sdc.be.utils.CommonBeUtils;
32 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
33 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
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.ComponentRestUtils;
41 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
42 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
43 import org.testng.annotations.AfterTest;
44 import org.testng.annotations.BeforeTest;
45 import org.testng.annotations.Test;
46
47 public class ValidateConformanceLevel extends ComponentBaseTest {
48
49         @Rule
50         public static TestName name = new TestName();
51
52         public ValidateConformanceLevel() {
53                 super(name, ValidateConformanceLevel.class.getName());
54         }
55
56         @Test
57         public void testValidateServiceConformanceLevel() throws Exception {
58                 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
59                 
60                 ServiceReqDetails service = ElementFactory.getDefaultService();
61                 RestResponse createdService = ServiceRestUtils.createService(service, user);
62                 BaseRestUtils.checkCreateResponse(createdService);
63                 Service serviceFirstImport = ResponseParser.parseToObjectUsingMapper(createdService.getResponse(), Service.class);
64                 Component serviceObject = AtomicOperationUtils.changeComponentState(serviceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
65                 
66                 RestResponse apiRes = ComponentRestUtils.validateConformanceLevel(serviceObject.getUUID(), user.getUserId());
67                 String result = apiRes.getResponse();
68                 assertTrue(apiRes.getErrorCode() == 200);
69                 assertTrue(result.equals("true"));
70         }
71         
72         @Test
73         public void testValidateServiceConformanceLevelForSecondMajorVersion() throws Exception {
74                 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
75                 
76                 ServiceReqDetails service = ElementFactory.getDefaultService();
77                 RestResponse createdService = ServiceRestUtils.createService(service, user);
78                 BaseRestUtils.checkCreateResponse(createdService);
79                 Service serviceFirstImport = ResponseParser.parseToObjectUsingMapper(createdService.getResponse(), Service.class);
80                 Component serviceObject = AtomicOperationUtils.changeComponentState(serviceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
81                 String uuid1 = serviceObject.getUUID();
82                 Component service20Object = AtomicOperationUtils.changeComponentState(serviceFirstImport, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CHECKIN, true).getLeft();
83                 service20Object = AtomicOperationUtils.changeComponentState(service20Object, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
84                 String uuid2 = service20Object.getUUID();
85                 
86                 assertTrue(uuid1 != uuid2);
87                 
88                 RestResponse apiRes = ComponentRestUtils.validateConformanceLevel(uuid1, user.getUserId());
89                 String result = apiRes.getResponse();
90                 assertTrue(apiRes.getErrorCode() == 200);
91                 assertTrue(result.equals("true"));
92                 
93                 apiRes = ComponentRestUtils.validateConformanceLevel(uuid2, user.getUserId());
94                 result = apiRes.getResponse();
95                 assertTrue(apiRes.getErrorCode() == 200);
96                 assertTrue(result.equals("true"));
97         }
98         
99         @Test
100         public void testValidateConformanceLevel404() throws Exception {
101                 User user = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
102                 RestResponse apiRes = ComponentRestUtils.validateConformanceLevel("fake-uuid-for-test", user.getUserId());
103                 assertTrue(apiRes.getErrorCode() == 404);
104         }
105 }