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;
24 import static org.testng.AssertJUnit.assertNull;
26 import java.io.FileNotFoundException;
28 import org.junit.Rule;
29 import org.junit.rules.TestName;
30 import org.openecomp.sdc.be.dao.api.ActionStatus;
31 import org.openecomp.sdc.be.model.LifecycleStateEnum;
32 import org.openecomp.sdc.be.model.Product;
33 import org.openecomp.sdc.be.model.User;
34 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
35 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedProductAudit;
36 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
37 import org.openecomp.sdc.ci.tests.utils.general.Convertor;
38 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
39 import org.openecomp.sdc.ci.tests.utils.rest.ProductRestUtils;
40 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
41 import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
42 import org.openecomp.sdc.ci.tests.utils.validation.ProductValidationUtils;
43 import org.openecomp.sdc.common.api.Constants;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.Test;
47 public class ProductUndoCheckoutTest extends ProductLifecycleTest {
50 public static TestName name = new TestName();
53 public static void staticInit() {
54 auditAction = UNDO_CHECKOUT_ACTION;
55 operation = ComponentOperationEnum.CHANGE_STATE_UNDO_CHECKOUT;
58 public ProductUndoCheckoutTest() {
59 super(name, ProductUndoCheckoutTest.class.getName());
63 public void undoCheckOutProductByPm() throws Exception {
64 undoCheckOutProductSuccess(productManager1, false);
68 public void undoCheckOutProductByAdmin() throws Exception {
69 undoCheckOutProductSuccess(adminUser, true);
73 public void undoCheckOutAfterCreate() throws Exception {
74 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
75 LifeCycleStatesEnum.UNDOCHECKOUT);
76 assertEquals("Check response code after undo checkout product", 200, lcsResponse.getErrorCode().intValue());
78 // Verify version was removed
79 lcsResponse = ProductRestUtils.getProduct(expectedProduct.getUniqueId(), productManager1.getUserId());
80 assertEquals("Check response code after get undone product", 404, lcsResponse.getErrorCode().intValue());
82 Product emptyProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
83 assertNull(emptyProduct);
84 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(emptyProduct,
85 auditAction, productManager1, ActionStatus.OK, "0.1", Constants.EMPTY_STRING,
86 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, null, Constants.EMPTY_STRING);
87 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
92 public void undoCheckOutNotExist() throws Exception {
93 String notExistId = "1234";
94 expectedProduct.setUniqueId(notExistId);
95 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
96 LifeCycleStatesEnum.UNDOCHECKOUT);
97 assertEquals("Check response code after undo checkout product", 404, lcsResponse.getErrorCode().intValue());
98 expectedProduct.setName(notExistId);
99 String[] auditParameters = new String[] { Constants.EMPTY_STRING };
100 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
101 auditAction, productManager1, ActionStatus.PRODUCT_NOT_FOUND, Constants.EMPTY_STRING,
102 Constants.EMPTY_STRING, null, null, Constants.EMPTY_STRING, auditParameters);
103 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
108 public void undoCheckOutNotInCheckout() throws Exception {
109 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
110 LifeCycleStatesEnum.CHECKIN);
111 assertEquals("Check response code after checkin product", 200, lcsResponse.getErrorCode().intValue());
113 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
114 LifeCycleStatesEnum.UNDOCHECKOUT);
115 assertEquals("Check response code after undo checkout product", 409, lcsResponse.getErrorCode().intValue());
117 String[] auditParameters = new String[] { expectedProduct.getName(), "product", productManager1.getFirstName(),
118 productManager1.getLastName(), productManager1.getUserId() };
120 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
121 auditAction, productManager1, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, "0.1", "0.1",
122 LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN,
123 expectedProduct.getUUID(), auditParameters);
124 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
129 public void undoCheckOutProductByPsRoleNotAllowed() throws Exception {
130 undoCheckOutProductRestricted(productStrategistUser1);
134 public void undoCheckOutProductByPmNotStateOwner() throws Exception {
135 undoCheckOutProductForbidden(productManager2);
138 private void undoCheckOutProductSuccess(User user, boolean isAdmin) throws Exception, FileNotFoundException {
139 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
140 LifeCycleStatesEnum.CHECKIN);
141 assertEquals("Check response code after checkin product", 200, lcsResponse.getErrorCode().intValue());
143 // Checking undo checkout of admin even if not state owner
144 User checkoutUser = isAdmin ? productManager1 : user;
146 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser,
147 LifeCycleStatesEnum.CHECKOUT);
148 assertEquals("Check response code after checkout product", 200, lcsResponse.getErrorCode().intValue());
149 Product productToBeUndone = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
151 lcsResponse = LifecycleRestUtils.changeProductState(productToBeUndone, user, LifeCycleStatesEnum.UNDOCHECKOUT);
152 assertEquals("Check response code after undo checkout product", 200, lcsResponse.getErrorCode().intValue());
154 // Verify version was removed
155 lcsResponse = ProductRestUtils.getProduct(productToBeUndone.getUniqueId(), user.getUserId());
156 assertEquals("Check response code after get undone product", 404, lcsResponse.getErrorCode().intValue());
158 lcsResponse = ProductRestUtils.getProduct(expectedProduct.getUniqueId(), user.getUserId());
159 assertEquals("Check response code after get latest version", 200, lcsResponse.getErrorCode().intValue());
161 Product latestProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
163 expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
164 ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, latestProduct, operation);
166 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(latestProduct,
167 auditAction, user, ActionStatus.OK, "0.2", "0.1", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
168 LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, latestProduct.getUUID());
169 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
172 private void undoCheckOutProductRestricted(User undoCheckoutUser) throws Exception, FileNotFoundException {
173 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
174 LifeCycleStatesEnum.CHECKIN);
175 assertEquals("Check response code after checkin product", 200, lcsResponse.getErrorCode().intValue());
177 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
178 LifeCycleStatesEnum.CHECKOUT);
179 assertEquals("Check response code after checkout product", 200, lcsResponse.getErrorCode().intValue());
180 Product productToBeUndone = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
182 lcsResponse = LifecycleRestUtils.changeProductState(productToBeUndone, undoCheckoutUser,
183 LifeCycleStatesEnum.UNDOCHECKOUT);
184 assertEquals("Check response code after undocheckout product", 409, lcsResponse.getErrorCode().intValue());
186 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(productToBeUndone,
187 auditAction, undoCheckoutUser, ActionStatus.RESTRICTED_OPERATION, "0.2", "0.2",
188 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
189 productToBeUndone.getUUID());
190 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
193 private void undoCheckOutProductForbidden(User undoCheckoutUser) throws Exception, FileNotFoundException {
194 RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
195 LifeCycleStatesEnum.CHECKIN);
196 assertEquals("Check response code after checkin product", 200, lcsResponse.getErrorCode().intValue());
198 lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
199 LifeCycleStatesEnum.CHECKOUT);
200 assertEquals("Check response code after checkout product", 200, lcsResponse.getErrorCode().intValue());
201 Product productToBeUndone = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class);
203 lcsResponse = LifecycleRestUtils.changeProductState(productToBeUndone, undoCheckoutUser,
204 LifeCycleStatesEnum.UNDOCHECKOUT);
205 assertEquals("Check response code after undocheckout product", 403, lcsResponse.getErrorCode().intValue());
206 String[] auditParameters = new String[] { productToBeUndone.getName(), "product",
207 productManager1.getFirstName(), productManager1.getLastName(), productManager1.getUserId() };
209 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
210 auditAction, undoCheckoutUser, ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, "0.2", "0.2",
211 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
212 productToBeUndone.getUUID(), auditParameters);
213 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);