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
|
package org.onap.dcae.ci.api.tests.services.attachment;
import static org.assertj.core.api.Assertions.*;
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.entities.composition.services.Vfi;
import org.onap.dcae.ci.entities.sdc.SdcResource;
import org.onap.dcae.ci.entities.sdc.SdcService;
import org.onap.dcae.ci.utilities.DcaeRestClient;
import org.onap.dcae.ci.report.Report;
import org.onap.dcae.ci.utilities.SdcInternalApiClient;
import org.onap.sdc.dcae.composition.vfcmt.Vfcmt;
import org.testng.annotations.*;
import java.util.UUID;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import com.aventstack.extentreports.Status;
public class PostAttachment extends DcaeRestBaseTest {
/* Positive */
@Test
public void vfcmtWithVfi_responseStatusOk() throws Exception {
// arrange
Vfcmt vfcmt;
Vfi vfi;
try {
vfcmt = client.createCheckedinVfcmt();
vfi = arrangeVfi();
} catch (Exception err) {
throw new Exception("Could not arrange test", err);
}
// act
Report.log(Status.INFO, "Attaching vfcmt [%s] to vfi [%s]", vfcmt.getUuid(), vfi.getName());
RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), vfi.getContainer().getUuid(), vfi.getName());
Report.logDebug("Response:", response);
// assert
JSONObject resData = (JSONObject) JSONValue.parse(response.getResponse());
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200);
softly.assertThat(resData.get("successResponse"))
.as("successResponse")
.isEqualTo("Artifact updated");
});
}
@Test
public void vfcmtAlreadyAttached_responseStatusOk() throws Exception {
// arrange
Vfcmt vfcmt;
Vfi vfi;
try {
vfcmt = client.createCheckedinVfcmt();
Report.log(Status.INFO, "Arranging first attachment");
arrangeAttachmentToNewVfi(vfcmt);
vfi = arrangeVfi();
} catch (Exception err) {
throw new Exception("Could not arrange test", err);
}
// act
Report.log(Status.INFO, "Updating attachment of vfcmt [%s] to a new vfi [%s]", vfcmt.getUuid(), vfi.getName());
RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), vfi.getContainer().getUuid(), vfi.getName());
Report.logDebug("Response:", response);
// assert
JSONObject resData = (JSONObject) JSONValue.parse(response.getResponse());
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200);
softly.assertThat(resData.get("successResponse"))
.as("successResponse")
.isEqualTo("Artifact updated");
});
}
/* Negative */
@Test
public void vfWithVfi_statusCode400() throws Exception {
// arrange
SdcResource vf;
Vfi vfi;
try {
Report.log(Status.INFO, "Create vf");
vf = SdcInternalApiClient.createVf();
vfi = arrangeVfi();
} catch (Exception err) {
throw new Exception("Could not arrange test", err);
}
// act
Report.log(Status.INFO, "Attaching vf [%s] to vfi [%s]", vf.getUuid(), vfi.getName());
RestResponse response = DcaeRestClient.attachVfiRef(vf.getUuid(), vfi.getContainer().getUuid(), vfi.getName());
Report.logDebug("Response:", response);
// assert
assertThat(response.getStatusCode()).as("status code").isEqualTo(400);
}
@Test
public void vfcmtWithFakeServiceAndFakeVfi_statusCode404() throws Exception {
// arrange
Vfcmt vfcmt;
String fakeServiceUuid = UUID.randomUUID().toString();
String fakeVfiName = "fakeVfi";
try {
vfcmt = client.createCheckedinVfcmt();
fakeServiceUuid = UUID.randomUUID().toString();
fakeVfiName = "fakeVfi";
} catch (Exception err) {
throw new Exception("Could not arrange test", err);
}
// act
Report.log(Status.INFO, "Attaching real vfcmt [%s] to fake service [%s] (random uuid) and fake vfi [%s]", vfcmt.getUuid(), fakeServiceUuid, fakeVfiName);
RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), fakeServiceUuid, fakeVfiName);
Report.logDebug("Response:", response);
// assert
assertThat(response.getStatusCode()).as("status code").isEqualTo(404);
}
@Test
public void vfcmtWithFakeVfi_statusCode404() throws Exception {
// arrange
Vfcmt vfcmt;
Vfi vfi;
try {
vfcmt = client.createCheckedinVfcmt();
Report.log(Status.INFO, "Create service");
SdcService service = SdcInternalApiClient.createService();
vfi = new Vfi("fakeVfi", service);
} catch (Exception err) {
throw new Exception("Could not arrange test", err);
}
// act
Report.log(Status.INFO, "Attaching vfcmt [%s] to real service [%s] and fake vfi [%s]", vfcmt.getUuid(), vfi.getContainer().getUuid(), vfi.getName());
RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), vfi.getContainer().getUuid(), vfi.getName());
Report.logDebug("Response:", response);
// assert
assertThat(response.getStatusCode()).as("status code").isEqualTo(404);
}
/* Private Methods */
private Vfi arrangeVfi() throws Exception {
Report.log(Status.INFO, "Create service");
SdcService service = SdcInternalApiClient.createService();
Report.log(Status.INFO, "Create vf");
SdcResource vf = SdcInternalApiClient.createVf();
Report.log(Status.INFO, "Checkin vf");
vf = SdcInternalApiClient.checkinVf(vf);
Report.log(Status.INFO, "Create vfi from (service [%s] + vf [%s])", service.getUuid(), vf.getUuid());
return SdcInternalApiClient.createVfi(service, vf);
}
private void arrangeAttachmentToNewVfi(Vfcmt vfcmt) throws Exception {
Vfi vfi = arrangeVfi();
Report.log(Status.INFO, "Attaching vfcmt [%s] to vfi [%s]", vfcmt.getUuid(), vfi.getName());
RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), vfi.getContainer().getUuid(), vfi.getName());
Report.logDebug("Response:", response);
if (response.getStatusCode() != 200) {
throw new Exception("Failed to attach vfcmt to vfi\nResponse: " + response.toString());
}
}
}
|