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.artifacts;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.google.gson.Gson;
25 import fj.data.Either;
26 import org.apache.http.HttpEntity;
27 import org.apache.http.HttpResponse;
28 import org.apache.http.client.HttpResponseException;
29 import org.apache.http.client.methods.CloseableHttpResponse;
30 import org.apache.http.client.methods.HttpDelete;
31 import org.apache.http.client.methods.HttpGet;
32 import org.apache.http.client.methods.HttpPost;
33 import org.apache.http.entity.StringEntity;
34 import org.apache.http.impl.client.BasicResponseHandler;
35 import org.apache.http.impl.client.CloseableHttpClient;
36 import org.apache.http.impl.client.HttpClients;
37 import org.apache.http.util.EntityUtils;
38 import org.json.simple.JSONArray;
39 import org.json.simple.JSONObject;
40 import org.json.simple.parser.JSONParser;
41 import org.json.simple.parser.ParseException;
42 import org.junit.Rule;
43 import org.junit.rules.TestName;
44 import org.openecomp.sdc.be.dao.api.ActionStatus;
45 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
46 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
47 import org.openecomp.sdc.be.model.*;
48 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
49 import org.openecomp.sdc.ci.tests.api.Urls;
50 import org.openecomp.sdc.ci.tests.config.Config;
51 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
52 import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
53 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
54 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
55 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
56 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
57 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
58 import org.openecomp.sdc.ci.tests.execute.interfaceoperation.InterfaceOperationsTest;
59 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
60 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
61 import org.openecomp.sdc.ci.tests.utils.rest.*;
62 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
63 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
64 import org.openecomp.sdc.common.util.GeneralUtility;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67 import org.testng.AssertJUnit;
68 import org.testng.annotations.BeforeMethod;
69 import org.testng.annotations.Test;
71 import java.io.IOException;
72 import java.io.UnsupportedEncodingException;
73 import java.util.HashMap;
76 public class ArtifactServletTest extends ComponentBaseTest {
78 private static final String ARTIFACT_NAME_STR = "artifactName";
79 private static final String ARTIFACT_TYPE_STR = "artifactType";
80 private static final String ARTIFACT_DESCRIPTION_STR = "description";
81 private static final String ARTIFACT_PAYLOAD_DATA_STR = "payloadData";
82 private static Logger log = LoggerFactory.getLogger(ArtifactServletTest.class.getName());
83 protected static final String UPLOAD_ARTIFACT_PAYLOAD = "UHVUVFktVXNlci1LZXktRmlsZS0yOiBzc2gtcnNhDQpFbmNyeXB0aW9uOiBhZXMyNTYtY2JjDQpDb21tZW5wOA0K";
84 protected static final String UPLOAD_ARTIFACT_NAME = "TLV_prv.ppk";
85 protected Config config = Config.instance();
86 protected String contentTypeHeaderData = "application/json";
87 protected String acceptHeaderDate = "application/json";
88 protected Gson gson = new Gson();
89 protected JSONParser jsonParser = new JSONParser();
90 protected String serviceVersion;
91 protected Resource resourceDetailsVFCcomp;
92 protected Service defaultService1;
93 protected Resource resource;
94 protected Resource pnfResource;
96 protected User sdncUserDetails;
99 public static TestName name = new TestName();
101 public ArtifactServletTest() {
102 super(name, ArtifactServletTest.class.getName());
107 public void create() throws Exception {
109 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
110 Either<Resource, RestResponse> resourceDetailsVFCcompE = AtomicOperationUtils
111 .createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.COMPUTE,
112 ResourceCategoryEnum.APPLICATION_L4_APP_SERVER, UserRoleEnum.DESIGNER, true);
113 resourceDetailsVFCcomp = resourceDetailsVFCcompE.left().value();
114 Either<Service, RestResponse> defaultService1e = AtomicOperationUtils
115 .createDefaultService(UserRoleEnum.DESIGNER, true);
116 defaultService1 = defaultService1e.left().value();
118 Either<Resource, RestResponse> createDefaultResourceEither =
119 AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true);
120 resource = createDefaultResourceEither.left().value();
122 Either<Resource, RestResponse> createDefaultPNFResourceEither =
123 AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true);
124 pnfResource = createDefaultPNFResourceEither.left().value();
128 public void upadteArtifactWithPayLoadToResourcseTest() throws Exception {
130 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
132 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
133 resourceDetailsVFCcomp.getUniqueId());
134 int status = response.getErrorCode();
135 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
138 defaultArtifact.setDescription("kjglkh");
139 defaultArtifact.setArtifactName("install_apache.sh");
140 defaultArtifact.setArtifactType("SHELL");
141 defaultArtifact.setPayload("new payload");
143 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
144 resourceDetailsVFCcomp.getUniqueId());
145 status = response.getErrorCode();
146 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
148 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
149 defaultArtifact, sdncUserDetails);
150 status = response.getErrorCode();
151 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
156 public void createAndUpdateArtifactToInterface() throws Exception {
158 CloseableHttpResponse response;
160 CloseableHttpClient httpclient = HttpClients.createDefault();
163 // upload artifact to interface
164 String interfaceName = "Standard";
165 String operationName = "configure";
167 String userBodyJson = createUploadArtifactBodyJson();
168 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
169 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
171 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
172 response = httpclient.execute(httpPost);
173 status = response.getStatusLine().getStatusCode();
174 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
176 // get artifact uniqueId
177 String artifactId = getLifecycleArtifactUid(response);
179 Map<String, Object> jsonBody = new HashMap<String, Object>();
180 jsonBody.put(ARTIFACT_NAME_STR, "TLV_prv.ppk");
181 jsonBody.put("artifactDisplayName", "configure");
182 jsonBody.put(ARTIFACT_TYPE_STR, "SHELL");
183 jsonBody.put("mandatory", "false");
184 String newDescription = "new something";
185 jsonBody.put(ARTIFACT_DESCRIPTION_STR, newDescription);
186 jsonBody.put("artifactLabel", "configure");
187 userBodyJson = gson.toJson(jsonBody);
189 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
190 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
193 httpPost = createPostAddArtifactRequeast(userBodyJson, url, false);
195 response = httpclient.execute(httpPost);
196 status = response.getStatusLine().getStatusCode();
197 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
199 url = String.format(Urls.GET_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(),
200 resourceDetailsVFCcomp.getUniqueId());
201 HttpGet httpGet = createGetRequest(url);
202 response = httpclient.execute(httpGet);
203 AssertJUnit.assertTrue(response.getStatusLine().getStatusCode() == 200);
204 String responseString = new BasicResponseHandler().handleResponse(response);
206 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
207 responseMap = (JSONObject) responseMap.get("interfaces");
208 responseMap = (JSONObject) responseMap.get(interfaceName.toLowerCase());
209 responseMap = (JSONObject) responseMap.get("operations");
210 responseMap = (JSONObject) responseMap.get(operationName.toLowerCase());
211 responseMap = (JSONObject) responseMap.get("implementation");
212 String description = (String) responseMap.get(ARTIFACT_DESCRIPTION_STR);
214 AssertJUnit.assertEquals("the new description value was not set", newDescription, description);
217 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
218 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
220 HttpDelete httpDelete = createDeleteArtifactRequest(url);
222 response = httpclient.execute(httpDelete);
223 status = response.getStatusLine().getStatusCode();
224 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
231 protected String createUploadArtifactBodyJson() {
232 Map<String, Object> jsonBody = new HashMap<String, Object>();
233 jsonBody.put(ARTIFACT_NAME_STR, UPLOAD_ARTIFACT_NAME);
234 jsonBody.put("artifactDisplayName", "configure");
235 jsonBody.put(ARTIFACT_TYPE_STR, "SHELL");
236 jsonBody.put("mandatory", "false");
237 jsonBody.put(ARTIFACT_DESCRIPTION_STR, "ff");
238 jsonBody.put(ARTIFACT_PAYLOAD_DATA_STR, UPLOAD_ARTIFACT_PAYLOAD);
239 jsonBody.put("artifactLabel", "configure");
240 return gson.toJson(jsonBody);
243 protected ArtifactDefinition getArtifactDataFromJson(String json) {
244 Gson gson = new Gson();
245 ArtifactDefinition artifact = new ArtifactDefinition();
246 artifact = gson.fromJson(json, ArtifactDefinition.class);
249 * atifact.setArtifactName(UPLOAD_ARTIFACT_NAME);
250 * artifact.setArtifactDisplayName("configure");
251 * artifact.setArtifactType("SHELL"); artifact.setMandatory(false);
252 * artifact.setDescription("ff");
253 * artifact.setPayloadData(UPLOAD_ARTIFACT_PAYLOAD);
254 * artifact.setArtifactLabel("configure");
259 protected HttpGet createGetRequest(String url) {
260 HttpGet httpGet = new HttpGet(url);
261 httpGet.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
262 httpGet.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
263 httpGet.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
267 protected String getArtifactUid(HttpResponse response) throws HttpResponseException, IOException, ParseException {
268 String responseString = new BasicResponseHandler().handleResponse(response);
269 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
270 String artifactId = (String) responseMap.get("uniqueId");
274 protected String getArtifactEsId(HttpResponse response) throws HttpResponseException, IOException, ParseException {
275 String responseString = new BasicResponseHandler().handleResponse(response);
276 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
277 String esId = (String) responseMap.get("EsId");
281 protected ArtifactDefinition addArtifactDataFromResponse(HttpResponse response, ArtifactDefinition artifact)
282 throws HttpResponseException, IOException, ParseException {
283 // String responseString = new
284 // BasicResponseHandler().handleResponse(response);
285 HttpEntity entity = response.getEntity();
286 String responseString = EntityUtils.toString(entity);
287 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
288 artifact.setEsId((String) responseMap.get("esId"));
289 artifact.setUniqueId((String) responseMap.get("uniqueId"));
290 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.findType((String) responseMap.get("artifactGroupType")));
291 artifact.setTimeout(((Long) responseMap.get("timeout")).intValue());
295 protected String getLifecycleArtifactUid(CloseableHttpResponse response)
296 throws HttpResponseException, IOException, ParseException {
297 String responseString = new BasicResponseHandler().handleResponse(response);
298 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
299 responseMap = (JSONObject) responseMap.get("implementation");
300 String artifactId = (String) responseMap.get("uniqueId");
304 protected HttpDelete createDeleteArtifactRequest(String url) {
305 HttpDelete httpDelete = new HttpDelete(url);
306 httpDelete.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
307 httpDelete.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
311 protected HttpPost createPostAddArtifactRequeast(String jsonBody, String url, boolean addMd5Header)
312 throws UnsupportedEncodingException {
313 HttpPost httppost = new HttpPost(url);
314 httppost.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
315 httppost.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
316 httppost.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
318 httppost.addHeader(HttpHeaderEnum.Content_MD5.getValue(), GeneralUtility.calculateMD5Base64EncodedByString(jsonBody));
320 StringEntity input = new StringEntity(jsonBody);
321 input.setContentType("application/json");
322 httppost.setEntity(input);
323 log.debug("Executing request {}", httppost.getRequestLine());
327 protected String createLoadArtifactBody() {
328 Map<String, Object> json = new HashMap<String, Object>();
329 json.put(ARTIFACT_NAME_STR, "install_apache2.sh");
330 json.put(ARTIFACT_TYPE_STR, "SHELL");
331 json.put(ARTIFACT_DESCRIPTION_STR, "ddd");
332 json.put(ARTIFACT_PAYLOAD_DATA_STR, "UEsDBAoAAAAIAAeLb0bDQz");
333 json.put("artifactLabel", "name123");
335 String jsonStr = gson.toJson(json);
339 protected void checkDeleteResponse(RestResponse response) {
340 BaseRestUtils.checkStatusCode(response, "delete request failed", false, 204, 404);
343 protected ArtifactUiDownloadData getArtifactUiDownloadData(String artifactUiDownloadDataStr) throws Exception {
345 ObjectMapper mapper = new ObjectMapper();
347 ArtifactUiDownloadData artifactUiDownloadData = mapper.readValue(artifactUiDownloadDataStr,
348 ArtifactUiDownloadData.class);
349 return artifactUiDownloadData;
350 } catch (Exception e) {
359 public void addArtifactNoPayLoadToResourcseTest() throws Exception {
360 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
361 defaultArtifact.setPayload(null);
363 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
364 resourceDetailsVFCcomp.getUniqueId());
365 int status = response.getErrorCode();
366 AssertJUnit.assertTrue(status == 400);
371 public void upadteArtifactNoPayLoadToResourcseTest() throws Exception {
373 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
375 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
376 resourceDetailsVFCcomp.getUniqueId());
377 int status = response.getErrorCode();
378 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
381 defaultArtifact.setDescription("kjglkh");
382 defaultArtifact.setArtifactName("install_apache.sh");
383 defaultArtifact.setArtifactType("SHELL");
384 defaultArtifact.setPayload(null);
386 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
387 resourceDetailsVFCcomp.getUniqueId());
388 status = response.getErrorCode();
389 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
391 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
392 defaultArtifact, sdncUserDetails);
393 status = response.getErrorCode();
394 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
399 @Test(enabled = false)
400 public void updateDeploymentArtifactToResourcseTest() throws Exception {
402 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultDeploymentArtifactForType("HEAT");
404 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
405 resourceDetailsVFCcomp.getUniqueId());
406 int status = response.getErrorCode();
407 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
410 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
411 resourceDetailsVFCcomp.getUniqueId());
412 status = response.getErrorCode();
413 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
415 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
416 defaultArtifact, sdncUserDetails);
417 status = response.getErrorCode();
418 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
422 // --------------------
424 public void addArtifactToResourcse_AlreadyExistsTest() throws Exception {
425 CloseableHttpClient httpclient = HttpClients.createDefault();
427 String jsonBody = createLoadArtifactBody();
429 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
430 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
431 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
432 CloseableHttpResponse response = httpclient.execute(httppost);
433 int status = response.getStatusLine().getStatusCode();
434 AssertJUnit.assertTrue("failed to add artifact", status == 200);
436 String artifactId = getArtifactUid(response);
438 httppost = createPostAddArtifactRequeast(jsonBody, url, true);
439 response = httpclient.execute(httppost);
440 status = response.getStatusLine().getStatusCode();
441 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
443 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
444 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), artifactId);
445 HttpDelete httpDelete = createDeleteArtifactRequest(url);
446 response = httpclient.execute(httpDelete);
447 status = response.getStatusLine().getStatusCode();
448 AssertJUnit.assertTrue("failed to remove artifact", status == 200);
456 public void addArtifactToResourcse_MissingContentTest() throws Exception {
458 CloseableHttpClient httpclient = HttpClients.createDefault();
460 Map<String, Object> json = new HashMap<String, Object>();
461 json.put(ARTIFACT_DESCRIPTION_STR, "desc");
462 json.put(ARTIFACT_PAYLOAD_DATA_STR, "UEsDBAoAAAAIAAeLb0bDQz");
463 json.put("Content-MD5", "YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI=");
465 String jsonBody = gson.toJson(json);
467 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
468 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
469 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
470 CloseableHttpResponse response = httpclient.execute(httppost);
471 int status = response.getStatusLine().getStatusCode();
472 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
480 public void addArtifactToResourcse_MissingMd5Test() throws Exception {
482 CloseableHttpClient httpclient = HttpClients.createDefault();
484 HashMap<String, Object> json = new HashMap<String, Object>();
485 json.put(ARTIFACT_NAME_STR, "install_apache.sh");
486 json.put(ARTIFACT_TYPE_STR, "SHELL");
487 json.put(ARTIFACT_DESCRIPTION_STR, "kjglkh");
488 json.put(ARTIFACT_PAYLOAD_DATA_STR, "UEsDBYTEIWUYIFHWFMABCNAoAAAAIAAeLb0bDQz");
489 json.put("artifactLabel", "name123");
490 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
491 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
492 String jsonBody = gson.toJson(json);
493 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, false);
494 CloseableHttpResponse response = httpclient.execute(httppost);
495 int status = response.getStatusLine().getStatusCode();
496 AssertJUnit.assertTrue("failed to update artifact metatdata", status == 400);
504 public void deleteArtifact_NotExistsTest() throws Exception {
505 CloseableHttpClient httpclient = HttpClients.createDefault();
507 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
508 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), "someFakeId");
509 HttpDelete httpDelete = createDeleteArtifactRequest(url);
510 CloseableHttpResponse response = httpclient.execute(httpDelete);
511 int status = response.getStatusLine().getStatusCode();
512 AssertJUnit.assertEquals("the returned status code is in correct", status, 404);
520 public void createAndRemoveArtifactToInterface() throws Exception {
521 CloseableHttpResponse response;
523 CloseableHttpClient httpclient = HttpClients.createDefault();
526 // upload artifact to interface
527 String interfaceName = "Standard";
528 String operationName = "configure";
530 String userBodyJson = createUploadArtifactBodyJson();
531 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
532 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
534 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
535 response = httpclient.execute(httpPost);
536 status = response.getStatusLine().getStatusCode();
537 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
539 // get artifact uniqueId
540 String artifactId = getLifecycleArtifactUid(response);
543 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
544 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
546 HttpDelete httpDelete = createDeleteArtifactRequest(url);
548 response = httpclient.execute(httpDelete);
549 status = response.getStatusLine().getStatusCode();
550 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
558 public void addArtifactToServiceTest() throws Exception {
560 CloseableHttpClient httpclient = HttpClients.createDefault();
563 String jsonStr = createLoadArtifactBody();
565 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
566 config.getCatalogBePort(), defaultService1.getUniqueId());
567 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
568 CloseableHttpResponse result = httpclient.execute(httpPost);
569 int status = result.getStatusLine().getStatusCode();
570 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
572 String artifactId = getArtifactUid(result);
574 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),
575 config.getCatalogBePort(), defaultService1.getUniqueId(), artifactId);
576 HttpDelete httpDelete = createDeleteArtifactRequest(url);
578 result = httpclient.execute(httpDelete);
579 status = result.getStatusLine().getStatusCode();
580 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
582 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
584 checkDeleteResponse(response);
590 public void addArtifactNotSupportedTypeToServiceTest() throws Exception {
591 CloseableHttpClient httpclient = HttpClients.createDefault();
593 Map<String, Object> json = new HashMap<String, Object>();
594 json.put(ARTIFACT_NAME_STR, "install_apache.sh");
595 json.put(ARTIFACT_TYPE_STR, "SHELL11");
596 json.put(ARTIFACT_DESCRIPTION_STR, "fff");
597 json.put(ARTIFACT_PAYLOAD_DATA_STR, "UEsDBAoAAAAIAAeLb0bDQz");
598 json.put("artifactLabel", "name123");
600 String jsonStr = gson.toJson(json);
602 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
603 config.getCatalogBePort(), defaultService1.getUniqueId());
605 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
606 CloseableHttpResponse result = httpclient.execute(httpPost);
607 int status = result.getStatusLine().getStatusCode();
608 AssertJUnit.assertEquals("response code is not 400, returned :" + status, 400, status);
610 ErrorInfo errorInfo = ErrorValidationUtils
611 .parseErrorConfigYaml(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED.name());
613 String responseString = EntityUtils.toString(result.getEntity());
615 JSONObject map = (JSONObject) jsonParser.parse(responseString);
616 JSONObject requestError = (JSONObject) map.get("requestError");
617 JSONObject serviceException = (JSONObject) requestError.get("serviceException");
619 String msgId = (String) serviceException.get("messageId");
620 AssertJUnit.assertEquals("message id did not match expacted", errorInfo.getMessageId(), msgId);
622 String text = (String) serviceException.get("text");
623 AssertJUnit.assertEquals("text did not match expacted", errorInfo.getMessage(), text);
625 JSONArray variables = (JSONArray) serviceException.get("variables");
626 String type = (String) variables.get(0);
627 AssertJUnit.assertEquals("variable did not match expacted", "SHELL11", type);
629 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
631 checkDeleteResponse(response);
638 public void addArtifactToResourceTest() throws Exception {
640 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
642 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
643 resourceDetailsVFCcomp.getUniqueId());
644 int status = response.getErrorCode();
645 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
648 RestResponse resourceResp = ResourceRestUtils.getResource(resourceDetailsVFCcomp.getUniqueId());
649 Resource resource = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
650 AssertJUnit.assertNotNull(resource);
652 Map<String, ArtifactDefinition> artifacts = resource.getArtifacts();
653 boolean isExist = false;
654 for (Map.Entry<String, ArtifactDefinition> entry : artifacts.entrySet()) {
655 if (entry.getKey().equals(defaultArtifact.getArtifactLabel())) {
660 AssertJUnit.assertTrue(isExist);
664 public void addInterfaceOperationArtifactOnResource() throws Exception {
665 try (CloseableHttpClient httpclient = HttpClients.createDefault()){
666 Map<String, Object> artifactData = new HashMap<>();
667 artifactData.put(ARTIFACT_NAME_STR, "TestWF-1_0.bpmn");
668 artifactData.put(ARTIFACT_TYPE_STR, "WORKFLOW");
669 artifactData.put(ARTIFACT_DESCRIPTION_STR, "Resource Workflow Artifact Description");
670 artifactData.put(ARTIFACT_PAYLOAD_DATA_STR, "Test Data of Resource");
672 String jsonStr = gson.toJson(artifactData);
673 RestResponse restResponse = InterfaceOperationsRestUtils.addInterfaceOperations(resource,
674 new InterfaceOperationsTest().buildInterfaceDefinitionForResource(resource,
676 ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
677 String interfaceDefStr = ResponseParser.getListFromJson(restResponse, "interfaces").get(0).toString();
678 InterfaceDefinition interfaceDefinition = ResponseParser.convertInterfaceDefinitionResponseToJavaObject(interfaceDefStr);
679 String interfaceUUID = interfaceDefinition.getUniqueId();
680 String operationUUID = interfaceDefinition.getOperationsMap().keySet().stream().findFirst().orElse(null);
681 String artifactUUID = interfaceDefinition.getOperationsMap().values().stream().findFirst().get().getImplementation().getArtifactUUID();
683 String url = String.format(Urls.UPLOAD_INTERFACE_OPERATION_ARTIFACT, config.getCatalogBeHost(),
684 config.getCatalogBePort(), ComponentTypeEnum.findParamByType(resource.getComponentType()),
685 resource.getUUID(), interfaceUUID, operationUUID, artifactUUID);
686 CloseableHttpResponse result = httpclient.execute(createPostAddArtifactRequeast(jsonStr, url, true));
687 int status = result.getStatusLine().getStatusCode();
688 AssertJUnit.assertEquals("add informational artifact request returned status: " + status, 200, status);
693 public void addInterfaceOperationArtifactOnPNFResource() throws Exception {
694 try (CloseableHttpClient httpclient = HttpClients.createDefault()){
695 Map<String, Object> artifactData = new HashMap<>();
696 artifactData.put(ARTIFACT_NAME_STR, "TestWF-1_0.bpmn");
697 artifactData.put(ARTIFACT_TYPE_STR, "WORKFLOW");
698 artifactData.put(ARTIFACT_DESCRIPTION_STR, "PNF Resource Workflow Artifact Description");
699 artifactData.put(ARTIFACT_PAYLOAD_DATA_STR, "Test Data of PNF Resource");
701 String jsonStr = gson.toJson(artifactData);
702 RestResponse restResponse = InterfaceOperationsRestUtils.addInterfaceOperations(pnfResource,
703 new InterfaceOperationsTest().buildInterfaceDefinitionForResource(pnfResource,
705 ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
706 String interfaceDefStr = ResponseParser.getListFromJson(restResponse, "interfaces").get(0).toString();
707 InterfaceDefinition interfaceDefinition = ResponseParser.convertInterfaceDefinitionResponseToJavaObject(interfaceDefStr);
708 String interfaceUUID = interfaceDefinition.getUniqueId();
709 String operationUUID = interfaceDefinition.getOperationsMap().keySet().stream().findFirst().orElse(null);
710 String artifactUUID = interfaceDefinition.getOperationsMap().values().stream().findFirst().get().getImplementation().getArtifactUUID();
712 String url = String.format(Urls.UPLOAD_INTERFACE_OPERATION_ARTIFACT, config.getCatalogBeHost(),
713 config.getCatalogBePort(), ComponentTypeEnum.findParamByType(pnfResource.getComponentType()),
714 pnfResource.getUUID(), interfaceUUID, operationUUID, artifactUUID);
715 CloseableHttpResponse result = httpclient.execute(createPostAddArtifactRequeast(jsonStr, url, true));
716 int status = result.getStatusLine().getStatusCode();
717 AssertJUnit.assertEquals("add informational artifact request returned status: " + status, 200, status);
722 public void addInterfaceOperationArtifactOnService() throws Exception {
723 try (CloseableHttpClient httpclient = HttpClients.createDefault()){
724 Map<String, Object> artifactData = new HashMap<>();
725 artifactData.put(ARTIFACT_NAME_STR, "TestWF-1_0.bpmn");
726 artifactData.put(ARTIFACT_TYPE_STR, "WORKFLOW");
727 artifactData.put(ARTIFACT_DESCRIPTION_STR, "Service Workflow Artifact Description");
728 artifactData.put(ARTIFACT_PAYLOAD_DATA_STR, "Test Data of Service");
730 String jsonStr = gson.toJson(artifactData);
731 RestResponse restResponse = InterfaceOperationsRestUtils.addInterfaceOperations(defaultService1,
732 new InterfaceOperationsTest().buildInterfaceDefinitionForService(),
733 ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
734 String interfaceDefinitionStr = ResponseParser.getListFromJson(restResponse, "interfaces").get(0).toString();
735 InterfaceDefinition interfaceDefinition = ResponseParser.convertInterfaceDefinitionResponseToJavaObject(interfaceDefinitionStr);
736 String interfaceUUID = interfaceDefinition.getUniqueId();
737 String operationUUID = interfaceDefinition.getOperationsMap().keySet().stream().findFirst().orElse(null);
738 String artifactUUID = interfaceDefinition.getOperationsMap().values().stream().findFirst().get().getImplementation().getArtifactUUID();
740 String url = String.format(Urls.UPLOAD_INTERFACE_OPERATION_ARTIFACT, config.getCatalogBeHost(),
741 config.getCatalogBePort(), ComponentTypeEnum.findParamByType(defaultService1.getComponentType()),
742 defaultService1.getUUID(), interfaceUUID, operationUUID, artifactUUID);
743 CloseableHttpResponse result = httpclient.execute(createPostAddArtifactRequeast(jsonStr, url, true));
744 int status = result.getStatusLine().getStatusCode();
745 AssertJUnit.assertEquals("add informational artifact request returned status: " + status, 200, status);