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 org.junit.Rule;
26 import org.junit.rules.TestName;
27 import org.openecomp.sdc.be.dao.api.ActionStatus;
28 import org.openecomp.sdc.be.model.LifecycleStateEnum;
29 import org.openecomp.sdc.be.model.Product;
30 import org.openecomp.sdc.be.model.User;
31 import org.openecomp.sdc.ci.tests.datatypes.enums.AuditJsonKeysEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedProductAudit;
34 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
35 import org.openecomp.sdc.ci.tests.utils.DbUtils;
36 import org.openecomp.sdc.ci.tests.utils.general.Convertor;
37 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
38 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
39 import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
40 import org.openecomp.sdc.ci.tests.utils.validation.ProductValidationUtils;
41 import org.openecomp.sdc.common.api.Constants;
42 import org.testng.annotations.BeforeClass;
43 import org.testng.annotations.Test;
45 public class ProductCheckinTest extends ProductLifecycleTest {
48 public static TestName name = new TestName();
50 public ProductCheckinTest() {
51 super(name, ProductCheckinTest.class.getName());
55 public static void staticInit() {
56 auditAction = CHECKIN_ACTION;
57 operation = ComponentOperationEnum.CHANGE_STATE_CHECKIN;
61 public void checkInProductByCreator() throws Exception {
63 String checkinComment = "good checkin";
64 RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
65 LifeCycleStatesEnum.CHECKIN, checkinComment);
66 assertEquals("Check response code after checkin resource", 200, checkInResponse.getErrorCode().intValue());
67 Product checkedInProduct = ResponseParser.parseToObjectUsingMapper(checkInResponse.getResponse(),
70 expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
71 ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedInProduct, operation);
73 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedInProduct,
74 auditAction, productManager1, ActionStatus.OK, "0.1", "0.1", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
75 LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, checkedInProduct.getUUID());
76 expectedProductAudit.setCOMMENT(checkinComment);
77 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction, AuditJsonKeysEnum.COMMENT);
81 public void checkInProductByPM() throws Exception {
83 String checkinComment = "good checkin";
84 RestResponse response = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
85 LifeCycleStatesEnum.CHECKIN, checkinComment);
86 assertEquals("Check response code after checkin resource", 200, response.getErrorCode().intValue());
88 User checkoutUser = productManager2;
89 response = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT);
90 assertEquals("Check response code after checkin resource", 200, response.getErrorCode().intValue());
91 expectedProduct = ResponseParser.parseToObjectUsingMapper(response.getResponse(), Product.class);
93 DbUtils.cleanAllAudits();
94 checkinComment = "good checkin no 2";
95 response = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKIN,
97 assertEquals("Check response code after checkin resource", 200, response.getErrorCode().intValue());
99 Product checkedInProduct = ResponseParser.parseToObjectUsingMapper(response.getResponse(), Product.class);
101 expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
102 expectedProduct.setVersion("0.2");
103 expectedProduct.setLastUpdaterUserId(checkoutUser.getUserId());
104 expectedProduct.setLastUpdaterFullName(checkoutUser.getFullName());
106 ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedInProduct, operation);
108 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedInProduct,
109 auditAction, checkoutUser, ActionStatus.OK, "0.2", "0.2", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
110 LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, checkedInProduct.getUUID());
111 expectedProductAudit.setCOMMENT(checkinComment);
112 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction, AuditJsonKeysEnum.COMMENT);
116 public void checkInProductByAdmin() throws Exception {
118 String checkinComment = "good checkin";
119 RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, adminUser,
120 LifeCycleStatesEnum.CHECKIN, checkinComment);
121 assertEquals("Check response code after checkin resource", 200, checkInResponse.getErrorCode().intValue());
122 Product checkedInProduct = ResponseParser.parseToObjectUsingMapper(checkInResponse.getResponse(),
125 expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
126 expectedProduct.setLastUpdaterUserId(adminUser.getUserId());
127 expectedProduct.setLastUpdaterFullName(adminUser.getFullName());
129 ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedInProduct, operation);
131 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedInProduct,
132 auditAction, adminUser, ActionStatus.OK, "0.1", "0.1", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
133 LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, checkedInProduct.getUUID());
134 expectedProductAudit.setCOMMENT(checkinComment);
135 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction, AuditJsonKeysEnum.COMMENT);
139 public void checkInProductByPMNotOwner() throws Exception {
141 RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager2,
142 LifeCycleStatesEnum.CHECKIN);
143 assertEquals("Check response code after checkin resource", 403, checkInResponse.getErrorCode().intValue());
144 String[] auditParameters = new String[] { expectedProduct.getName(), "product", productManager1.getFirstName(),
145 productManager1.getLastName(), productManager1.getUserId() };
146 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
147 auditAction, productManager2, ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, "0.1", "0.1",
148 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
149 expectedProduct.getUUID(), auditParameters);
150 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
154 public void checkInProductByPsRoleNotAllowed() throws Exception {
156 RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productStrategistUser1,
157 LifeCycleStatesEnum.CHECKIN);
158 assertEquals("Check response code after checkin resource", 409, checkInResponse.getErrorCode().intValue());
159 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
160 auditAction, productStrategistUser1, ActionStatus.RESTRICTED_OPERATION, "0.1", "0.1",
161 LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
162 expectedProduct.getUUID());
163 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
167 public void checkInProductNotExist() throws Exception {
168 String notExisitingUuid = "1234";
169 expectedProduct.setUniqueId(notExisitingUuid);
170 RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
171 LifeCycleStatesEnum.CHECKIN);
172 assertEquals("Check response code after checkin resource", 404, checkInResponse.getErrorCode().intValue());
173 String[] auditParameters = new String[] { "", "product" };
174 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
175 auditAction, productManager1, ActionStatus.PRODUCT_NOT_FOUND, Constants.EMPTY_STRING,
176 Constants.EMPTY_STRING, null, null, Constants.EMPTY_STRING, auditParameters);
177 expectedProductAudit.setCURR_STATE(Constants.EMPTY_STRING);
178 expectedProductAudit.setRESOURCE_NAME(notExisitingUuid);
179 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
183 public void checkInProductAlreadyCheckedIn() throws Exception {
184 RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
185 LifeCycleStatesEnum.CHECKIN);
186 assertEquals("Check response code after checkin resource", 200, checkInResponse.getErrorCode().intValue());
187 DbUtils.cleanAllAudits();
188 checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager2,
189 LifeCycleStatesEnum.CHECKIN);
190 assertEquals("Check response code after checkin resource", 409, checkInResponse.getErrorCode().intValue());
191 String[] auditParameters = new String[] { expectedProduct.getName(), "product", productManager1.getFirstName(),
192 productManager1.getLastName(), productManager1.getUserId() };
193 ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
194 auditAction, productManager2, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, "0.1", "0.1",
195 LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN,
196 expectedProduct.getUUID(), auditParameters);
197 AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);