summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dcae/ci/api/tests/lifeCycle/PutCheckin.java
blob: 6b5ce88ccfa1797a6eb6f8fa2001445aa7bdc133 (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
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 - 2019 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.dcae.ci.api.tests.lifeCycle;

import java.io.IOException;
import java.util.UUID;

import org.assertj.core.api.SoftAssertions;
import org.onap.dcae.ci.api.tests.DcaeRestBaseTest;
import org.onap.dcae.ci.entities.RestResponse;
import org.onap.dcae.ci.utilities.DcaeRestClient;

import org.onap.dcae.ci.report.Report;
import org.onap.dcae.ci.utilities.StringUtils;
import org.testng.annotations.*;
import static org.assertj.core.api.Assertions.*;


import org.onap.sdc.dcae.composition.vfcmt.Vfcmt;

import com.aventstack.extentreports.Status;

public class PutCheckin extends DcaeRestBaseTest {
	
	private ArrangeHelper arrange = new ArrangeHelper(client);
	
	/* Positive */
	
	@Test
	public void checkedoutVfcmt_success() throws Exception {
		// arrange
		Vfcmt vfcmt = arrange.getCheckedoutVfcmt();
		// act
		Report.log(Status.INFO, "Checkin the vfcmt with it's lastUpdater user");
		RestResponse response = checkinVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId());
		// assert
		Vfcmt vfcmtAfterCheckin = gson.fromJson(response.getResponse(), Vfcmt.class);
		SoftAssertions.assertSoftly(softly -> {
			softly.assertThat(response.getStatusCode()).isEqualTo(200);
			softly.assertThat(vfcmtAfterCheckin.getLifecycleState()).contains("CHECKIN");
		});
	}
	
	/* Negative */
	
	@Test
	public void alreadyCheckedinVfcmt_statusCode409() throws Exception {
		// arrange
		Vfcmt vfcmt = arrange.getCheckedinVfcmt();
		// act
		Report.log(Status.INFO, "Checkin the vfcmt <b>AGAIN</b> with it's lastUpdater user");
		RestResponse response = checkinVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId());
		// assert
		assertThat(response.getStatusCode()).isEqualTo(409);
	}
	
	@Test
	public void invalidVfcmtUuid_statusCode400() throws Exception {
		// arrange
		String userId = DcaeRestClient.getDefaultUserId();
		// act
		Report.log(Status.INFO, "Checkin with an invalid-uuid as vfcmt-uuid");
		RestResponse response = checkinVfcmt("invalid-vfcmt-uuid", userId);
		// assert
		assertThat(response.getStatusCode()).isEqualTo(400);
	}
	
	@Test
	public void nonExistingUuid_statusCode409() throws Exception {
		// arrange
		String uuid = UUID.randomUUID().toString();
		String userId = DcaeRestClient.getDefaultUserId();
		// act
		Report.log(Status.INFO, "Checkin with a non-existing vfcmt-uuid");
		RestResponse response = checkinVfcmt(uuid, userId);
		// assert
		assertThat(response.getStatusCode()).isEqualTo(409);
	}
	
	@Test
	public void nonExistingUser_statusCode403() throws Exception {
		// arrange
		Vfcmt vfcmt = arrange.getCheckedoutVfcmt();
		// act
		Report.log(Status.INFO, "Checkin with a non-existing user");
		RestResponse response = checkinVfcmt(vfcmt.getUuid(), "anonymus");
		// assert
		assertThat(response.getStatusCode()).isEqualTo(403);
	}
	
	@Test
	public void notLastUser_statusCode403() throws Exception {
		// arrange
		String user1 = DcaeRestClient.getDefaultUserId();
		String user2 = DcaeRestClient.getDesigner2UserId();
		Vfcmt vfcmt = arrange.getCheckedoutVfcmt(user1);
		// act
		Report.log(Status.INFO, "Checkin the vfcmt with different user: " + user2);
		RestResponse response = checkinVfcmt(vfcmt.getUuid(), user2);
		// assert
		assertThat(response.getStatusCode()).isEqualTo(403);
	}
	
	@Test
	public void invalidAssetType_statusCode400() throws Exception {
		// arrange 
		String assetType = "kengero";
		String userId = DcaeRestClient.getDefaultUserId();
		Vfcmt vfcmt = arrange.getCheckedoutVfcmt();
		// act
		Report.log(Status.INFO, "Checkin the vfcmt with invalid asset-type");
		RestResponse response = checkinGeneral(assetType, userId, vfcmt);
		// assert
		assertThat(response.getStatusCode()).isEqualTo(400);
	}
	
	
	/* Private Methods */

	/**
	 * Performs checkin on a general vfcmt, use this in test action
	 * @param assetType
	 * @param userId
	 * @param vfcmt
	 * @return
	 * @throws IOException
	 */
	private RestResponse checkinGeneral(String assetType, String userId, Vfcmt vfcmt) throws IOException {
		RestResponse response = DcaeRestClient.checkinGeneral(assetType, vfcmt.getUuid(), userId);
		Report.log(Status.DEBUG, "Response: " + StringUtils.truncate(response));
		return response;
	}
	
	/**
	 * Performs checkin on vfcmt, use this in test action
	 * @param vfcmtUuid
	 * @param userId
	 * @return
	 * @throws IOException
	 */
	private RestResponse checkinVfcmt(String vfcmtUuid, String userId) throws IOException {
		RestResponse response = DcaeRestClient.checkinVfcmt(vfcmtUuid, userId);
		Report.log(Status.DEBUG, "Response: " + StringUtils.truncate(response));
		return response;
	}	
	
	
}