2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.execute.product;
23 import static org.testng.AssertJUnit.assertEquals;
25 import java.io.FileNotFoundException;
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;
47 public class ProductCheckoutTest extends ProductLifecycleTest {
50 public static TestName name = new TestName();
53 public static void staticInit() {
54 auditAction = CHECKOUT_ACTION;
55 operation = ComponentOperationEnum.CHANGE_STATE_CHECKOUT;
58 public ProductCheckoutTest() {
59 super(name, ProductCheckoutTest.class.getName());
63 public void checkOutProductByPmNotInContacts() throws Exception {
64 checkOutProductSuccess(productManager2);
68 public void checkOutProductByPmInContacts() throws Exception {
69 checkOutProductSuccess(productManager1);
73 public void checkOutProductByAdmin() throws Exception {
74 checkOutProductSuccess(adminUser);
78 public void checkOutProductByPs() throws Exception {
79 // Changed in 1604 patch - now it's restricted
80 checkOutProductRestricted(productStrategistUser3);
81 // checkOutProductSuccess(productStrategistUser3);
85 public void checkOutProductByDesignerRoleNotAllowed() throws Exception {
86 checkOutProductRestricted(designerUser);
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());
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);
98 DbUtils.cleanAllAudits();
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() };
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);
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());
113 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT);
114 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
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());
122 Product checkedOutProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
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);
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);
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());
139 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT);
140 assertEquals("Check response code after checkin resource", 409, lcsResponse.getErrorCode().intValue());
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);