aboutsummaryrefslogtreecommitdiffstats
path: root/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/product/ProductCheckinTest.java
blob: 94027bd6ebdacf617cc2c9a0041fefbea67a7446 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*-
 * ============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.openecomp.sdc.ci.tests.execute.product;

import org.junit.Rule;
import org.junit.rules.TestName;
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.openecomp.sdc.ci.tests.datatypes.enums.AuditJsonKeysEnum;
import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedProductAudit;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.utils.DbUtils;
import org.openecomp.sdc.ci.tests.utils.general.Convertor;
import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
import org.openecomp.sdc.ci.tests.utils.validation.ProductValidationUtils;
import org.openecomp.sdc.common.api.Constants;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static org.testng.AssertJUnit.assertEquals;

public class ProductCheckinTest extends ProductLifecycleTest {

	@Rule
	public static TestName name = new TestName();

	public ProductCheckinTest() {
		super(name, ProductCheckinTest.class.getName());
	}

	@BeforeClass
	public static void staticInit() {
		auditAction = CHECKIN_ACTION;
		operation = ComponentOperationEnum.CHANGE_STATE_CHECKIN;
	}

	@Test
	public void checkInProductByCreator() throws Exception {

		String checkinComment = "good checkin";
		RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
				LifeCycleStatesEnum.CHECKIN, checkinComment);
		assertEquals("Check response code after checkin resource", 200, checkInResponse.getErrorCode().intValue());
		Product checkedInProduct = ResponseParser.parseToObjectUsingMapper(checkInResponse.getResponse(),
				Product.class);

		expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
		ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedInProduct, operation);

		ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedInProduct,
				auditAction, productManager1, ActionStatus.OK, "0.1", "0.1", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
				LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, checkedInProduct.getUUID());
		expectedProductAudit.setCOMMENT(checkinComment);
		AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction, AuditJsonKeysEnum.COMMENT);
	}

	@Test
	public void checkInProductByPM() throws Exception {

		String checkinComment = "good checkin";
		RestResponse response = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
				LifeCycleStatesEnum.CHECKIN, checkinComment);
		assertEquals("Check response code after checkin resource", 200, response.getErrorCode().intValue());

		User checkoutUser = productManager2;
		response = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKOUT);
		assertEquals("Check response code after checkin resource", 200, response.getErrorCode().intValue());
		expectedProduct = ResponseParser.parseToObjectUsingMapper(response.getResponse(), Product.class);

		DbUtils.cleanAllAudits();
		checkinComment = "good checkin no 2";
		response = LifecycleRestUtils.changeProductState(expectedProduct, checkoutUser, LifeCycleStatesEnum.CHECKIN,
				checkinComment);
		assertEquals("Check response code after checkin resource", 200, response.getErrorCode().intValue());

		Product checkedInProduct = ResponseParser.parseToObjectUsingMapper(response.getResponse(), Product.class);

		expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
		expectedProduct.setVersion("0.2");
		expectedProduct.setLastUpdaterUserId(checkoutUser.getUserId());
		expectedProduct.setLastUpdaterFullName(checkoutUser.getFullName());

		ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedInProduct, operation);

		ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedInProduct,
				auditAction, checkoutUser, ActionStatus.OK, "0.2", "0.2", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
				LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, checkedInProduct.getUUID());
		expectedProductAudit.setCOMMENT(checkinComment);
		AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction, AuditJsonKeysEnum.COMMENT);
	}

	@Test
	public void checkInProductByAdmin() throws Exception {

		String checkinComment = "good checkin";
		RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, adminUser,
				LifeCycleStatesEnum.CHECKIN, checkinComment);
		assertEquals("Check response code after checkin resource", 200, checkInResponse.getErrorCode().intValue());
		Product checkedInProduct = ResponseParser.parseToObjectUsingMapper(checkInResponse.getResponse(),
				Product.class);

		expectedProduct.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
		expectedProduct.setLastUpdaterUserId(adminUser.getUserId());
		expectedProduct.setLastUpdaterFullName(adminUser.getFullName());

		ProductValidationUtils.compareExpectedAndActualProducts(expectedProduct, checkedInProduct, operation);

		ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(checkedInProduct,
				auditAction, adminUser, ActionStatus.OK, "0.1", "0.1", LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
				LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, checkedInProduct.getUUID());
		expectedProductAudit.setCOMMENT(checkinComment);
		AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction, AuditJsonKeysEnum.COMMENT);
	}

	@Test
	public void checkInProductByPMNotOwner() throws Exception {

		RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager2,
				LifeCycleStatesEnum.CHECKIN);
		assertEquals("Check response code after checkin resource", 403, checkInResponse.getErrorCode().intValue());
		String[] auditParameters = new String[] { expectedProduct.getName(), "product", productManager1.getFirstName(),
				productManager1.getLastName(), productManager1.getUserId() };
		ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
				auditAction, productManager2, ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, "0.1", "0.1",
				LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
				expectedProduct.getUUID(), auditParameters);
		AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
	}

	@Test
	public void checkInProductByPsRoleNotAllowed() throws Exception {

		RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productStrategistUser1,
				LifeCycleStatesEnum.CHECKIN);
		assertEquals("Check response code after checkin resource", 409, checkInResponse.getErrorCode().intValue());
		ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
				auditAction, productStrategistUser1, ActionStatus.RESTRICTED_OPERATION, "0.1", "0.1",
				LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT,
				expectedProduct.getUUID());
		AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
	}

	@Test
	public void checkInProductNotExist() throws Exception {
		String notExisitingUuid = "1234";
		expectedProduct.setUniqueId(notExisitingUuid);
		RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
				LifeCycleStatesEnum.CHECKIN);
		assertEquals("Check response code after checkin resource", 404, checkInResponse.getErrorCode().intValue());
		String[] auditParameters = new String[] { "", "product" };
		ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
				auditAction, productManager1, ActionStatus.PRODUCT_NOT_FOUND, Constants.EMPTY_STRING,
				Constants.EMPTY_STRING, null, null, Constants.EMPTY_STRING, auditParameters);
		expectedProductAudit.setCURR_STATE(Constants.EMPTY_STRING);
		expectedProductAudit.setRESOURCE_NAME(notExisitingUuid);
		AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
	}

	@Test
	public void checkInProductAlreadyCheckedIn() throws Exception {
		RestResponse checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager1,
				LifeCycleStatesEnum.CHECKIN);
		assertEquals("Check response code after checkin resource", 200, checkInResponse.getErrorCode().intValue());
		DbUtils.cleanAllAudits();
		checkInResponse = LifecycleRestUtils.changeProductState(expectedProduct, productManager2,
				LifeCycleStatesEnum.CHECKIN);
		assertEquals("Check response code after checkin resource", 409, checkInResponse.getErrorCode().intValue());
		String[] auditParameters = new String[] { expectedProduct.getName(), "product", productManager1.getFirstName(),
				productManager1.getLastName(), productManager1.getUserId() };
		ExpectedProductAudit expectedProductAudit = Convertor.constructFieldsForAuditValidation(expectedProduct,
				auditAction, productManager2, ActionStatus.COMPONENT_ALREADY_CHECKED_IN, "0.1", "0.1",
				LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN,
				expectedProduct.getUUID(), auditParameters);
		AuditValidationUtils.validateAuditProduct(expectedProductAudit, auditAction);
	}
}