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 java.io.IOException;
24 import java.io.UnsupportedEncodingException;
25 import java.util.HashMap;
28 import org.apache.http.HttpEntity;
29 import org.apache.http.HttpResponse;
30 import org.apache.http.client.HttpResponseException;
31 import org.apache.http.client.methods.CloseableHttpResponse;
32 import org.apache.http.client.methods.HttpDelete;
33 import org.apache.http.client.methods.HttpGet;
34 import org.apache.http.client.methods.HttpPost;
35 import org.apache.http.entity.StringEntity;
36 import org.apache.http.impl.client.BasicResponseHandler;
37 import org.apache.http.impl.client.CloseableHttpClient;
38 import org.apache.http.impl.client.HttpClients;
39 import org.apache.http.util.EntityUtils;
40 import org.codehaus.jackson.map.ObjectMapper;
41 import org.json.simple.JSONArray;
42 import org.json.simple.JSONObject;
43 import org.json.simple.parser.JSONParser;
44 import org.json.simple.parser.ParseException;
45 import org.junit.Rule;
46 import org.junit.rules.TestName;
47 import org.openecomp.sdc.be.dao.api.ActionStatus;
48 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
49 import org.openecomp.sdc.be.model.ArtifactDefinition;
50 import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
51 import org.openecomp.sdc.be.model.Resource;
52 import org.openecomp.sdc.be.model.Service;
53 import org.openecomp.sdc.be.model.User;
54 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
55 import org.openecomp.sdc.ci.tests.api.Urls;
56 import org.openecomp.sdc.ci.tests.config.Config;
57 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
58 import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
59 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
60 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
61 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
62 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
63 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
64 import org.openecomp.sdc.ci.tests.utils.Utils;
65 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
66 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
67 import org.openecomp.sdc.ci.tests.utils.general.FileUtils;
68 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
69 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
70 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
71 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
72 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
73 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
74 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
75 import org.openecomp.sdc.common.util.GeneralUtility;
76 import org.slf4j.Logger;
77 import org.slf4j.LoggerFactory;
78 import org.testng.AssertJUnit;
79 import org.testng.annotations.BeforeMethod;
80 import org.testng.annotations.Test;
82 import com.google.gson.Gson;
84 import fj.data.Either;
86 public class ArtifactServletTest extends ComponentBaseTest {
88 private static Logger log = LoggerFactory.getLogger(ArtifactServletTest.class.getName());
89 protected static final String UPLOAD_ARTIFACT_PAYLOAD = "UHVUVFktVXNlci1LZXktRmlsZS0yOiBzc2gtcnNhDQpFbmNyeXB0aW9uOiBhZXMyNTYtY2JjDQpDb21tZW5wOA0K";
90 protected static final String UPLOAD_ARTIFACT_NAME = "TLV_prv.ppk";
91 protected Config config = Config.instance();
92 protected String contentTypeHeaderData = "application/json";
93 protected String acceptHeaderDate = "application/json";
94 protected Gson gson = new Gson();
95 protected JSONParser jsonParser = new JSONParser();
96 protected String serviceVersion;
97 protected Resource resourceDetailsVFCcomp;
98 protected Service defaultService1;
100 protected User sdncUserDetails;
103 public static TestName name = new TestName();
105 public ArtifactServletTest() {
106 super(name, ArtifactServletTest.class.getName());
111 public void create() throws Exception {
113 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
114 Either<Resource, RestResponse> resourceDetailsVFCcompE = AtomicOperationUtils
115 .createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.COMPUTE,
116 ResourceCategoryEnum.APPLICATION_L4_APP_SERVER, UserRoleEnum.DESIGNER, true);
117 resourceDetailsVFCcomp = resourceDetailsVFCcompE.left().value();
118 Either<Service, RestResponse> defaultService1e = AtomicOperationUtils
119 .createDefaultService(UserRoleEnum.DESIGNER, true);
120 defaultService1 = defaultService1e.left().value();
124 public void upadteArtifactWithPayLoadToResourcseTest() throws Exception {
126 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
128 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
129 resourceDetailsVFCcomp.getUniqueId());
130 int status = response.getErrorCode();
131 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
134 defaultArtifact.setDescription("kjglkh");
135 defaultArtifact.setArtifactName("install_apache.sh");
136 defaultArtifact.setArtifactType("SHELL");
137 defaultArtifact.setPayload("new payload");
139 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
140 resourceDetailsVFCcomp.getUniqueId());
141 status = response.getErrorCode();
142 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
144 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
145 defaultArtifact, sdncUserDetails);
146 status = response.getErrorCode();
147 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
152 public void createAndUpdateArtifactToInterface() throws Exception {
154 CloseableHttpResponse response;
156 CloseableHttpClient httpclient = HttpClients.createDefault();
159 // upload artifact to interface
160 String interfaceName = "Standard";
161 String operationName = "configure";
163 String userBodyJson = createUploadArtifactBodyJson();
164 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
165 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
167 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
168 response = httpclient.execute(httpPost);
169 status = response.getStatusLine().getStatusCode();
170 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
172 // get artifact uniqueId
173 String artifactId = getLifecycleArtifactUid(response);
175 Map<String, Object> jsonBody = new HashMap<String, Object>();
176 jsonBody.put("artifactName", "TLV_prv.ppk");
177 jsonBody.put("artifactDisplayName", "configure");
178 jsonBody.put("artifactType", "SHELL");
179 jsonBody.put("mandatory", "false");
180 String newDescription = "new something";
181 jsonBody.put("description", newDescription);
182 jsonBody.put("artifactLabel", "configure");
183 userBodyJson = gson.toJson(jsonBody);
185 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
186 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
189 httpPost = createPostAddArtifactRequeast(userBodyJson, url, false);
191 response = httpclient.execute(httpPost);
192 status = response.getStatusLine().getStatusCode();
193 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
195 url = String.format(Urls.GET_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(),
196 resourceDetailsVFCcomp.getUniqueId());
197 HttpGet httpGet = createGetRequest(url);
198 response = httpclient.execute(httpGet);
199 AssertJUnit.assertTrue(response.getStatusLine().getStatusCode() == 200);
200 String responseString = new BasicResponseHandler().handleResponse(response);
202 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
203 responseMap = (JSONObject) responseMap.get("interfaces");
204 responseMap = (JSONObject) responseMap.get(interfaceName.toLowerCase());
205 responseMap = (JSONObject) responseMap.get("operations");
206 responseMap = (JSONObject) responseMap.get(operationName.toLowerCase());
207 responseMap = (JSONObject) responseMap.get("implementation");
208 String description = (String) responseMap.get("description");
210 AssertJUnit.assertEquals("the new description value was not set", newDescription, description);
213 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
214 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
216 HttpDelete httpDelete = createDeleteArtifactRequest(url);
218 response = httpclient.execute(httpDelete);
219 status = response.getStatusLine().getStatusCode();
220 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
227 protected String createUploadArtifactBodyJson() {
228 Map<String, Object> jsonBody = new HashMap<String, Object>();
229 jsonBody.put("artifactName", UPLOAD_ARTIFACT_NAME);
230 jsonBody.put("artifactDisplayName", "configure");
231 jsonBody.put("artifactType", "SHELL");
232 jsonBody.put("mandatory", "false");
233 jsonBody.put("description", "ff");
234 jsonBody.put("payloadData", UPLOAD_ARTIFACT_PAYLOAD);
235 jsonBody.put("artifactLabel", "configure");
236 return gson.toJson(jsonBody);
239 protected ArtifactDefinition getArtifactDataFromJson(String json) {
240 Gson gson = new Gson();
241 ArtifactDefinition artifact = new ArtifactDefinition();
242 artifact = gson.fromJson(json, ArtifactDefinition.class);
245 * atifact.setArtifactName(UPLOAD_ARTIFACT_NAME);
246 * artifact.setArtifactDisplayName("configure");
247 * artifact.setArtifactType("SHELL"); artifact.setMandatory(false);
248 * artifact.setDescription("ff");
249 * artifact.setPayloadData(UPLOAD_ARTIFACT_PAYLOAD);
250 * artifact.setArtifactLabel("configure");
255 protected HttpGet createGetRequest(String url) {
256 HttpGet httpGet = new HttpGet(url);
257 httpGet.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
258 httpGet.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
259 httpGet.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
263 protected String getArtifactUid(HttpResponse response) throws HttpResponseException, IOException, ParseException {
264 String responseString = new BasicResponseHandler().handleResponse(response);
265 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
266 String artifactId = (String) responseMap.get("uniqueId");
270 protected String getArtifactEsId(HttpResponse response) throws HttpResponseException, IOException, ParseException {
271 String responseString = new BasicResponseHandler().handleResponse(response);
272 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
273 String esId = (String) responseMap.get("EsId");
277 protected ArtifactDefinition addArtifactDataFromResponse(HttpResponse response, ArtifactDefinition artifact)
278 throws HttpResponseException, IOException, ParseException {
279 // String responseString = new
280 // BasicResponseHandler().handleResponse(response);
281 HttpEntity entity = response.getEntity();
282 String responseString = EntityUtils.toString(entity);
283 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
284 artifact.setEsId((String) responseMap.get("esId"));
285 artifact.setUniqueId((String) responseMap.get("uniqueId"));
286 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.findType((String) responseMap.get("artifactGroupType")));
287 artifact.setTimeout(((Long) responseMap.get("timeout")).intValue());
291 protected String getLifecycleArtifactUid(CloseableHttpResponse response)
292 throws HttpResponseException, IOException, ParseException {
293 String responseString = new BasicResponseHandler().handleResponse(response);
294 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
295 responseMap = (JSONObject) responseMap.get("implementation");
296 String artifactId = (String) responseMap.get("uniqueId");
300 protected HttpDelete createDeleteArtifactRequest(String url) {
301 HttpDelete httpDelete = new HttpDelete(url);
302 httpDelete.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
303 httpDelete.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
307 protected HttpPost createPostAddArtifactRequeast(String jsonBody, String url, boolean addMd5Header)
308 throws UnsupportedEncodingException {
309 HttpPost httppost = new HttpPost(url);
310 httppost.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
311 httppost.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
312 httppost.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
314 httppost.addHeader(HttpHeaderEnum.Content_MD5.getValue(), GeneralUtility.calculateMD5ByString(jsonBody));
316 StringEntity input = new StringEntity(jsonBody);
317 input.setContentType("application/json");
318 httppost.setEntity(input);
319 log.debug("Executing request {}", httppost.getRequestLine());
323 protected String createLoadArtifactBody() {
324 Map<String, Object> json = new HashMap<String, Object>();
325 json.put("artifactName", "install_apache2.sh");
326 json.put("artifactType", "SHELL");
327 json.put("description", "ddd");
328 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
329 json.put("artifactLabel", "name123");
331 String jsonStr = gson.toJson(json);
335 protected void checkDeleteResponse(RestResponse response) {
336 BaseRestUtils.checkStatusCode(response, "delete request failed", false, 204, 404);
339 protected ArtifactUiDownloadData getArtifactUiDownloadData(String artifactUiDownloadDataStr) throws Exception {
341 ObjectMapper mapper = new ObjectMapper();
343 ArtifactUiDownloadData artifactUiDownloadData = mapper.readValue(artifactUiDownloadDataStr,
344 ArtifactUiDownloadData.class);
345 return artifactUiDownloadData;
346 } catch (Exception e) {
355 public void addArtifactNoPayLoadToResourcseTest() throws Exception {
356 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
357 defaultArtifact.setPayload(null);
359 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
360 resourceDetailsVFCcomp.getUniqueId());
361 int status = response.getErrorCode();
362 AssertJUnit.assertTrue(status == 400);
367 public void upadteArtifactNoPayLoadToResourcseTest() throws Exception {
369 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
371 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
372 resourceDetailsVFCcomp.getUniqueId());
373 int status = response.getErrorCode();
374 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
377 defaultArtifact.setDescription("kjglkh");
378 defaultArtifact.setArtifactName("install_apache.sh");
379 defaultArtifact.setArtifactType("SHELL");
380 defaultArtifact.setPayload(null);
382 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
383 resourceDetailsVFCcomp.getUniqueId());
384 status = response.getErrorCode();
385 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
387 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
388 defaultArtifact, sdncUserDetails);
389 status = response.getErrorCode();
390 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
395 @Test(enabled = false)
396 public void updateDeploymentArtifactToResourcseTest() throws Exception {
398 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultDeploymentArtifactForType("HEAT");
400 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
401 resourceDetailsVFCcomp.getUniqueId());
402 int status = response.getErrorCode();
403 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
406 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
407 resourceDetailsVFCcomp.getUniqueId());
408 status = response.getErrorCode();
409 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
411 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
412 defaultArtifact, sdncUserDetails);
413 status = response.getErrorCode();
414 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
418 // --------------------
420 public void addArtifactToResourcse_AlreadyExistsTest() throws Exception {
421 CloseableHttpClient httpclient = HttpClients.createDefault();
423 String jsonBody = createLoadArtifactBody();
425 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
426 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
427 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
428 CloseableHttpResponse response = httpclient.execute(httppost);
429 int status = response.getStatusLine().getStatusCode();
430 AssertJUnit.assertTrue("failed to add artifact", status == 200);
432 String artifactId = getArtifactUid(response);
434 httppost = createPostAddArtifactRequeast(jsonBody, url, true);
435 response = httpclient.execute(httppost);
436 status = response.getStatusLine().getStatusCode();
437 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
439 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
440 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), artifactId);
441 HttpDelete httpDelete = createDeleteArtifactRequest(url);
442 response = httpclient.execute(httpDelete);
443 status = response.getStatusLine().getStatusCode();
444 AssertJUnit.assertTrue("failed to remove artifact", status == 200);
452 public void addArtifactToResourcse_MissingContentTest() throws Exception {
454 CloseableHttpClient httpclient = HttpClients.createDefault();
456 Map<String, Object> json = new HashMap<String, Object>();
457 json.put("description", "desc");
458 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
459 json.put("Content-MD5", "YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI=");
461 String jsonBody = gson.toJson(json);
463 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
464 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
465 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
466 CloseableHttpResponse response = httpclient.execute(httppost);
467 int status = response.getStatusLine().getStatusCode();
468 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
476 public void addArtifactToResourcse_MissingMd5Test() throws Exception {
478 CloseableHttpClient httpclient = HttpClients.createDefault();
480 HashMap<String, Object> json = new HashMap<String, Object>();
481 json.put("artifactName", "install_apache.sh");
482 json.put("artifactType", "SHELL");
483 json.put("description", "kjglkh");
484 json.put("payloadData", "UEsDBYTEIWUYIFHWFMABCNAoAAAAIAAeLb0bDQz");
485 json.put("artifactLabel", "name123");
486 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
487 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
488 String jsonBody = gson.toJson(json);
489 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, false);
490 CloseableHttpResponse response = httpclient.execute(httppost);
491 int status = response.getStatusLine().getStatusCode();
492 AssertJUnit.assertTrue("failed to update artifact metatdata", status == 400);
500 public void deleteArtifact_NotExistsTest() throws Exception {
501 CloseableHttpClient httpclient = HttpClients.createDefault();
503 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
504 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), "someFakeId");
505 HttpDelete httpDelete = createDeleteArtifactRequest(url);
506 CloseableHttpResponse response = httpclient.execute(httpDelete);
507 int status = response.getStatusLine().getStatusCode();
508 AssertJUnit.assertEquals("the returned status code is in correct", status, 404);
516 public void createAndRemoveArtifactToInterface() throws Exception {
517 CloseableHttpResponse response;
519 CloseableHttpClient httpclient = HttpClients.createDefault();
522 // upload artifact to interface
523 String interfaceName = "Standard";
524 String operationName = "configure";
526 String userBodyJson = createUploadArtifactBodyJson();
527 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
528 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
530 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
531 response = httpclient.execute(httpPost);
532 status = response.getStatusLine().getStatusCode();
533 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
535 // get artifact uniqueId
536 String artifactId = getLifecycleArtifactUid(response);
539 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
540 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
542 HttpDelete httpDelete = createDeleteArtifactRequest(url);
544 response = httpclient.execute(httpDelete);
545 status = response.getStatusLine().getStatusCode();
546 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
554 public void addArtifactToServiceTest() throws Exception {
556 CloseableHttpClient httpclient = HttpClients.createDefault();
559 String jsonStr = createLoadArtifactBody();
561 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
562 config.getCatalogBePort(), defaultService1.getUniqueId());
563 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
564 CloseableHttpResponse result = httpclient.execute(httpPost);
565 int status = result.getStatusLine().getStatusCode();
566 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
568 String artifactId = getArtifactUid(result);
570 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),
571 config.getCatalogBePort(), defaultService1.getUniqueId(), artifactId);
572 HttpDelete httpDelete = createDeleteArtifactRequest(url);
574 result = httpclient.execute(httpDelete);
575 status = result.getStatusLine().getStatusCode();
576 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
578 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
580 checkDeleteResponse(response);
586 public void addArtifactNotSupportedTypeToServiceTest() throws Exception {
587 CloseableHttpClient httpclient = HttpClients.createDefault();
589 Map<String, Object> json = new HashMap<String, Object>();
590 json.put("artifactName", "install_apache.sh");
591 json.put("artifactType", "SHELL11");
592 json.put("description", "fff");
593 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
594 json.put("artifactLabel", "name123");
596 String jsonStr = gson.toJson(json);
598 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
599 config.getCatalogBePort(), defaultService1.getUniqueId());
601 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
602 CloseableHttpResponse result = httpclient.execute(httpPost);
603 int status = result.getStatusLine().getStatusCode();
604 AssertJUnit.assertEquals("response code is not 400, returned :" + status, 400, status);
606 ErrorInfo errorInfo = ErrorValidationUtils
607 .parseErrorConfigYaml(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED.name());
609 String responseString = EntityUtils.toString(result.getEntity());
611 JSONObject map = (JSONObject) jsonParser.parse(responseString);
612 JSONObject requestError = (JSONObject) map.get("requestError");
613 JSONObject serviceException = (JSONObject) requestError.get("serviceException");
615 String msgId = (String) serviceException.get("messageId");
616 AssertJUnit.assertEquals("message id did not match expacted", errorInfo.getMessageId(), msgId);
618 String text = (String) serviceException.get("text");
619 AssertJUnit.assertEquals("text did not match expacted", errorInfo.getMessage(), text);
621 JSONArray variables = (JSONArray) serviceException.get("variables");
622 String type = (String) variables.get(0);
623 AssertJUnit.assertEquals("variable did not match expacted", "SHELL11", type);
625 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
627 checkDeleteResponse(response);
634 public void addArtifactToResourceTest() throws Exception {
636 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
638 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
639 resourceDetailsVFCcomp.getUniqueId());
640 int status = response.getErrorCode();
641 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
644 RestResponse resourceResp = ResourceRestUtils.getResource(resourceDetailsVFCcomp.getUniqueId());
645 Resource resource = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
646 AssertJUnit.assertNotNull(resource);
648 Map<String, ArtifactDefinition> artifacts = resource.getArtifacts();
649 boolean isExist = false;
650 for (Map.Entry<String, ArtifactDefinition> entry : artifacts.entrySet()) {
651 if (entry.getKey().equals(defaultArtifact.getArtifactLabel())) {
656 AssertJUnit.assertTrue(isExist);