[SDC-31] add mising script got Comformance fix
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / product / ProductCheckoutTest.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.product;
22
23 import static org.testng.AssertJUnit.assertEquals;
24
25 import java.io.FileNotFoundException;
26
27 import org.junit.Rule;
28 import org.junit.rules.TestName;
29 import org.openecomp.sdc.be.dao.api.ActionStatus;
30 import org.openecomp.sdc.be.model.LifecycleStateEnum;
31 import org.openecomp.sdc.be.model.Product;
32 import org.openecomp.sdc.be.model.User;
33 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedProductAudit;
35 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
36 import org.openecomp.sdc.ci.tests.utils.DbUtils;
37 import org.openecomp.sdc.ci.tests.utils.Utils;
38 import org.openecomp.sdc.ci.tests.utils.general.Convertor;
39 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
40 import org.openecomp.sdc.ci.tests.utils.rest.ProductRestUtils;
41 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
42 import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
43 import org.openecomp.sdc.ci.tests.utils.validation.ProductValidationUtils;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.Test;
46
47 public class ProductCheckoutTest extends ProductLifecycleTest {
48
49         @Rule
50         public static TestName name = new TestName();
51
52         @BeforeClass
53         public static void staticInit() {
54                 auditAction = CHECKOUT_ACTION;
55                 operation = ComponentOperationEnum.CHANGE_STATE_CHECKOUT;
56         }
57
58         public ProductCheckoutTest() {
59                 super(name, ProductCheckoutTest.class.getName());
60         }
61
62         @Test
63         public void checkOutProductByPmNotInContacts() throws Exception {
64                 checkOutProductSuccess(productManager2);
65         }
66
67         @Test
68         public void checkOutProductByPmInContacts() throws Exception {
69                 checkOutProductSuccess(productManager1);
70         }
71
72         @Test
73         public void checkOutProductByAdmin() throws Exception {
74                 checkOutProductSuccess(adminUser);
75         }
76
77         @Test
78         public void checkOutProductByPs() throws Exception {
79                 // Changed in 1604 patch - now it's restricted
80                 checkOutProductRestricted(productStrategistUser3);
81                 // checkOutProductSuccess(productStrategistUser3);
82         }
83
84         @Test
85         public void checkOutProductByDesignerRoleNotAllowed() throws Exception {
86                 checkOutProductRestricted(designerUser);
87         }
88
89         @Test
90         public void checkOutProductAlreadyCheckedOut() throws Exception {
91                 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN);
92                 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
93
94                 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKOUT);
95                 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
96                 Product checkedOutProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
97
98                 DbUtils.cleanAllAudits();
99
100                 lcsResponse = LifecycleRestUtils.changeProductState(checkedOutProduct, productManager2, LifeCycleStatesEnum.CHECKOUT);
101                 assertEquals("Check response code after checkin resource", 403, lcsResponse.getErrorCode().intValue());
102                 String[] auditParameters = new String[] { checkedOutProduct.getName(), "product", productManager1.getFirstName(), productManager1.getLastName(), productManager1.getUserId() };
103
104                 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedOutProduct, auditAction, productManager2, ActionStatus.COMPONENT_IN_CHECKOUT_STATE, "0.2", "0.2", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
105                                 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, checkedOutProduct.getUUID(), auditParameters);
106                 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
107         }
108
109         private void checkOutProductSuccess(User checkoutUser) throws Exception, FileNotFoundException {
110                 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN);
111                 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
112
113                 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT);
114                 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
115
116                 // 0.1 is not highest now
117                 RestResponse prevVersionProductResp = ProductRestUtils.getProduct(expectedProduct.getUniqueId(), productStrategistUser1.getUserId());
118                 Product prevVersionProduct = ResponseParser.parseToObjectUsingMapper(prevVersionProductResp.getResponse(), Product.class);
119                 Boolean falseParam = false;
120                 assertEquals(falseParam, prevVersionProduct.isHighestVersion());
121
122                 Product checkedOutProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
123
124                 expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
125                 expectedProduct.setVersion("0.2");
126                 expectedProduct.setLastUpdaterUserId(checkoutUser.getUserId());
127                 expectedProduct.setLastUpdaterFullName(checkoutUser.getFullName());
128                 ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedOutProduct, operation);
129
130                 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedOutProduct, auditAction, checkoutUser, ActionStatus.OK, "0.1", "0.2", LifecycleStateEnum.NOT_CERTIFIED_CHECKIN,
131                                 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, checkedOutProduct.getUUID());
132                 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
133         }
134
135         private void checkOutProductRestricted(User checkoutUser) throws Exception, FileNotFoundException {
136                 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN);
137                 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
138
139                 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT);
140                 assertEquals("Check response code after checkin resource", 409, lcsResponse.getErrorCode().intValue());
141
142                 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct, auditAction, checkoutUser, ActionStatus.RESTRICTED_OPERATION, "0.1", "0.1", LifecycleStateEnum.NOT_CERTIFIED_CHECKIN,
143                                 LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, expectedProduct.getUUID());
144                 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
145         }
146
147 }