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 com.fasterxml.jackson.databind.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.fasterxml.jackson.databind.ObjectMapper;
81 import com.google.gson.Gson;
83 import fj.data.Either;
85 public class ArtifactServletTest extends ComponentBaseTest {
87 private static Logger log = LoggerFactory.getLogger(ArtifactServletTest.class.getName());
88 protected static final String UPLOAD_ARTIFACT_PAYLOAD = "UHVUVFktVXNlci1LZXktRmlsZS0yOiBzc2gtcnNhDQpFbmNyeXB0aW9uOiBhZXMyNTYtY2JjDQpDb21tZW5wOA0K";
89 protected static final String UPLOAD_ARTIFACT_NAME = "TLV_prv.ppk";
90 protected Config config = Config.instance();
91 protected String contentTypeHeaderData = "application/json";
92 protected String acceptHeaderDate = "application/json";
93 protected Gson gson = new Gson();
94 protected JSONParser jsonParser = new JSONParser();
95 protected String serviceVersion;
96 protected Resource resourceDetailsVFCcomp;
97 protected Service defaultService1;
99 protected User sdncUserDetails;
102 public static TestName name = new TestName();
104 public ArtifactServletTest() {
105 super(name, ArtifactServletTest.class.getName());
110 public void create() throws Exception {
112 sdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
113 Either<Resource, RestResponse> resourceDetailsVFCcompE = AtomicOperationUtils
114 .createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC, NormativeTypesEnum.COMPUTE,
115 ResourceCategoryEnum.APPLICATION_L4_APP_SERVER, UserRoleEnum.DESIGNER, true);
116 resourceDetailsVFCcomp = resourceDetailsVFCcompE.left().value();
117 Either<Service, RestResponse> defaultService1e = AtomicOperationUtils
118 .createDefaultService(UserRoleEnum.DESIGNER, true);
119 defaultService1 = defaultService1e.left().value();
123 public void upadteArtifactWithPayLoadToResourcseTest() throws Exception {
125 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
127 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
128 resourceDetailsVFCcomp.getUniqueId());
129 int status = response.getErrorCode();
130 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
133 defaultArtifact.setDescription("kjglkh");
134 defaultArtifact.setArtifactName("install_apache.sh");
135 defaultArtifact.setArtifactType("SHELL");
136 defaultArtifact.setPayload("new payload");
138 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
139 resourceDetailsVFCcomp.getUniqueId());
140 status = response.getErrorCode();
141 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
143 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
144 defaultArtifact, sdncUserDetails);
145 status = response.getErrorCode();
146 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
151 public void createAndUpdateArtifactToInterface() throws Exception {
153 CloseableHttpResponse response;
155 CloseableHttpClient httpclient = HttpClients.createDefault();
158 // upload artifact to interface
159 String interfaceName = "Standard";
160 String operationName = "configure";
162 String userBodyJson = createUploadArtifactBodyJson();
163 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
164 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
166 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
167 response = httpclient.execute(httpPost);
168 status = response.getStatusLine().getStatusCode();
169 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
171 // get artifact uniqueId
172 String artifactId = getLifecycleArtifactUid(response);
174 Map<String, Object> jsonBody = new HashMap<String, Object>();
175 jsonBody.put("artifactName", "TLV_prv.ppk");
176 jsonBody.put("artifactDisplayName", "configure");
177 jsonBody.put("artifactType", "SHELL");
178 jsonBody.put("mandatory", "false");
179 String newDescription = "new something";
180 jsonBody.put("description", newDescription);
181 jsonBody.put("artifactLabel", "configure");
182 userBodyJson = gson.toJson(jsonBody);
184 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
185 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
188 httpPost = createPostAddArtifactRequeast(userBodyJson, url, false);
190 response = httpclient.execute(httpPost);
191 status = response.getStatusLine().getStatusCode();
192 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
194 url = String.format(Urls.GET_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(),
195 resourceDetailsVFCcomp.getUniqueId());
196 HttpGet httpGet = createGetRequest(url);
197 response = httpclient.execute(httpGet);
198 AssertJUnit.assertTrue(response.getStatusLine().getStatusCode() == 200);
199 String responseString = new BasicResponseHandler().handleResponse(response);
201 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
202 responseMap = (JSONObject) responseMap.get("interfaces");
203 responseMap = (JSONObject) responseMap.get(interfaceName.toLowerCase());
204 responseMap = (JSONObject) responseMap.get("operations");
205 responseMap = (JSONObject) responseMap.get(operationName.toLowerCase());
206 responseMap = (JSONObject) responseMap.get("implementation");
207 String description = (String) responseMap.get("description");
209 AssertJUnit.assertEquals("the new description value was not set", newDescription, description);
212 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
213 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
215 HttpDelete httpDelete = createDeleteArtifactRequest(url);
217 response = httpclient.execute(httpDelete);
218 status = response.getStatusLine().getStatusCode();
219 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
226 protected String createUploadArtifactBodyJson() {
227 Map<String, Object> jsonBody = new HashMap<String, Object>();
228 jsonBody.put("artifactName", UPLOAD_ARTIFACT_NAME);
229 jsonBody.put("artifactDisplayName", "configure");
230 jsonBody.put("artifactType", "SHELL");
231 jsonBody.put("mandatory", "false");
232 jsonBody.put("description", "ff");
233 jsonBody.put("payloadData", UPLOAD_ARTIFACT_PAYLOAD);
234 jsonBody.put("artifactLabel", "configure");
235 return gson.toJson(jsonBody);
238 protected ArtifactDefinition getArtifactDataFromJson(String json) {
239 Gson gson = new Gson();
240 ArtifactDefinition artifact = new ArtifactDefinition();
241 artifact = gson.fromJson(json, ArtifactDefinition.class);
244 * atifact.setArtifactName(UPLOAD_ARTIFACT_NAME);
245 * artifact.setArtifactDisplayName("configure");
246 * artifact.setArtifactType("SHELL"); artifact.setMandatory(false);
247 * artifact.setDescription("ff");
248 * artifact.setPayloadData(UPLOAD_ARTIFACT_PAYLOAD);
249 * artifact.setArtifactLabel("configure");
254 protected HttpGet createGetRequest(String url) {
255 HttpGet httpGet = new HttpGet(url);
256 httpGet.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
257 httpGet.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
258 httpGet.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
262 protected String getArtifactUid(HttpResponse response) throws HttpResponseException, IOException, ParseException {
263 String responseString = new BasicResponseHandler().handleResponse(response);
264 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
265 String artifactId = (String) responseMap.get("uniqueId");
269 protected String getArtifactEsId(HttpResponse response) throws HttpResponseException, IOException, ParseException {
270 String responseString = new BasicResponseHandler().handleResponse(response);
271 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
272 String esId = (String) responseMap.get("EsId");
276 protected ArtifactDefinition addArtifactDataFromResponse(HttpResponse response, ArtifactDefinition artifact)
277 throws HttpResponseException, IOException, ParseException {
278 // String responseString = new
279 // BasicResponseHandler().handleResponse(response);
280 HttpEntity entity = response.getEntity();
281 String responseString = EntityUtils.toString(entity);
282 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
283 artifact.setEsId((String) responseMap.get("esId"));
284 artifact.setUniqueId((String) responseMap.get("uniqueId"));
285 artifact.setArtifactGroupType(ArtifactGroupTypeEnum.findType((String) responseMap.get("artifactGroupType")));
286 artifact.setTimeout(((Long) responseMap.get("timeout")).intValue());
290 protected String getLifecycleArtifactUid(CloseableHttpResponse response)
291 throws HttpResponseException, IOException, ParseException {
292 String responseString = new BasicResponseHandler().handleResponse(response);
293 JSONObject responseMap = (JSONObject) jsonParser.parse(responseString);
294 responseMap = (JSONObject) responseMap.get("implementation");
295 String artifactId = (String) responseMap.get("uniqueId");
299 protected HttpDelete createDeleteArtifactRequest(String url) {
300 HttpDelete httpDelete = new HttpDelete(url);
301 httpDelete.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
302 httpDelete.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
306 protected HttpPost createPostAddArtifactRequeast(String jsonBody, String url, boolean addMd5Header)
307 throws UnsupportedEncodingException {
308 HttpPost httppost = new HttpPost(url);
309 httppost.addHeader(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
310 httppost.addHeader(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
311 httppost.addHeader(HttpHeaderEnum.USER_ID.getValue(), sdncUserDetails.getUserId());
313 httppost.addHeader(HttpHeaderEnum.Content_MD5.getValue(), GeneralUtility.calculateMD5Base64EncodedByString(jsonBody));
315 StringEntity input = new StringEntity(jsonBody);
316 input.setContentType("application/json");
317 httppost.setEntity(input);
318 log.debug("Executing request {}", httppost.getRequestLine());
322 protected String createLoadArtifactBody() {
323 Map<String, Object> json = new HashMap<String, Object>();
324 json.put("artifactName", "install_apache2.sh");
325 json.put("artifactType", "SHELL");
326 json.put("description", "ddd");
327 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
328 json.put("artifactLabel", "name123");
330 String jsonStr = gson.toJson(json);
334 protected void checkDeleteResponse(RestResponse response) {
335 BaseRestUtils.checkStatusCode(response, "delete request failed", false, 204, 404);
338 protected ArtifactUiDownloadData getArtifactUiDownloadData(String artifactUiDownloadDataStr) throws Exception {
340 ObjectMapper mapper = new ObjectMapper();
342 ArtifactUiDownloadData artifactUiDownloadData = mapper.readValue(artifactUiDownloadDataStr,
343 ArtifactUiDownloadData.class);
344 return artifactUiDownloadData;
345 } catch (Exception e) {
354 public void addArtifactNoPayLoadToResourcseTest() throws Exception {
355 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
356 defaultArtifact.setPayload(null);
358 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
359 resourceDetailsVFCcomp.getUniqueId());
360 int status = response.getErrorCode();
361 AssertJUnit.assertTrue(status == 400);
366 public void upadteArtifactNoPayLoadToResourcseTest() throws Exception {
368 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
370 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
371 resourceDetailsVFCcomp.getUniqueId());
372 int status = response.getErrorCode();
373 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
376 defaultArtifact.setDescription("kjglkh");
377 defaultArtifact.setArtifactName("install_apache.sh");
378 defaultArtifact.setArtifactType("SHELL");
379 defaultArtifact.setPayload(null);
381 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
382 resourceDetailsVFCcomp.getUniqueId());
383 status = response.getErrorCode();
384 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
386 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
387 defaultArtifact, sdncUserDetails);
388 status = response.getErrorCode();
389 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
394 @Test(enabled = false)
395 public void updateDeploymentArtifactToResourcseTest() throws Exception {
397 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultDeploymentArtifactForType("HEAT");
399 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
400 resourceDetailsVFCcomp.getUniqueId());
401 int status = response.getErrorCode();
402 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
405 response = ArtifactRestUtils.updateInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
406 resourceDetailsVFCcomp.getUniqueId());
407 status = response.getErrorCode();
408 AssertJUnit.assertEquals("failed to update artifact metatdata: " + response.getErrorCode(), 200, status);
410 response = ArtifactRestUtils.deleteInformationalArtifactFromResource(resourceDetailsVFCcomp.getUniqueId(),
411 defaultArtifact, sdncUserDetails);
412 status = response.getErrorCode();
413 AssertJUnit.assertEquals("failed to remove artifact: " + response.getErrorCode(), 200, status);
417 // --------------------
419 public void addArtifactToResourcse_AlreadyExistsTest() throws Exception {
420 CloseableHttpClient httpclient = HttpClients.createDefault();
422 String jsonBody = createLoadArtifactBody();
424 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
425 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
426 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
427 CloseableHttpResponse response = httpclient.execute(httppost);
428 int status = response.getStatusLine().getStatusCode();
429 AssertJUnit.assertTrue("failed to add artifact", status == 200);
431 String artifactId = getArtifactUid(response);
433 httppost = createPostAddArtifactRequeast(jsonBody, url, true);
434 response = httpclient.execute(httppost);
435 status = response.getStatusLine().getStatusCode();
436 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
438 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
439 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), artifactId);
440 HttpDelete httpDelete = createDeleteArtifactRequest(url);
441 response = httpclient.execute(httpDelete);
442 status = response.getStatusLine().getStatusCode();
443 AssertJUnit.assertTrue("failed to remove artifact", status == 200);
451 public void addArtifactToResourcse_MissingContentTest() throws Exception {
453 CloseableHttpClient httpclient = HttpClients.createDefault();
455 Map<String, Object> json = new HashMap<String, Object>();
456 json.put("description", "desc");
457 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
458 json.put("Content-MD5", "YTg2Mjg4MWJhNmI5NzBiNzdDFkMWI=");
460 String jsonBody = gson.toJson(json);
462 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
463 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
464 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, true);
465 CloseableHttpResponse response = httpclient.execute(httppost);
466 int status = response.getStatusLine().getStatusCode();
467 AssertJUnit.assertEquals("the returned status code is in correct", status, 400);
475 public void addArtifactToResourcse_MissingMd5Test() throws Exception {
477 CloseableHttpClient httpclient = HttpClients.createDefault();
479 HashMap<String, Object> json = new HashMap<String, Object>();
480 json.put("artifactName", "install_apache.sh");
481 json.put("artifactType", "SHELL");
482 json.put("description", "kjglkh");
483 json.put("payloadData", "UEsDBYTEIWUYIFHWFMABCNAoAAAAIAAeLb0bDQz");
484 json.put("artifactLabel", "name123");
485 String url = String.format(Urls.ADD_ARTIFACT_TO_RESOURCE, config.getCatalogBeHost(),
486 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId());
487 String jsonBody = gson.toJson(json);
488 HttpPost httppost = createPostAddArtifactRequeast(jsonBody, url, false);
489 CloseableHttpResponse response = httpclient.execute(httppost);
490 int status = response.getStatusLine().getStatusCode();
491 AssertJUnit.assertTrue("failed to update artifact metatdata", status == 400);
499 public void deleteArtifact_NotExistsTest() throws Exception {
500 CloseableHttpClient httpclient = HttpClients.createDefault();
502 String url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_RESOURCE, config.getCatalogBeHost(),
503 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), "someFakeId");
504 HttpDelete httpDelete = createDeleteArtifactRequest(url);
505 CloseableHttpResponse response = httpclient.execute(httpDelete);
506 int status = response.getStatusLine().getStatusCode();
507 AssertJUnit.assertEquals("the returned status code is in correct", status, 404);
515 public void createAndRemoveArtifactToInterface() throws Exception {
516 CloseableHttpResponse response;
518 CloseableHttpClient httpclient = HttpClients.createDefault();
521 // upload artifact to interface
522 String interfaceName = "Standard";
523 String operationName = "configure";
525 String userBodyJson = createUploadArtifactBodyJson();
526 String url = String.format(Urls.UPLOAD_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
527 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName);
529 HttpPost httpPost = createPostAddArtifactRequeast(userBodyJson, url, true);
530 response = httpclient.execute(httpPost);
531 status = response.getStatusLine().getStatusCode();
532 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
534 // get artifact uniqueId
535 String artifactId = getLifecycleArtifactUid(response);
538 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_BY_INTERFACE_TO_RESOURCE, config.getCatalogBeHost(),
539 config.getCatalogBePort(), resourceDetailsVFCcomp.getUniqueId(), interfaceName, operationName,
541 HttpDelete httpDelete = createDeleteArtifactRequest(url);
543 response = httpclient.execute(httpDelete);
544 status = response.getStatusLine().getStatusCode();
545 AssertJUnit.assertEquals("response code is not 200, returned :" + status, status, 200);
553 public void addArtifactToServiceTest() throws Exception {
555 CloseableHttpClient httpclient = HttpClients.createDefault();
558 String jsonStr = createLoadArtifactBody();
560 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
561 config.getCatalogBePort(), defaultService1.getUniqueId());
562 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
563 CloseableHttpResponse result = httpclient.execute(httpPost);
564 int status = result.getStatusLine().getStatusCode();
565 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
567 String artifactId = getArtifactUid(result);
569 url = String.format(Urls.UPDATE_OR_DELETE_ARTIFACT_OF_SERVICE, config.getCatalogBeHost(),
570 config.getCatalogBePort(), defaultService1.getUniqueId(), artifactId);
571 HttpDelete httpDelete = createDeleteArtifactRequest(url);
573 result = httpclient.execute(httpDelete);
574 status = result.getStatusLine().getStatusCode();
575 AssertJUnit.assertEquals("response code is not 200, returned :" + status, 200, status);
577 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
579 checkDeleteResponse(response);
585 public void addArtifactNotSupportedTypeToServiceTest() throws Exception {
586 CloseableHttpClient httpclient = HttpClients.createDefault();
588 Map<String, Object> json = new HashMap<String, Object>();
589 json.put("artifactName", "install_apache.sh");
590 json.put("artifactType", "SHELL11");
591 json.put("description", "fff");
592 json.put("payloadData", "UEsDBAoAAAAIAAeLb0bDQz");
593 json.put("artifactLabel", "name123");
595 String jsonStr = gson.toJson(json);
597 String url = String.format(Urls.ADD_ARTIFACT_TO_SERVICE, config.getCatalogBeHost(),
598 config.getCatalogBePort(), defaultService1.getUniqueId());
600 HttpPost httpPost = createPostAddArtifactRequeast(jsonStr, url, true);
601 CloseableHttpResponse result = httpclient.execute(httpPost);
602 int status = result.getStatusLine().getStatusCode();
603 AssertJUnit.assertEquals("response code is not 400, returned :" + status, 400, status);
605 ErrorInfo errorInfo = ErrorValidationUtils
606 .parseErrorConfigYaml(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED.name());
608 String responseString = EntityUtils.toString(result.getEntity());
610 JSONObject map = (JSONObject) jsonParser.parse(responseString);
611 JSONObject requestError = (JSONObject) map.get("requestError");
612 JSONObject serviceException = (JSONObject) requestError.get("serviceException");
614 String msgId = (String) serviceException.get("messageId");
615 AssertJUnit.assertEquals("message id did not match expacted", errorInfo.getMessageId(), msgId);
617 String text = (String) serviceException.get("text");
618 AssertJUnit.assertEquals("text did not match expacted", errorInfo.getMessage(), text);
620 JSONArray variables = (JSONArray) serviceException.get("variables");
621 String type = (String) variables.get(0);
622 AssertJUnit.assertEquals("variable did not match expacted", "SHELL11", type);
624 RestResponse response = ServiceRestUtils.deleteService(defaultService1.getName(), serviceVersion,
626 checkDeleteResponse(response);
633 public void addArtifactToResourceTest() throws Exception {
635 ArtifactReqDetails defaultArtifact = ElementFactory.getDefaultArtifact();
637 RestResponse response = ArtifactRestUtils.addInformationalArtifactToResource(defaultArtifact, sdncUserDetails,
638 resourceDetailsVFCcomp.getUniqueId());
639 int status = response.getErrorCode();
640 AssertJUnit.assertEquals("add informational artifact request returned status: " + response.getErrorCode(), 200,
643 RestResponse resourceResp = ResourceRestUtils.getResource(resourceDetailsVFCcomp.getUniqueId());
644 Resource resource = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
645 AssertJUnit.assertNotNull(resource);
647 Map<String, ArtifactDefinition> artifacts = resource.getArtifacts();
648 boolean isExist = false;
649 for (Map.Entry<String, ArtifactDefinition> entry : artifacts.entrySet()) {
650 if (entry.getKey().equals(defaultArtifact.getArtifactLabel())) {
655 AssertJUnit.assertTrue(isExist);