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 org.junit.Rule;
24 import org.junit.rules.TestName;
25 import org.openecomp.sdc.be.dao.api.ActionStatus;
26 import org.openecomp.sdc.be.model.LifecycleStateEnum;
27 import org.openecomp.sdc.be.model.Product;
28 import org.openecomp.sdc.be.model.User;
29 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedProductAudit;
31 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
32 import org.openecomp.sdc.ci.tests.utils.DbUtils;
33 import org.openecomp.sdc.ci.tests.utils.general.Convertor;
34 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
35 import org.openecomp.sdc.ci.tests.utils.rest.ProductRestUtils;
36 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
37 import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
38 import org.openecomp.sdc.ci.tests.utils.validation.ProductValidationUtils;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.Test;
42 import java.io.FileNotFoundException;
44 import static org.testng.AssertJUnit.assertEquals;
46 public class ProductCheckoutTest extends ProductLifecycleTest {
49 public static TestName name = new TestName();
52 public static void staticInit() {
53 auditAction = CHECKOUT_ACTION;
54 operation = ComponentOperationEnum.CHANGE_STATE_CHECKOUT;
57 public ProductCheckoutTest() {
58 super(name, ProductCheckoutTest.class.getName());
62 public void checkOutProductByPmNotInContacts() throws Exception {
63 checkOutProductSuccess(productManager2);
67 public void checkOutProductByPmInContacts() throws Exception {
68 checkOutProductSuccess(productManager1);
72 public void checkOutProductByAdmin() throws Exception {
73 checkOutProductSuccess(adminUser);
77 public void checkOutProductByPs() throws Exception {
78 // Changed in 1604 patch - now it's restricted
79 checkOutProductRestricted(productStrategistUser3);
80 // checkOutProductSuccess(productStrategistUser3);
84 public void checkOutProductByDesignerRoleNotAllowed() throws Exception {
85 checkOutProductRestricted(designerUser);
89 public void checkOutProductAlreadyCheckedOut() throws Exception {
90 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN);
91 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
93 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKOUT);
94 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
95 Product checkedOutProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
97 DbUtils.cleanAllAudits();
99 lcsResponse = LifecycleRestUtils.changeProductState(checkedOutProduct, productManager2, LifeCycleStatesEnum.CHECKOUT);
100 assertEquals("Check response code after checkin resource", 403, lcsResponse.getErrorCode().intValue());
101 String[] auditParameters = new String[] { checkedOutProduct.getName(), "product", productManager1.getFirstName(), productManager1.getLastName(), productManager1.getUserId() };
103 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedOutProduct, auditAction, productManager2, ActionStatus.COMPONENT_IN_CHECKOUT_STATE, "0.2", "0.2", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
104 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, checkedOutProduct.getUUID(), auditParameters);
105 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
108 private void checkOutProductSuccess(User checkoutUser) throws Exception, FileNotFoundException {
109 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN);
110 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
112 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT);
113 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
115 // 0.1 is not highest now
116 RestResponse prevVersionProductResp = ProductRestUtils.getProduct(expectedProduct.getUniqueId(), productStrategistUser1.getUserId());
117 Product prevVersionProduct = ResponseParser.parseToObjectUsingMapper(prevVersionProductResp.getResponse(), Product.class);
118 Boolean falseParam = false;
119 assertEquals(falseParam, prevVersionProduct.isHighestVersion());
121 Product checkedOutProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
123 expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
124 expectedProduct.setVersion("0.2");
125 expectedProduct.setLastUpdaterUserId(checkoutUser.getUserId());
126 expectedProduct.setLastUpdaterFullName(checkoutUser.getFullName());
127 ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedOutProduct, operation);
129 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedOutProduct, auditAction, checkoutUser, ActionStatus.OK, "0.1", "0.2", LifecycleStateEnum.NOT_CERTIFIED_CHECKIN,
130 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, checkedOutProduct.getUUID());
131 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
134 private void checkOutProductRestricted(User checkoutUser) throws Exception, FileNotFoundException {
135 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN);
136 assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue());
138 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT);
139 assertEquals("Check response code after checkin resource", 409, lcsResponse.getErrorCode().intValue());
141 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct, auditAction, checkoutUser, ActionStatus.RESTRICTED_OPERATION, "0.1", "0.1", LifecycleStateEnum.NOT_CERTIFIED_CHECKIN,
142 LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, expectedProduct.getUUID());
143 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);