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.general.AtomicOperationUtils;
65 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
66 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
67 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
68 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
69 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
70 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
71 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
72 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
73 import org.openecomp.sdc.common.util.GeneralUtility;
74 import org.slf4j.Logger;
75 import org.slf4j.LoggerFactory;
76 import org.testng.AssertJUnit;
77 import org.testng.annotations.BeforeMethod;
78 import org.testng.annotations.Test;
80 import com.google.gson.Gson;
82 import fj.data.Either;
84 public class ArtifactServletTest extends ComponentBaseTest {
86 private static Logger log = LoggerFactory.getLogger(ArtifactServletTest.class.getName());
87 protected static final String UPLOAD_ARTIFACT_PAYLOAD = "UHVUVFktVXNlci1LZXktRmlsZS0yOiBzc2gtcnNhDQpFbmNyeXB0aW9uOiBhZXMyNTYtY2JjDQpDb21tZW5wOA0K";
88 protected static final String UPLOAD_ARTIFACT_NAME = "TLV_prv.ppk";
89 protected Config config = Config.instance();
90 protected String contentTypeHeaderData = "application/json";
91 protected String acceptHeaderDate = "application/json";
92 protected Gson gson = new Gson();
93 protected JSONParser jsonParser = new JSONParser();
94 protected String serviceVersion;
95 protected Resource resourceDetailsVFCcomp;
96 protected Service defaultService1;
98 protected User sdncUserDetails;
101 public static TestName name = new TestName();
103 public ArtifactServletTest() {
104 super(name, ArtifactServletTest.class.getName());
109 public void create() throws Exception {
111 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
112 Either<Resource, RestResponse> resourceDetailsVFCcompE = AtomicOperationUtils
113 .createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.COMPUTE,
114 ResourceCategoryEnum.APPLICATION_L4_APP_SERVER, UserRoleEnum.DESIGNER, true);
115 resourceDetailsVFCcomp = resourceDetailsVFCcompE.left().value();
116 Either<Service, RestResponse> defaultService1e = AtomicOperationUtils
117 .createDefaultService(UserRoleEnum.DESIGNER, true);
118 defaultService1 = defaultService1e.left().value();
122 public void upadteArtifactWithPayLoadToResourcseTest() throws Exception {
124 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
126 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
127 resourceDetailsVFCcomp.getUniqueId());
128 int status = response.getErrorCode();
129 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
132 defaultArtifact.setDescription("kjglkh");
133 defaultArtifact.setArtifactName("install_apache.sh");
134 defaultArtifact.setArtifactType("SHELL");
135 defaultArtifact.setPayload("new payload");
137 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
138 resourceDetailsVFCcomp.getUniqueId());
139 status = response.getErrorCode();
140 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
142 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
143 defaultArtifact, sdncUserDetails);
144 status = response.getErrorCode();
145 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
150 public void createAndUpdateArtifactToInterface() throws Exception {
152 CloseableHttpResponse response;
154 CloseableHttpClient httpclient = HttpClients.createDefault();
157 // upload artifact to interface
158 String interfaceName = "Standard";
159 String operationName = "configure";
161 String userBodyJson = createUploadArtifactBodyJson();
162 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
163 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
165 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
166 response = httpclient.execute(httpPost);
167 status = response.getStatusLine().getStatusCode();
168 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
170 // get artifact uniqueId
171 String artifactId = getLifecycleArtifactUid(response);
173 Map<String, Object> jsonBody = new HashMap<String, Object>();
174 jsonBody.put("artifactName", "TLV_prv.ppk");
175 jsonBody.put("artifactDisplayName", "configure");
176 jsonBody.put("artifactType", "SHELL");
177 jsonBody.put("mandatory", "false");
178 String newDescription = "new something";
179 jsonBody.put("description", newDescription);
180 jsonBody.put("artifactLabel", "configure");
181 userBodyJson = gson.toJson(jsonBody);
183 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
184 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
187 httpPost = createPostAddArtifactRequeast(userBodyJson, url, false);
189 response = httpclient.execute(httpPost);
190 status = response.getStatusLine().getStatusCode();
191 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
193 url = String.format(Urls.GET_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(),
194 resourceDetailsVFCcomp.getUniqueId());
195 HttpGet httpGet = createGetRequest(url);
196 response = httpclient.execute(httpGet);
197 AssertJUnit.assertTrue(response.getStatusLine().getStatusCode() == 200);
198 String responseString = new BasicResponseHandler().handleResponse(response);
200 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
201 responseMap = (JSONObject) responseMap.get("interfaces");
202 responseMap = (JSONObject) responseMap.get(interfaceName.toLowerCase());
203 responseMap = (JSONObject) responseMap.get("operations");
204 responseMap = (JSONObject) responseMap.get(operationName.toLowerCase());
205 responseMap = (JSONObject) responseMap.get("implementation");
206 String description = (String) responseMap.get("description");
208 AssertJUnit.assertEquals("the new description value was not set", newDescription, description);
211 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
212 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
214 HttpDelete httpDelete = createDeleteArtifactRequest(url);
216 response = httpclient.execute(httpDelete);
217 status = response.getStatusLine().getStatusCode();
218 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
225 protected String createUploadArtifactBodyJson() {
226 Map<String, Object> jsonBody = new HashMap<String, Object>();
227 jsonBody.put("artifactName", UPLOAD_ARTIFACT_NAME);
228 jsonBody.put("artifactDisplayName", "configure");
229 jsonBody.put("artifactType", "SHELL");
230 jsonBody.put("mandatory", "false");
231 jsonBody.put("description", "ff");
232 jsonBody.put("payloadData", UPLOAD_ARTIFACT_PAYLOAD);
233 jsonBody.put("artifactLabel", "configure");
234 return gson.toJson(jsonBody);
237 protected ArtifactDefinition getArtifactDataFromJson(String json) {
238 Gson gson = new Gson();
239 ArtifactDefinition artifact = new ArtifactDefinition();
240 artifact = gson.fromJson(json, ArtifactDefinition.class);
243 * atifact.setArtifactName(UPLOAD_ARTIFACT_NAME);
244 * artifact.setArtifactDisplayName("configure");
245 * artifact.setArtifactType("SHELL"); artifact.setMandatory(false);
246 * artifact.setDescription("ff");
247 * artifact.setPayloadData(UPLOAD_ARTIFACT_PAYLOAD);
248 * artifact.setArtifactLabel("configure");
253 protected HttpGet createGetRequest(String url) {
254 HttpGet httpGet = new HttpGet(url);
255 httpGet.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
256 httpGet.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
257 httpGet.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
261 protected String getArtifactUid(HttpResponse response) throws HttpResponseException, IOException, ParseException {
262 String responseString = new BasicResponseHandler().handleResponse(response);
263 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
264 String artifactId = (String) responseMap.get("uniqueId");
268 protected String getArtifactEsId(HttpResponse response) throws HttpResponseException, IOException, ParseException {
269 String responseString = new BasicResponseHandler().handleResponse(response);
270 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
271 String esId = (String) responseMap.get("EsId");
275 protected ArtifactDefinition addArtifactDataFromResponse(HttpResponse response, ArtifactDefinition artifact)
276 throws HttpResponseException, IOException, ParseException {
277 // String responseString = new
278 // BasicResponseHandler().handleResponse(response);
279 HttpEntity entity = response.getEntity();
280 String responseString = EntityUtils.toString(entity);
281 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
282 artifact.setEsId((String) responseMap.get("esId"));
283 artifact.setUniqueId((String) responseMap.get("uniqueId"));
284 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.findType((String) responseMap.get("artifactGroupType")));
285 artifact.setTimeout(((Long) responseMap.get("timeout")).intValue());
289 protected String getLifecycleArtifactUid(CloseableHttpResponse response)
290 throws HttpResponseException, IOException, ParseException {
291 String responseString = new BasicResponseHandler().handleResponse(response);
292 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
293 responseMap = (JSONObject) responseMap.get("implementation");
294 String artifactId = (String) responseMap.get("uniqueId");
298 protected HttpDelete createDeleteArtifactRequest(String url) {
299 HttpDelete httpDelete = new HttpDelete(url);
300 httpDelete.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
301 httpDelete.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
305 protected HttpPost createPostAddArtifactRequeast(String jsonBody, String url, boolean addMd5Header)
306 throws UnsupportedEncodingException {
307 HttpPost httppost = new HttpPost(url);
308 httppost.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
309 httppost.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
310 httppost.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
312 httppost.addHeader(HttpHeaderEnum.Content_MD5.getValue(), GeneralUtility.calculateMD5Base64EncodedByString(jsonBody));
314 StringEntity input = new StringEntity(jsonBody);
315 input.setContentType("application/json");
316 httppost.setEntity(input);
317 log.debug("Executing request {}", httppost.getRequestLine());
321 protected String createLoadArtifactBody() {
322 Map<String, Object> json = new HashMap<String, Object>();
323 json.put("artifactName", "install_apache2.sh");
324 json.put("artifactType", "SHELL");
325 json.put("description", "ddd");
326 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
327 json.put("artifactLabel", "name123");
329 String jsonStr = gson.toJson(json);
333 protected void checkDeleteResponse(RestResponse response) {
334 BaseRestUtils.checkStatusCode(response, "delete request failed", false, 204, 404);
337 protected ArtifactUiDownloadData getArtifactUiDownloadData(String artifactUiDownloadDataStr) throws Exception {
339 ObjectMapper mapper = new ObjectMapper();
341 ArtifactUiDownloadData artifactUiDownloadData = mapper.readValue(artifactUiDownloadDataStr,
342 ArtifactUiDownloadData.class);
343 return artifactUiDownloadData;
344 } catch (Exception e) {
353 public void addArtifactNoPayLoadToResourcseTest() throws Exception {
354 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
355 defaultArtifact.setPayload(null);
357 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
358 resourceDetailsVFCcomp.getUniqueId());
359 int status = response.getErrorCode();
360 AssertJUnit.assertTrue(status == 400);
365 public void upadteArtifactNoPayLoadToResourcseTest() throws Exception {
367 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
369 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
370 resourceDetailsVFCcomp.getUniqueId());
371 int status = response.getErrorCode();
372 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
375 defaultArtifact.setDescription("kjglkh");
376 defaultArtifact.setArtifactName("install_apache.sh");
377 defaultArtifact.setArtifactType("SHELL");
378 defaultArtifact.setPayload(null);
380 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
381 resourceDetailsVFCcomp.getUniqueId());
382 status = response.getErrorCode();
383 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
385 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
386 defaultArtifact, sdncUserDetails);
387 status = response.getErrorCode();
388 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
393 @Test(enabled = false)
394 public void updateDeploymentArtifactToResourcseTest() throws Exception {
396 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultDeploymentArtifactForType("HEAT");
398 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
399 resourceDetailsVFCcomp.getUniqueId());
400 int status = response.getErrorCode();
401 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
404 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
405 resourceDetailsVFCcomp.getUniqueId());
406 status = response.getErrorCode();
407 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
409 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
410 defaultArtifact, sdncUserDetails);
411 status = response.getErrorCode();
412 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
416 // --------------------
418 public void addArtifactToResourcse_AlreadyExistsTest() throws Exception {
419 CloseableHttpClient httpclient = HttpClients.createDefault();
421 String jsonBody = createLoadArtifactBody();
423 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
424 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
425 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
426 CloseableHttpResponse response = httpclient.execute(httppost);
427 int status = response.getStatusLine().getStatusCode();
428 AssertJUnit.assertTrue("failed to add artifact", status == 200);
430 String artifactId = getArtifactUid(response);
432 httppost = createPostAddArtifactRequeast(jsonBody, url, true);
433 response = httpclient.execute(httppost);
434 status = response.getStatusLine().getStatusCode();
435 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
437 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
438 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), artifactId);
439 HttpDelete httpDelete = createDeleteArtifactRequest(url);
440 response = httpclient.execute(httpDelete);
441 status = response.getStatusLine().getStatusCode();
442 AssertJUnit.assertTrue("failed to remove artifact", status == 200);
450 public void addArtifactToResourcse_MissingContentTest() throws Exception {
452 CloseableHttpClient httpclient = HttpClients.createDefault();
454 Map<String, Object> json = new HashMap<String, Object>();
455 json.put("description", "desc");
456 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
457 json.put("Content-MD5", "YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI=");
459 String jsonBody = gson.toJson(json);
461 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
462 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
463 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
464 CloseableHttpResponse response = httpclient.execute(httppost);
465 int status = response.getStatusLine().getStatusCode();
466 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
474 public void addArtifactToResourcse_MissingMd5Test() throws Exception {
476 CloseableHttpClient httpclient = HttpClients.createDefault();
478 HashMap<String, Object> json = new HashMap<String, Object>();
479 json.put("artifactName", "install_apache.sh");
480 json.put("artifactType", "SHELL");
481 json.put("description", "kjglkh");
482 json.put("payloadData", "UEsDBYTEIWUYIFHWFMABCNAoAAAAIAAeLb0bDQz");
483 json.put("artifactLabel", "name123");
484 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
485 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
486 String jsonBody = gson.toJson(json);
487 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, false);
488 CloseableHttpResponse response = httpclient.execute(httppost);
489 int status = response.getStatusLine().getStatusCode();
490 AssertJUnit.assertTrue("failed to update artifact metatdata", status == 400);
498 public void deleteArtifact_NotExistsTest() throws Exception {
499 CloseableHttpClient httpclient = HttpClients.createDefault();
501 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
502 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), "someFakeId");
503 HttpDelete httpDelete = createDeleteArtifactRequest(url);
504 CloseableHttpResponse response = httpclient.execute(httpDelete);
505 int status = response.getStatusLine().getStatusCode();
506 AssertJUnit.assertEquals("the returned status code is in correct", status, 404);
514 public void createAndRemoveArtifactToInterface() throws Exception {
515 CloseableHttpResponse response;
517 CloseableHttpClient httpclient = HttpClients.createDefault();
520 // upload artifact to interface
521 String interfaceName = "Standard";
522 String operationName = "configure";
524 String userBodyJson = createUploadArtifactBodyJson();
525 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
526 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
528 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
529 response = httpclient.execute(httpPost);
530 status = response.getStatusLine().getStatusCode();
531 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
533 // get artifact uniqueId
534 String artifactId = getLifecycleArtifactUid(response);
537 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
538 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
540 HttpDelete httpDelete = createDeleteArtifactRequest(url);
542 response = httpclient.execute(httpDelete);
543 status = response.getStatusLine().getStatusCode();
544 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
552 public void addArtifactToServiceTest() throws Exception {
554 CloseableHttpClient httpclient = HttpClients.createDefault();
557 String jsonStr = createLoadArtifactBody();
559 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
560 config.getCatalogBePort(), defaultService1.getUniqueId());
561 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
562 CloseableHttpResponse result = httpclient.execute(httpPost);
563 int status = result.getStatusLine().getStatusCode();
564 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
566 String artifactId = getArtifactUid(result);
568 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),
569 config.getCatalogBePort(), defaultService1.getUniqueId(), artifactId);
570 HttpDelete httpDelete = createDeleteArtifactRequest(url);
572 result = httpclient.execute(httpDelete);
573 status = result.getStatusLine().getStatusCode();
574 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
576 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
578 checkDeleteResponse(response);
584 public void addArtifactNotSupportedTypeToServiceTest() throws Exception {
585 CloseableHttpClient httpclient = HttpClients.createDefault();
587 Map<String, Object> json = new HashMap<String, Object>();
588 json.put("artifactName", "install_apache.sh");
589 json.put("artifactType", "SHELL11");
590 json.put("description", "fff");
591 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
592 json.put("artifactLabel", "name123");
594 String jsonStr = gson.toJson(json);
596 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
597 config.getCatalogBePort(), defaultService1.getUniqueId());
599 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
600 CloseableHttpResponse result = httpclient.execute(httpPost);
601 int status = result.getStatusLine().getStatusCode();
602 AssertJUnit.assertEquals("response code is not 400, returned :" + status, 400, status);
604 ErrorInfo errorInfo = ErrorValidationUtils
605 .parseErrorConfigYaml(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED.name());
607 String responseString = EntityUtils.toString(result.getEntity());
609 JSONObject map = (JSONObject) jsonParser.parse(responseString);
610 JSONObject requestError = (JSONObject) map.get("requestError");
611 JSONObject serviceException = (JSONObject) requestError.get("serviceException");
613 String msgId = (String) serviceException.get("messageId");
614 AssertJUnit.assertEquals("message id did not match expacted", errorInfo.getMessageId(), msgId);
616 String text = (String) serviceException.get("text");
617 AssertJUnit.assertEquals("text did not match expacted", errorInfo.getMessage(), text);
619 JSONArray variables = (JSONArray) serviceException.get("variables");
620 String type = (String) variables.get(0);
621 AssertJUnit.assertEquals("variable did not match expacted", "SHELL11", type);
623 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
625 checkDeleteResponse(response);
632 public void addArtifactToResourceTest() throws Exception {
634 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
636 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
637 resourceDetailsVFCcomp.getUniqueId());
638 int status = response.getErrorCode();
639 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
642 RestResponse resourceResp = ResourceRestUtils.getResource(resourceDetailsVFCcomp.getUniqueId());
643 Resource resource = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
644 AssertJUnit.assertNotNull(resource);
646 Map<String, ArtifactDefinition> artifacts = resource.getArtifacts();
647 boolean isExist = false;
648 for (Map.Entry<String, ArtifactDefinition> entry : artifacts.entrySet()) {
649 if (entry.getKey().equals(defaultArtifact.getArtifactLabel())) {
654 AssertJUnit.assertTrue(isExist);