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.ResourceTypeEnum;
46 import org.openecomp.sdc.be.model.*;
47 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
48 import org.openecomp.sdc.ci.tests.api.Urls;
49 import org.openecomp.sdc.ci.tests.config.Config;
50 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
51 import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
52 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
53 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
54 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
55 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
56 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
57 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
58 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
59 import org.openecomp.sdc.ci.tests.utils.rest.*;
60 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
61 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
62 import org.openecomp.sdc.common.util.GeneralUtility;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
65 import org.testng.AssertJUnit;
66 import org.testng.annotations.BeforeMethod;
67 import org.testng.annotations.Test;
69 import java.io.IOException;
70 import java.io.UnsupportedEncodingException;
71 import java.util.HashMap;
74 public class ArtifactServletTest extends ComponentBaseTest {
76 private static Logger log = LoggerFactory.getLogger(ArtifactServletTest.class.getName());
77 protected static final String UPLOAD_ARTIFACT_PAYLOAD = "UHVUVFktVXNlci1LZXktRmlsZS0yOiBzc2gtcnNhDQpFbmNyeXB0aW9uOiBhZXMyNTYtY2JjDQpDb21tZW5wOA0K";
78 protected static final String UPLOAD_ARTIFACT_NAME = "TLV_prv.ppk";
79 protected Config config = Config.instance();
80 protected String contentTypeHeaderData = "application/json";
81 protected String acceptHeaderDate = "application/json";
82 protected Gson gson = new Gson();
83 protected JSONParser jsonParser = new JSONParser();
84 protected String serviceVersion;
85 protected Resource resourceDetailsVFCcomp;
86 protected Service defaultService1;
88 protected User sdncUserDetails;
91 public static TestName name = new TestName();
93 public ArtifactServletTest() {
94 super(name, ArtifactServletTest.class.getName());
99 public void create() throws Exception {
101 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
102 Either<Resource, RestResponse> resourceDetailsVFCcompE = AtomicOperationUtils
103 .createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.COMPUTE,
104 ResourceCategoryEnum.APPLICATION_L4_APP_SERVER, UserRoleEnum.DESIGNER, true);
105 resourceDetailsVFCcomp = resourceDetailsVFCcompE.left().value();
106 Either<Service, RestResponse> defaultService1e = AtomicOperationUtils
107 .createDefaultService(UserRoleEnum.DESIGNER, true);
108 defaultService1 = defaultService1e.left().value();
112 public void upadteArtifactWithPayLoadToResourcseTest() throws Exception {
114 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
116 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
117 resourceDetailsVFCcomp.getUniqueId());
118 int status = response.getErrorCode();
119 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
122 defaultArtifact.setDescription("kjglkh");
123 defaultArtifact.setArtifactName("install_apache.sh");
124 defaultArtifact.setArtifactType("SHELL");
125 defaultArtifact.setPayload("new payload");
127 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
128 resourceDetailsVFCcomp.getUniqueId());
129 status = response.getErrorCode();
130 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
132 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
133 defaultArtifact, sdncUserDetails);
134 status = response.getErrorCode();
135 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
140 public void createAndUpdateArtifactToInterface() throws Exception {
142 CloseableHttpResponse response;
144 CloseableHttpClient httpclient = HttpClients.createDefault();
147 // upload artifact to interface
148 String interfaceName = "Standard";
149 String operationName = "configure";
151 String userBodyJson = createUploadArtifactBodyJson();
152 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
153 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
155 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
156 response = httpclient.execute(httpPost);
157 status = response.getStatusLine().getStatusCode();
158 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
160 // get artifact uniqueId
161 String artifactId = getLifecycleArtifactUid(response);
163 Map<String, Object> jsonBody = new HashMap<String, Object>();
164 jsonBody.put("artifactName", "TLV_prv.ppk");
165 jsonBody.put("artifactDisplayName", "configure");
166 jsonBody.put("artifactType", "SHELL");
167 jsonBody.put("mandatory", "false");
168 String newDescription = "new something";
169 jsonBody.put("description", newDescription);
170 jsonBody.put("artifactLabel", "configure");
171 userBodyJson = gson.toJson(jsonBody);
173 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
174 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
177 httpPost = createPostAddArtifactRequeast(userBodyJson, url, false);
179 response = httpclient.execute(httpPost);
180 status = response.getStatusLine().getStatusCode();
181 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
183 url = String.format(Urls.GET_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(),
184 resourceDetailsVFCcomp.getUniqueId());
185 HttpGet httpGet = createGetRequest(url);
186 response = httpclient.execute(httpGet);
187 AssertJUnit.assertTrue(response.getStatusLine().getStatusCode() == 200);
188 String responseString = new BasicResponseHandler().handleResponse(response);
190 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
191 responseMap = (JSONObject) responseMap.get("interfaces");
192 responseMap = (JSONObject) responseMap.get(interfaceName.toLowerCase());
193 responseMap = (JSONObject) responseMap.get("operations");
194 responseMap = (JSONObject) responseMap.get(operationName.toLowerCase());
195 responseMap = (JSONObject) responseMap.get("implementation");
196 String description = (String) responseMap.get("description");
198 AssertJUnit.assertEquals("the new description value was not set", newDescription, description);
201 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
202 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
204 HttpDelete httpDelete = createDeleteArtifactRequest(url);
206 response = httpclient.execute(httpDelete);
207 status = response.getStatusLine().getStatusCode();
208 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
215 protected String createUploadArtifactBodyJson() {
216 Map<String, Object> jsonBody = new HashMap<String, Object>();
217 jsonBody.put("artifactName", UPLOAD_ARTIFACT_NAME);
218 jsonBody.put("artifactDisplayName", "configure");
219 jsonBody.put("artifactType", "SHELL");
220 jsonBody.put("mandatory", "false");
221 jsonBody.put("description", "ff");
222 jsonBody.put("payloadData", UPLOAD_ARTIFACT_PAYLOAD);
223 jsonBody.put("artifactLabel", "configure");
224 return gson.toJson(jsonBody);
227 protected ArtifactDefinition getArtifactDataFromJson(String json) {
228 Gson gson = new Gson();
229 ArtifactDefinition artifact = new ArtifactDefinition();
230 artifact = gson.fromJson(json, ArtifactDefinition.class);
233 * atifact.setArtifactName(UPLOAD_ARTIFACT_NAME);
234 * artifact.setArtifactDisplayName("configure");
235 * artifact.setArtifactType("SHELL"); artifact.setMandatory(false);
236 * artifact.setDescription("ff");
237 * artifact.setPayloadData(UPLOAD_ARTIFACT_PAYLOAD);
238 * artifact.setArtifactLabel("configure");
243 protected HttpGet createGetRequest(String url) {
244 HttpGet httpGet = new HttpGet(url);
245 httpGet.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
246 httpGet.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
247 httpGet.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
251 protected String getArtifactUid(HttpResponse response) throws HttpResponseException, IOException, ParseException {
252 String responseString = new BasicResponseHandler().handleResponse(response);
253 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
254 String artifactId = (String) responseMap.get("uniqueId");
258 protected String getArtifactEsId(HttpResponse response) throws HttpResponseException, IOException, ParseException {
259 String responseString = new BasicResponseHandler().handleResponse(response);
260 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
261 String esId = (String) responseMap.get("EsId");
265 protected ArtifactDefinition addArtifactDataFromResponse(HttpResponse response, ArtifactDefinition artifact)
266 throws HttpResponseException, IOException, ParseException {
267 // String responseString = new
268 // BasicResponseHandler().handleResponse(response);
269 HttpEntity entity = response.getEntity();
270 String responseString = EntityUtils.toString(entity);
271 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
272 artifact.setEsId((String) responseMap.get("esId"));
273 artifact.setUniqueId((String) responseMap.get("uniqueId"));
274 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.findType((String) responseMap.get("artifactGroupType")));
275 artifact.setTimeout(((Long) responseMap.get("timeout")).intValue());
279 protected String getLifecycleArtifactUid(CloseableHttpResponse response)
280 throws HttpResponseException, IOException, ParseException {
281 String responseString = new BasicResponseHandler().handleResponse(response);
282 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
283 responseMap = (JSONObject) responseMap.get("implementation");
284 String artifactId = (String) responseMap.get("uniqueId");
288 protected HttpDelete createDeleteArtifactRequest(String url) {
289 HttpDelete httpDelete = new HttpDelete(url);
290 httpDelete.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
291 httpDelete.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
295 protected HttpPost createPostAddArtifactRequeast(String jsonBody, String url, boolean addMd5Header)
296 throws UnsupportedEncodingException {
297 HttpPost httppost = new HttpPost(url);
298 httppost.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
299 httppost.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
300 httppost.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
302 httppost.addHeader(HttpHeaderEnum.Content_MD5.getValue(), GeneralUtility.calculateMD5Base64EncodedByString(jsonBody));
304 StringEntity input = new StringEntity(jsonBody);
305 input.setContentType("application/json");
306 httppost.setEntity(input);
307 log.debug("Executing request {}", httppost.getRequestLine());
311 protected String createLoadArtifactBody() {
312 Map<String, Object> json = new HashMap<String, Object>();
313 json.put("artifactName", "install_apache2.sh");
314 json.put("artifactType", "SHELL");
315 json.put("description", "ddd");
316 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
317 json.put("artifactLabel", "name123");
319 String jsonStr = gson.toJson(json);
323 protected void checkDeleteResponse(RestResponse response) {
324 BaseRestUtils.checkStatusCode(response, "delete request failed", false, 204, 404);
327 protected ArtifactUiDownloadData getArtifactUiDownloadData(String artifactUiDownloadDataStr) throws Exception {
329 ObjectMapper mapper = new ObjectMapper();
331 ArtifactUiDownloadData artifactUiDownloadData = mapper.readValue(artifactUiDownloadDataStr,
332 ArtifactUiDownloadData.class);
333 return artifactUiDownloadData;
334 } catch (Exception e) {
343 public void addArtifactNoPayLoadToResourcseTest() throws Exception {
344 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
345 defaultArtifact.setPayload(null);
347 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
348 resourceDetailsVFCcomp.getUniqueId());
349 int status = response.getErrorCode();
350 AssertJUnit.assertTrue(status == 400);
355 public void upadteArtifactNoPayLoadToResourcseTest() throws Exception {
357 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
359 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
360 resourceDetailsVFCcomp.getUniqueId());
361 int status = response.getErrorCode();
362 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
365 defaultArtifact.setDescription("kjglkh");
366 defaultArtifact.setArtifactName("install_apache.sh");
367 defaultArtifact.setArtifactType("SHELL");
368 defaultArtifact.setPayload(null);
370 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
371 resourceDetailsVFCcomp.getUniqueId());
372 status = response.getErrorCode();
373 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
375 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
376 defaultArtifact, sdncUserDetails);
377 status = response.getErrorCode();
378 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
383 @Test(enabled = false)
384 public void updateDeploymentArtifactToResourcseTest() throws Exception {
386 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultDeploymentArtifactForType("HEAT");
388 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
389 resourceDetailsVFCcomp.getUniqueId());
390 int status = response.getErrorCode();
391 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
394 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
395 resourceDetailsVFCcomp.getUniqueId());
396 status = response.getErrorCode();
397 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
399 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
400 defaultArtifact, sdncUserDetails);
401 status = response.getErrorCode();
402 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
406 // --------------------
408 public void addArtifactToResourcse_AlreadyExistsTest() throws Exception {
409 CloseableHttpClient httpclient = HttpClients.createDefault();
411 String jsonBody = createLoadArtifactBody();
413 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
414 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
415 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
416 CloseableHttpResponse response = httpclient.execute(httppost);
417 int status = response.getStatusLine().getStatusCode();
418 AssertJUnit.assertTrue("failed to add artifact", status == 200);
420 String artifactId = getArtifactUid(response);
422 httppost = createPostAddArtifactRequeast(jsonBody, url, true);
423 response = httpclient.execute(httppost);
424 status = response.getStatusLine().getStatusCode();
425 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
427 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
428 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), artifactId);
429 HttpDelete httpDelete = createDeleteArtifactRequest(url);
430 response = httpclient.execute(httpDelete);
431 status = response.getStatusLine().getStatusCode();
432 AssertJUnit.assertTrue("failed to remove artifact", status == 200);
440 public void addArtifactToResourcse_MissingContentTest() throws Exception {
442 CloseableHttpClient httpclient = HttpClients.createDefault();
444 Map<String, Object> json = new HashMap<String, Object>();
445 json.put("description", "desc");
446 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
447 json.put("Content-MD5", "YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI=");
449 String jsonBody = gson.toJson(json);
451 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
452 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
453 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
454 CloseableHttpResponse response = httpclient.execute(httppost);
455 int status = response.getStatusLine().getStatusCode();
456 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
464 public void addArtifactToResourcse_MissingMd5Test() throws Exception {
466 CloseableHttpClient httpclient = HttpClients.createDefault();
468 HashMap<String, Object> json = new HashMap<String, Object>();
469 json.put("artifactName", "install_apache.sh");
470 json.put("artifactType", "SHELL");
471 json.put("description", "kjglkh");
472 json.put("payloadData", "UEsDBYTEIWUYIFHWFMABCNAoAAAAIAAeLb0bDQz");
473 json.put("artifactLabel", "name123");
474 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
475 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
476 String jsonBody = gson.toJson(json);
477 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, false);
478 CloseableHttpResponse response = httpclient.execute(httppost);
479 int status = response.getStatusLine().getStatusCode();
480 AssertJUnit.assertTrue("failed to update artifact metatdata", status == 400);
488 public void deleteArtifact_NotExistsTest() throws Exception {
489 CloseableHttpClient httpclient = HttpClients.createDefault();
491 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
492 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), "someFakeId");
493 HttpDelete httpDelete = createDeleteArtifactRequest(url);
494 CloseableHttpResponse response = httpclient.execute(httpDelete);
495 int status = response.getStatusLine().getStatusCode();
496 AssertJUnit.assertEquals("the returned status code is in correct", status, 404);
504 public void createAndRemoveArtifactToInterface() throws Exception {
505 CloseableHttpResponse response;
507 CloseableHttpClient httpclient = HttpClients.createDefault();
510 // upload artifact to interface
511 String interfaceName = "Standard";
512 String operationName = "configure";
514 String userBodyJson = createUploadArtifactBodyJson();
515 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
516 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
518 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
519 response = httpclient.execute(httpPost);
520 status = response.getStatusLine().getStatusCode();
521 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
523 // get artifact uniqueId
524 String artifactId = getLifecycleArtifactUid(response);
527 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
528 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
530 HttpDelete httpDelete = createDeleteArtifactRequest(url);
532 response = httpclient.execute(httpDelete);
533 status = response.getStatusLine().getStatusCode();
534 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
542 public void addArtifactToServiceTest() throws Exception {
544 CloseableHttpClient httpclient = HttpClients.createDefault();
547 String jsonStr = createLoadArtifactBody();
549 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
550 config.getCatalogBePort(), defaultService1.getUniqueId());
551 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
552 CloseableHttpResponse result = httpclient.execute(httpPost);
553 int status = result.getStatusLine().getStatusCode();
554 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
556 String artifactId = getArtifactUid(result);
558 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),
559 config.getCatalogBePort(), defaultService1.getUniqueId(), artifactId);
560 HttpDelete httpDelete = createDeleteArtifactRequest(url);
562 result = httpclient.execute(httpDelete);
563 status = result.getStatusLine().getStatusCode();
564 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
566 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
568 checkDeleteResponse(response);
574 public void addArtifactNotSupportedTypeToServiceTest() throws Exception {
575 CloseableHttpClient httpclient = HttpClients.createDefault();
577 Map<String, Object> json = new HashMap<String, Object>();
578 json.put("artifactName", "install_apache.sh");
579 json.put("artifactType", "SHELL11");
580 json.put("description", "fff");
581 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
582 json.put("artifactLabel", "name123");
584 String jsonStr = gson.toJson(json);
586 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
587 config.getCatalogBePort(), defaultService1.getUniqueId());
589 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
590 CloseableHttpResponse result = httpclient.execute(httpPost);
591 int status = result.getStatusLine().getStatusCode();
592 AssertJUnit.assertEquals("response code is not 400, returned :" + status, 400, status);
594 ErrorInfo errorInfo = ErrorValidationUtils
595 .parseErrorConfigYaml(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED.name());
597 String responseString = EntityUtils.toString(result.getEntity());
599 JSONObject map = (JSONObject) jsonParser.parse(responseString);
600 JSONObject requestError = (JSONObject) map.get("requestError");
601 JSONObject serviceException = (JSONObject) requestError.get("serviceException");
603 String msgId = (String) serviceException.get("messageId");
604 AssertJUnit.assertEquals("message id did not match expacted", errorInfo.getMessageId(), msgId);
606 String text = (String) serviceException.get("text");
607 AssertJUnit.assertEquals("text did not match expacted", errorInfo.getMessage(), text);
609 JSONArray variables = (JSONArray) serviceException.get("variables");
610 String type = (String) variables.get(0);
611 AssertJUnit.assertEquals("variable did not match expacted", "SHELL11", type);
613 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
615 checkDeleteResponse(response);
622 public void addArtifactToResourceTest() throws Exception {
624 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
626 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
627 resourceDetailsVFCcomp.getUniqueId());
628 int status = response.getErrorCode();
629 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
632 RestResponse resourceResp = ResourceRestUtils.getResource(resourceDetailsVFCcomp.getUniqueId());
633 Resource resource = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
634 AssertJUnit.assertNotNull(resource);
636 Map<String, ArtifactDefinition> artifacts = resource.getArtifacts();
637 boolean isExist = false;
638 for (Map.Entry<String, ArtifactDefinition> entry : artifacts.entrySet()) {
639 if (entry.getKey().equals(defaultArtifact.getArtifactLabel())) {
644 AssertJUnit.assertTrue(isExist);