diff options
Diffstat (limited to 'integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/execute/product/ProductCheckoutTest.java')
-rw-r--r-- | integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/execute/product/ProductCheckoutTest.java | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/execute/product/ProductCheckoutTest.java b/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/execute/product/ProductCheckoutTest.java new file mode 100644 index 0000000000..90c1fa1455 --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/execute/product/ProductCheckoutTest.java @@ -0,0 +1,146 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.backend.ci.tests.execute.product; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.onap.sdc.backend.ci.tests.datatypes.enums.LifeCycleStatesEnum; +import org.onap.sdc.backend.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.Product; +import org.openecomp.sdc.be.model.User; +import org.onap.sdc.backend.ci.tests.datatypes.expected.ExpectedProductAudit; +import org.onap.sdc.backend.ci.tests.utils.DbUtils; +import org.onap.sdc.backend.ci.tests.utils.general.Convertor; +import org.onap.sdc.backend.ci.tests.utils.rest.LifecycleRestUtils; +import org.onap.sdc.backend.ci.tests.utils.rest.ProductRestUtils; +import org.onap.sdc.backend.ci.tests.utils.rest.ResponseParser; +import org.onap.sdc.backend.ci.tests.utils.validation.AuditValidationUtils; +import org.onap.sdc.backend.ci.tests.utils.validation.ProductValidationUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.FileNotFoundException; + +import static org.testng.AssertJUnit.assertEquals; + +public class ProductCheckoutTest extends ProductLifecycleTest { + + @Rule + public static TestName name = new TestName(); + + @BeforeClass + public static void staticInit() { + auditAction = CHECKOUT_ACTION; + operation = ComponentOperationEnum.CHANGE_STATE_CHECKOUT; + } + + public ProductCheckoutTest() { + super(name, ProductCheckoutTest.class.getName()); + } + + @Test + public void checkOutProductByPmNotInContacts() throws Exception { + checkOutProductSuccess(productManager2); + } + + @Test + public void checkOutProductByPmInContacts() throws Exception { + checkOutProductSuccess(productManager1); + } + + @Test + public void checkOutProductByAdmin() throws Exception { + checkOutProductSuccess(adminUser); + } + + @Test + public void checkOutProductByPs() throws Exception { + // Changed in 1604 patch - now it's restricted + checkOutProductRestricted(productStrategistUser3); + // checkOutProductSuccess(productStrategistUser3); + } + + @Test + public void checkOutProductByDesignerRoleNotAllowed() throws Exception { + checkOutProductRestricted(designerUser); + } + + @Test + public void checkOutProductAlreadyCheckedOut() throws Exception { + RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN); + assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue()); + + lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKOUT); + assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue()); + Product checkedOutProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class); + + DbUtils.cleanAllAudits(); + + lcsResponse = LifecycleRestUtils.changeProductState(checkedOutProduct, productManager2, LifeCycleStatesEnum.CHECKOUT); + assertEquals("Check response code after checkin resource", 403, lcsResponse.getErrorCode().intValue()); + String[] auditParameters = new String[] { checkedOutProduct.getName(), "product", productManager1.getFirstName(), productManager1.getLastName(), productManager1.getUserId() }; + + ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedOutProduct, auditAction, productManager2, ActionStatus.COMPONENT_IN_CHECKOUT_STATE, "0.2", "0.2", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, + LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, checkedOutProduct.getUUID(), auditParameters); + AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction); + } + + private void checkOutProductSuccess(User checkoutUser) throws Exception, FileNotFoundException { + RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN); + assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue()); + + lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT); + assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue()); + + // 0.1 is not highest now + RestResponse prevVersionProductResp = ProductRestUtils.getProduct(expectedProduct.getUniqueId(), productStrategistUser1.getUserId()); + Product prevVersionProduct = ResponseParser.parseToObjectUsingMapper(prevVersionProductResp.getResponse(), Product.class); + Boolean falseParam = false; + assertEquals(falseParam, prevVersionProduct.isHighestVersion()); + + Product checkedOutProduct = ResponseParser.parseToObjectUsingMapper(lcsResponse.getResponse(), Product.class); + + expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + expectedProduct.setVersion("0.2"); + expectedProduct.setLastUpdaterUserId(checkoutUser.getUserId()); + expectedProduct.setLastUpdaterFullName(checkoutUser.getFullName()); + ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedOutProduct, operation); + + ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedOutProduct, auditAction, checkoutUser, ActionStatus.OK, "0.1", "0.2", LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, + LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, checkedOutProduct.getUUID()); + AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction); + } + + private void checkOutProductRestricted(User checkoutUser) throws Exception, FileNotFoundException { + RestResponse lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1, LifeCycleStatesEnum.CHECKIN); + assertEquals("Check response code after checkin resource", 200, lcsResponse.getErrorCode().intValue()); + + lcsResponse = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT); + assertEquals("Check response code after checkin resource", 409, lcsResponse.getErrorCode().intValue()); + + ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct, auditAction, checkoutUser, ActionStatus.RESTRICTED_OPERATION, "0.1", "0.1", LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, + LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, expectedProduct.getUUID()); + AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction); + } + +} |