b61489d12d3cc65d162f59567ea8dfec04d6b4ac
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.resource;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
26
27 import java.io.FileNotFoundException;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.Map;
34
35 import org.json.JSONException;
36 import org.json.JSONObject;
37 import org.junit.rules.TestName;
38 import org.openecomp.sdc.be.dao.api.ActionStatus;
39 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
40 import org.openecomp.sdc.be.model.LifecycleStateEnum;
41 import org.openecomp.sdc.be.model.Resource;
42 import org.openecomp.sdc.be.model.User;
43 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
44 import org.openecomp.sdc.ci.tests.api.Urls;
45 import org.openecomp.sdc.ci.tests.config.Config;
46 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
47 import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo;
48 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
49 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
50 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
51 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
52 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
53 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedResourceAuditJavaObject;
54 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
55 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
56 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
57 import org.openecomp.sdc.ci.tests.utils.DbUtils;
58 import org.openecomp.sdc.ci.tests.utils.Utils;
59 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
60 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
61 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
62 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
63 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
64 import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils;
65 import org.openecomp.sdc.ci.tests.utils.validation.ResourceValidationUtils;
66 import org.openecomp.sdc.common.util.ValidationUtils;
67 import org.slf4j.Logger;
68 import org.slf4j.LoggerFactory;
69 import org.testng.AssertJUnit;
70 import org.testng.annotations.BeforeMethod;
71 import org.testng.annotations.Test;
72
73 import com.google.gson.Gson;
74
75 public class UpdateResourceMetadataTest extends ComponentBaseTest {
76         private static Logger logger = LoggerFactory.getLogger(UpdateResourceMetadataTest.class.getName());
77         protected List<String> Empty_List = new ArrayList<String>();
78         protected String extendedChars;
79
80         protected final String contentTypeHeaderData = "application/json";
81         protected final String acceptHeaderDate = "application/json";
82         protected final String CHARSET_ISO_8859 = "charset=ISO-8859-1";
83
84         public static TestName name = new TestName();
85         protected User sdncModifierDetails;
86         protected ResourceReqDetails resourceDetails;
87
88         public UpdateResourceMetadataTest() {
89                 super(name, UpdateResourceMetadataTest.class.getName());
90
91         }
92
93         public String extendedCharsStringBuilder() throws Exception {
94                 char[] extendedCharsArray = new char[128];
95                 char ch = 128;
96                 for (int i = 0; i < extendedCharsArray.length - 1; i++) {
97                         extendedCharsArray[i] = ch;
98                         ch++;
99                 }
100                 extendedChars = new String(extendedCharsArray);
101                 return extendedChars;
102
103         }
104
105         @BeforeMethod
106         public void setup() throws Exception {
107                 sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
108                 resourceDetails = defineResourse();
109
110         }
111
112         // Keep
113         @Test
114         public void UpdateDerivedFromSuccess() throws Exception {
115
116                 String oldDerivedFromName = NormativeTypesEnum.ROOT.getNormativeName();
117                 String newDerivedFromName = NormativeTypesEnum.SOFTWARE_COMPONENT.getNormativeName();
118
119                 // Getting both derived from resources for validation
120                 /*
121                  * RestResponse resourceByNameAndVersion = resourceUtils.getResourceByNameAndVersion(sdncModifierDetails, oldDerivedFromName, "1.0"); assertEquals("Check response code after get database normative", 200,
122                  * resourceByNameAndVersion.getErrorCode().intValue()); Resource databaseNormative = resourceUtils.parseResourceResp(resourceByNameAndVersion);
123                  * 
124                  * resourceByNameAndVersion = resourceUtils.getResourceByNameAndVersion(sdncModifierDetails, newDerivedFromName, "1.0"); assertEquals("Check response code after get database normative", 200,
125                  * resourceByNameAndVersion.getErrorCode().intValue()); Resource lbNormative = resourceUtils.parseResourceResp(resourceByNameAndVersion);
126                  */
127
128                 // Derived from set to Database
129                 List<String> derivedFrom = new ArrayList<>();
130                 derivedFrom.add(oldDerivedFromName);
131                 resourceDetails.setDerivedFrom(derivedFrom);
132
133                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
134                 AssertJUnit.assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
135                 Resource currentResource = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
136
137                 derivedFrom.clear();
138                 derivedFrom.add(newDerivedFromName);
139                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, currentResource.getUniqueId(), "");
140                 AssertJUnit.assertEquals("Check response code after create resource", 200, updatedRestResponse.getErrorCode().intValue());
141
142         }
143
144         protected ResourceReqDetails defineUpdateResourceWithNonUpdatableFields(Resource resourceBeforeUpdate) {
145                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceBeforeUpdate.getName());
146
147                 updatedResourceDetails.setVersion("mumu");
148                 updatedResourceDetails.setIsAbstract(true);
149                 updatedResourceDetails.setIsHighestVersion(true);
150                 updatedResourceDetails.setCreatorUserId("df4444");
151                 updatedResourceDetails.setCreatorFullName("John Doe");
152                 updatedResourceDetails.setLastUpdaterUserId("gf5646");
153                 updatedResourceDetails.setLastUpdaterFullName("Viktor Tzoy");
154                 updatedResourceDetails.setCreationDate(new Long(4444));
155                 updatedResourceDetails.setLastUpdateDate(new Long("534535"));
156                 updatedResourceDetails.setLifecycleState(LifecycleStateEnum.READY_FOR_CERTIFICATION);
157                 updatedResourceDetails.setCost("6.1");
158                 updatedResourceDetails.setLicenseType("Installation");
159                 updatedResourceDetails.setUUID("dfsfsdf");
160                 return updatedResourceDetails;
161         }
162
163         public void UpdateResourceNotFoundTest() throws Exception {
164                 // init ADMIN user
165                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
166
167                 String resourceName = "cisco4";
168                 // update resource
169                 String description = "updatedDescription";
170                 ArrayList<String> resourceTags = new ArrayList<String>();
171                 resourceTags.add("tag2");
172                 String category = ServiceCategoriesEnum.MOBILITY.getValue();
173                 ArrayList<String> derivedFrom = new ArrayList<String>();
174                 derivedFrom.add(NormativeTypesEnum.ROOT.getNormativeName());
175                 String vendorName = "newOracle";
176                 String vendorRelease = "2.5";
177                 String contactId = "jh0003";
178                 String icon = "myICON";
179
180                 ResourceReqDetails updatedResourceDetails = new ResourceReqDetails(resourceName, description, resourceTags, category, derivedFrom, vendorName, vendorRelease, contactId, icon);
181                 updatedResourceDetails.setUniqueId("dummyId");
182                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, "0.1");
183
184                 // validate response
185                 AssertJUnit.assertNotNull("check response object is not null after update resource", updatedRestResponse);
186                 AssertJUnit.assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
187                 AssertJUnit.assertEquals("Check response code after update resource", 404, updatedRestResponse.getErrorCode().intValue());
188                 // String resourceId =
189                 // UniqueIdBuilder.buildResourceUniqueId(resourceName, "0.1");
190                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESOURCE_NOT_FOUND.name(), Arrays.asList("dummyId"), updatedRestResponse.getResponse());
191
192                 resourceName = "";
193                 // resourceId = UniqueIdBuilder.buildResourceUniqueId(resourceName,
194                 // "0.1");
195                 updatedResourceDetails = defineUpdatedResourse(resourceName);
196                 updatedResourceDetails.setUniqueId("dummyId");
197                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, "0.1");
198                 AssertJUnit.assertNotNull("check response object is not null after update resource", updatedRestResponse);
199                 AssertJUnit.assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
200                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESOURCE_NOT_FOUND.name(), Arrays.asList("dummyId"), updatedRestResponse.getResponse());
201
202         }
203
204         public char[] getInValidChars() throws Exception {
205
206                 char[] extendedCharsArray = new char[59];
207                 char ch = 1;
208                 for (int i = 0; i < 44; i++) {
209                         extendedCharsArray[i] = ch;
210                         ch++;
211                 }
212                 ch = 58;
213                 for (int i = 44; i < 51; i++) {
214                         extendedCharsArray[i] = ch;
215                         ch++;
216                 }
217                 ch = 91;
218                 for (int i = 51; i < 55; i++) {
219                         extendedCharsArray[i] = ch;
220                         ch++;
221                 }
222                 ch = 123;
223                 for (int i = 55; i < 59; i++) {
224                         extendedCharsArray[i] = ch;
225                         ch++;
226                 }
227                 return extendedCharsArray;
228         }
229
230         public char[] getTagInValidFormatChars() throws Exception {
231                 // Tag format is the same as defined for Resource Name :
232                 // Allowed characters: Alphanumeric (a-zA-Z0-9), space (' '), underscore
233                 // ('_'), dash ('-'), dot ('.')
234                 char[] notValidCharsArray = new char[30];
235                 char ch = 33;
236                 for (int i = 0; i < 12; i++) {
237                         notValidCharsArray[i] = ch;
238                         ch++;
239                 }
240                 notValidCharsArray[13] = 47;
241                 ch = 58;
242                 for (int i = 14; i < 21; i++) {
243                         notValidCharsArray[i] = ch;
244                         ch++;
245                 }
246                 ch = 91;
247                 for (int i = 21; i < 24; i++) {
248                         notValidCharsArray[i] = ch;
249                         ch++;
250                 }
251                 notValidCharsArray[24] = 96;
252                 ch = 123;
253                 for (int i = 25; i < 30; i++) {
254                         notValidCharsArray[i] = ch;
255                         ch++;
256                 }
257                 return notValidCharsArray;
258         }
259
260         public void Validation_UpdateWithIncompleteJsonBodyTest() throws Exception {
261                 // init ADMIN user
262                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
263
264                 // define and create resource
265                 ResourceReqDetails resourceDetails = defineResourse();
266                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, resourceDetails.getName(), "0.1");
267                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, resourceDetails.getName(), "1.0");
268                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, resourceDetails.getName(), "1.1");
269
270                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
271                 String resourceId = resourceDetails.getUniqueId();
272                 resourceDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(restResponse));
273
274                 // build Json Object
275                 JSONObject jsonObject = JsonObjectBuilder(resourceDetails);
276
277                 List<String> resource = new ArrayList<>();
278                 resource.add("Resource");
279
280                 // remove Description
281                 UpdateAndValidateWithIncompletedJsonBody(sdncModifierDetails, jsonObject, resourceId, "description", ActionStatus.COMPONENT_MISSING_DESCRIPTION.name(), resource);
282                 // remove Tags
283                 UpdateAndValidateWithIncompletedJsonBody(sdncModifierDetails, jsonObject, resourceId, "tags", ActionStatus.COMPONENT_MISSING_TAGS.name(), Empty_List);
284                 // remove Category
285                 UpdateAndValidateWithIncompletedJsonBody(sdncModifierDetails, jsonObject, resourceId, "category", ActionStatus.COMPONENT_MISSING_CATEGORY.name(), resource);
286                 // remove VendorName
287                 UpdateAndValidateWithIncompletedJsonBody(sdncModifierDetails, jsonObject, resourceId, "vendorName", ActionStatus.MISSING_VENDOR_NAME.name(), Empty_List);
288                 // remove VendorRelease
289                 UpdateAndValidateWithIncompletedJsonBody(sdncModifierDetails, jsonObject, resourceId, "vendorRelease", ActionStatus.MISSING_VENDOR_RELEASE.name(), Empty_List);
290                 // remove AT&T Contact
291                 UpdateAndValidateWithIncompletedJsonBody(sdncModifierDetails, jsonObject, resourceId, "contactId", ActionStatus.COMPONENT_MISSING_CONTACT.name(), resource);
292
293                 // get resource with original name. original metadata should be returned
294                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, "0.1");
295                 // validate response
296                 AssertJUnit.assertNotNull("check response object is not null after get resource", getRestResponse);
297                 AssertJUnit.assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
298                 AssertJUnit.assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
299
300                 // parse updated response to javaObject
301                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
302                 // validate that metadata was not changed
303                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
304
305                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, resourceDetails.getName(), "0.1");
306                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, resourceDetails.getName(), "1.0");
307                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, resourceDetails.getName(), "1.1");
308         }
309
310         // End of validation tests
311         // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
312
313         protected ResourceReqDetails defineUpdatedResourse(String resourceName) {
314                 String description = "updatedDescription";
315                 ArrayList<String> resourceTags = new ArrayList<String>();
316                 // Duplicate tags are allowed and should be de-duplicated by server side
317                 resourceTags.add(resourceName);
318                 resourceTags.add("tag1");
319                 resourceTags.add("tag1");
320                 resourceTags.add("tag2");
321                 resourceTags.add("tag2");
322                 String category = ServiceCategoriesEnum.VOIP.getValue();
323                 ArrayList<String> derivedFrom = new ArrayList<String>();
324                 derivedFrom.add(NormativeTypesEnum.ROOT.getNormativeName());
325                 String vendorName = "updatedOracle";
326                 String vendorRelease = "3.5";
327                 String contactId = "jh0001";
328                 String icon = "myUpdatedICON";
329
330                 ResourceReqDetails resourceDetails = new ResourceReqDetails(resourceName, description, resourceTags, category, derivedFrom, vendorName, vendorRelease, contactId, icon);
331                 resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_INFRASTRUCTURE.getCategory(), ResourceCategoryEnum.GENERIC_INFRASTRUCTURE.getSubCategory());
332
333                 return resourceDetails;
334         }
335
336         protected ResourceReqDetails defineResourse() {
337                 String resourceName = "cisco4";
338                 String description = "description";
339                 ArrayList<String> resourceTags = new ArrayList<String>();
340                 resourceTags.add(resourceName);
341                 ArrayList<String> derivedFrom = new ArrayList<String>();
342                 derivedFrom.add(NormativeTypesEnum.ROOT.getNormativeName());// "tosca.nodes.Root");
343                 String vendorName = "Oracle";
344                 String vendorRelease = "1.5";
345                 String contactId = "jh0003";
346                 String icon = "objectStorage";
347
348                 ResourceReqDetails resourceDetails = new ResourceReqDetails(resourceName, description, resourceTags, null, derivedFrom, vendorName, vendorRelease, contactId, icon);
349                 resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_INFRASTRUCTURE.getCategory(), ResourceCategoryEnum.GENERIC_INFRASTRUCTURE.getSubCategory());
350
351                 return resourceDetails;
352         }
353
354         protected RestResponse createResource(User sdncModifierDetails, ResourceReqDetails resourceDetails) throws Exception {
355                 // clean ES DB
356                 DbUtils.cleanAllAudits();
357
358                 // create resource
359                 RestResponse restResponse = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
360
361                 // validate response
362                 AssertJUnit.assertNotNull("check response object is not null after create resource", restResponse);
363                 AssertJUnit.assertNotNull("check error code exists in response after create resource", restResponse.getErrorCode());
364                 AssertJUnit.assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
365
366                 return restResponse;
367         }
368
369         protected RestResponse TryUpdateByAnotherVerb(ResourceReqDetails updatedResourceDetails, User sdncModifierDetails, String uri) throws Exception {
370                 // delete resource
371                 Config config;
372                 RestResponse ResourceResponse;
373                 try {
374                         config = Utils.getConfig();
375                         Map<String, String> headersMap = new HashMap<String, String>();
376                         headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), contentTypeHeaderData);
377                         headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), acceptHeaderDate);
378                         headersMap.put(HttpHeaderEnum.USER_ID.getValue(), sdncModifierDetails.getUserId());
379                         HttpRequest http = new HttpRequest();
380                         String url = String.format(Urls.UPDATE_RESOURCE_METADATA, config.getCatalogBeHost(), config.getCatalogBePort(), updatedResourceDetails.getName() + ".0.1");
381
382                         if (uri == "GET") {
383                                 ResourceResponse = http.httpSendGet(url, headersMap);
384                         } else if (uri == "POST") {
385                                 Gson gson = new Gson();
386                                 String userBodyJson = gson.toJson(updatedResourceDetails);
387                                 ResourceResponse = http.httpSendPost(url, userBodyJson, headersMap);
388                         } else if (uri == "DELETE") {
389                                 ResourceResponse = http.httpSendDelete(url, headersMap);
390                         } else
391                                 return null;
392
393                         return ResourceResponse;
394                 } catch (FileNotFoundException e) {
395                         // TODO Auto-generated catch block
396                         e.printStackTrace();
397                 }
398
399                 return null;
400
401         }
402
403         protected JSONObject JsonObjectBuilder(ResourceReqDetails resourceDetails) throws JSONException {
404                 // json object: resourceName and icon are must
405                 JSONObject jObject = new JSONObject();
406
407                 List<String> tagsList = Arrays.asList(resourceDetails.getName());
408                 List<String> derivedFromList = Arrays.asList("[tosca.nodes.Root]");
409
410                 jObject.put("name", resourceDetails.getName());
411                 jObject.put("description", "updatedDescription");
412                 jObject.put("tags", tagsList);
413                 jObject.put("category", ServiceCategoriesEnum.VOIP.getValue());
414                 jObject.put("derivedFrom", derivedFromList);
415                 jObject.put("vendorName", "newOracle");
416                 jObject.put("vendorRelease", "1.5");
417                 jObject.put("contactId", "jh0003");
418                 jObject.put("icon", resourceDetails.getIcon());
419
420                 return jObject;
421         }
422
423         protected JSONObject RemoveFromJsonObject(JSONObject jObject, String removedPropery) {
424                 jObject.remove(removedPropery);
425
426                 return jObject;
427         }
428
429         // purpose: function for controlling json body fields and validating
430         // response
431         protected void UpdateAndValidateWithIncompletedJsonBody(User sdncModifierDetails, JSONObject jsonObject, String resourceId, String removedField, String errorMessage, List<String> variables) throws Exception {
432
433                 JSONObject jObject = new JSONObject(jsonObject, JSONObject.getNames(jsonObject));
434                 // remove description from jsonObject
435                 jObject = RemoveFromJsonObject(jObject, removedField);
436                 // update with incomplete body.
437                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(jObject.toString(), sdncModifierDetails, resourceId);
438                 // validate response
439                 AssertJUnit.assertNotNull("check response object is not null after update resource", updatedRestResponse);
440                 AssertJUnit.assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
441                 ErrorValidationUtils.checkBodyResponseOnError(errorMessage, variables, updatedRestResponse.getResponse());
442
443         }
444
445         // purpose: function for validating error response
446         protected void UpdateAndValidate(User sdncModifierDetails, ResourceReqDetails resourceDetails, String recievedMessage, List<String> variables) throws Exception {
447                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, "0.1");
448                 // validate response
449                 AssertJUnit.assertNotNull("check response object is not null after update resource", updatedRestResponse);
450                 AssertJUnit.assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
451                 ErrorValidationUtils.checkBodyResponseOnError(recievedMessage, variables, updatedRestResponse.getResponse());
452
453         }
454
455         protected void parseResponseAndValidateNonUpdatable(ResourceReqDetails resourceDetails, RestResponse restResponse) throws Exception {
456                 // parse response to javaObject
457                 Resource updatedResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
458                 AssertJUnit.assertTrue(!resourceDetails.getIsHighestVersion().equals(updatedResourceRespJavaObject.isHighestVersion()));
459                 AssertJUnit.assertTrue(!resourceDetails.getVersion().equals(updatedResourceRespJavaObject.getName()));
460                 AssertJUnit.assertTrue(!resourceDetails.getIsAbstract().equals(updatedResourceRespJavaObject.isAbstract()));
461                 AssertJUnit.assertTrue(!resourceDetails.getCreatorUserId().equals(updatedResourceRespJavaObject.getCreatorUserId()));
462                 AssertJUnit.assertTrue(!resourceDetails.getCreatorFullName().equals(updatedResourceRespJavaObject.getCreatorFullName()));
463                 AssertJUnit.assertTrue(!resourceDetails.getLastUpdateDate().equals(updatedResourceRespJavaObject.getLastUpdateDate()));
464                 AssertJUnit.assertTrue(!resourceDetails.getCreationDate().equals(updatedResourceRespJavaObject.getCreationDate()));
465                 AssertJUnit.assertTrue(!resourceDetails.getLastUpdaterUserId().equals(updatedResourceRespJavaObject.getLastUpdaterUserId()));
466                 AssertJUnit.assertTrue(!resourceDetails.getLastUpdaterFullName().equals(updatedResourceRespJavaObject.getLastUpdaterFullName()));
467                 AssertJUnit.assertTrue(!resourceDetails.getLifecycleState().equals(updatedResourceRespJavaObject.getLifecycleState()));
468                 AssertJUnit.assertTrue(!resourceDetails.getCost().equals(updatedResourceRespJavaObject.getCost()));
469                 AssertJUnit.assertTrue(!resourceDetails.getLicenseType().equals(updatedResourceRespJavaObject.getLicenseType()));
470                 AssertJUnit.assertTrue(!resourceDetails.getUUID().equals(updatedResourceRespJavaObject.getUUID()));
471         }
472
473         protected void parseResponseAndValidate(ResourceReqDetails ResourceDetails, RestResponse restResponse) throws Exception {
474                 // parse response to javaObject
475                 Resource updatedResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
476                 // validate request vs response
477                 ResourceValidationUtils.validateResourceReqVsResp(ResourceDetails, updatedResourceRespJavaObject);
478         }
479
480         public ExpectedResourceAuditJavaObject constructFieldsForAuditValidation(ResourceReqDetails resourceDetails, String resourceVersion) {
481
482                 ExpectedResourceAuditJavaObject expectedResourceAuditJavaObject = new ExpectedResourceAuditJavaObject();
483
484                 expectedResourceAuditJavaObject.setAction("Checkout");
485                 expectedResourceAuditJavaObject.setModifierUid(UserRoleEnum.ADMIN.getUserId());
486                 expectedResourceAuditJavaObject.setModifierName(UserRoleEnum.ADMIN.getUserName());
487                 expectedResourceAuditJavaObject.setStatus("200.0");
488                 expectedResourceAuditJavaObject.setDesc("OK");
489                 expectedResourceAuditJavaObject.setResourceName(resourceDetails.getName().toLowerCase());
490                 expectedResourceAuditJavaObject.setResourceType("Resource");
491                 expectedResourceAuditJavaObject.setPrevVersion(String.valueOf(Float.parseFloat(resourceVersion) - 0.1f));
492                 expectedResourceAuditJavaObject.setCurrVersion(resourceVersion);
493                 expectedResourceAuditJavaObject.setPrevState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
494                 expectedResourceAuditJavaObject.setCurrState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString());
495
496                 return expectedResourceAuditJavaObject;
497
498         }
499
500         public enum FieldToValidate {
501                 ContactId, Tags, VendorName, VendorRelease, Description
502         }
503
504         @Test
505         public void UpdateBy_postTest() throws Exception {
506
507                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
508                 String resourceName = resourceDetails.getName();
509
510                 // update resource - without changing resourceName
511                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
512
513                 RestResponse updatedRestResponse = TryUpdateByAnotherVerb(updatedResourceDetails, sdncModifierDetails, "POST");
514
515                 // validate response
516                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
517                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
518                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.NOT_ALLOWED.name(), Empty_List, updatedRestResponse.getResponse());
519
520                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
521                 assertNotNull("check response object is not null after update resource", getRestResponse);
522                 parseResponseAndValidate(resourceDetails, getRestResponse);
523
524         }
525
526         @Test
527         public void UpdateBy_getTest() throws Exception {
528
529                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
530                 String resourceName = resourceDetails.getName();
531
532                 // update resource - without changing resourceName
533                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
534                 RestResponse updatedRestResponse = TryUpdateByAnotherVerb(updatedResourceDetails, sdncModifierDetails, "GET");
535
536                 // validate response
537                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
538                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
539                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.NOT_ALLOWED.name(), Empty_List, updatedRestResponse.getResponse());
540
541                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
542                 assertNotNull("check response object is not null after update resource", getRestResponse);
543                 parseResponseAndValidate(resourceDetails, getRestResponse);
544
545         }
546
547         @Test
548         public void UpdateBy_deleteTest() throws Exception {
549
550                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
551                 String resourceName = resourceDetails.getName();
552
553                 // update resource - without changing resourceName
554                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
555                 RestResponse updatedRestResponse = TryUpdateByAnotherVerb(updatedResourceDetails, sdncModifierDetails, "DELETE");
556
557                 // validate response
558                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
559                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
560                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.NOT_ALLOWED.name(), Empty_List, updatedRestResponse.getResponse());
561
562                 RestResponse getRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
563                 assertNotNull("check response object is not null after update resource", getRestResponse);
564                 parseResponseAndValidate(resourceDetails, getRestResponse);
565
566         }
567
568         // TODO DE
569         // @Ignore("")
570         @Test
571         public void UpdateWithInvaldJsonBodyTest() throws Exception {
572
573                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
574                 resourceDetails.setUniqueId(ResponseParser.getUniqueIdFromResponse(restResponse));
575                 String resourceId = resourceDetails.getUniqueId();
576
577                 // update Descirption value
578                 String description = "updatedDescription";
579
580                 // send update with incompleted json, only description string
581                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(description, sdncModifierDetails, resourceId);
582
583                 // validate response
584                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
585                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
586                 assertEquals("check error code after update resource", 400, updatedRestResponse.getErrorCode().intValue());
587
588                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
589                 assertNotNull("check response object is not null after update resource", getRestResponse);
590                 parseResponseAndValidate(resourceDetails, getRestResponse);
591
592         }
593
594         @Test
595         public void UpdateResourceNameSensitiveTest() throws Exception {
596                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
597                 String resourceBaseVersion = "0.1";
598                 String resourceName = "Ab";
599                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
600                 // Delete resources
601                 RestResponse response = null;
602                 response = ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, updatedResourceDetails.getName(), "0.1");
603                 BaseRestUtils.checkDeleteResponse(response);
604                 response = ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, updatedResourceDetails.getName(), "0.2");
605                 BaseRestUtils.checkDeleteResponse(response);
606
607                 RestResponse restResponse = createResource(sdncModifierDetails, updatedResourceDetails);
608                 assertEquals("create resource failed", 201, restResponse.getErrorCode().intValue());
609
610                 // check-in Resource
611                 logger.debug("Changing resource life cycle ");
612                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(updatedResourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
613                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
614
615                 // String resourceCertifyVersion = "0.1";
616                 logger.debug("Changing resource life cycle ");
617                 checkoutResource = LifecycleRestUtils.changeResourceState(updatedResourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKOUT);
618                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
619
620                 updatedResourceDetails.setName("ABC_-bt.aT");
621                 ArrayList<String> resourceTag = new ArrayList<String>();
622                 resourceTag.add(0, "ABC_-bt.aT");
623                 updatedResourceDetails.setTags(resourceTag);
624                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, updatedResourceDetails.getUniqueId(), "");
625                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
626                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
627                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
628                 parseResponseAndValidate(updatedResourceDetails, updatedRestResponse);
629
630                 // Delete resources
631                 response = ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, updatedResourceDetails.getName(), "0.1");
632                 BaseRestUtils.checkDeleteResponse(response);
633                 response = ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, updatedResourceDetails.getName(), "0.2");
634                 BaseRestUtils.checkDeleteResponse(response);
635
636         }
637
638         @Test
639         public void UpdateIcon_InegativeFlow() throws Exception {
640
641                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
642                 String resourceName = resourceDetails.getName();
643
644                 List<String> resourceList = new ArrayList<String>();
645                 resourceList.add(0, "Resource");
646                 // check InValid Characters
647                 char[] notValidCharsArray = new char[59];
648                 notValidCharsArray = getInValidChars();
649                 // update metadata details
650                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
651                 RestResponse updatedRestResponse;
652
653                 for (int i = 0; i < notValidCharsArray.length; i++) {
654                         // change icon of metadata
655                         updatedResourceDetails.setIcon("MyIcon" + notValidCharsArray[i]);
656                         // PUT request
657                         updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
658                         // validate response
659                         assertNotNull("check response object is not null after update resource", updatedRestResponse);
660                         assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
661                         ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_ICON.name(), resourceList, updatedRestResponse.getResponse());
662                         assertEquals("Check response code after updating resource icon", 400, updatedRestResponse.getErrorCode().intValue());
663                         assertEquals("Check response code after updating resource icon", "Bad Request", updatedRestResponse.getResponseMessage().toString());
664
665                 }
666
667                 // empty icon
668                 String updateIcon = "";
669                 updatedResourceDetails.setIcon(updateIcon);
670                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
671                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
672                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
673                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_ICON.name(), resourceList, updatedRestResponse.getResponse());
674
675                 // Icon length more then 25 characters
676                 resourceList.add(1, "25");
677                 updatedResourceDetails.setIcon("1234567890_-qwertyuiopASDNNN");
678                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
679                 // validate response
680                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
681                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
682                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT.name(), resourceList, updatedRestResponse.getResponse());
683                 assertEquals("Check response code after create resource", 400, updatedRestResponse.getErrorCode().intValue());
684                 assertEquals("Check response code after updating resource icon", "Bad Request", updatedRestResponse.getResponseMessage().toString());
685
686                 // get resource with original name. original metadata should be returned
687                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
688                 // validate response
689                 assertNotNull("check response object is not null after get resource", getRestResponse);
690                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
691                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
692
693                 // parse updated response to javaObject
694                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
695                 // validate that metadata was not changed
696                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
697
698         }
699
700         @Test
701         public void UpdateResource_NoTagsEqualToResourceName() throws Exception {
702
703                 User adminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
704                 String resourceBaseVersion = "0.1";
705
706                 // create resource
707                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
708                 String resourceName = resourceDetails.getName();
709
710                 ResourceReqDetails updatedResourceDetails = defineResourse();
711                 updatedResourceDetails.setName("updatedResourceName");
712                 List<String> tags = updatedResourceDetails.getTags();
713
714                 for (Iterator<String> iter = tags.listIterator(); iter.hasNext();) {
715                         String a = iter.next();
716                         if (a.equals("updatedResourceName")) {
717                                 iter.remove();
718                         }
719                 }
720
721                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
722                 // validate response
723                 List<String> resourceList = new ArrayList<String>();
724                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
725                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
726                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME.name(), resourceList, updatedRestResponse.getResponse());
727                 assertEquals("Check response code after updating resource icon", 400, updatedRestResponse.getErrorCode().intValue());
728
729                 // get resource with original name. original metadata should be returned
730                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
731                 // validate response
732                 assertNotNull("check response object is not null after get resource", getRestResponse);
733                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
734                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
735                 // parse updated response to javaObject
736                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
737                 // validate that metadata was not changed
738                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
739
740         }
741
742         @Test
743         public void UpdateResourceName_negativeFlow() throws Exception {
744                 // The validation are done in Tag's validation
745                 User sdncAdminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
746
747                 RestResponse updatedRestResponse;
748                 RestResponse restResponse = createResource(sdncAdminModifierDetails, resourceDetails);
749                 assertEquals("create resource failed", 201, restResponse.getErrorCode().intValue());
750                 String uniqueId = resourceDetails.getUniqueId();
751                 String resourceName = resourceDetails.getName();
752                 // check InValid Characters
753                 char[] notValidCharsArray = new char[59];
754                 notValidCharsArray = getInValidChars();
755                 ArrayList<String> resource_Name = new ArrayList<String>();
756                 List<String> resourceList = new ArrayList<String>();
757
758                 ArrayList<String> resourceTags = new ArrayList<String>();
759                 resourceList.add(0, "Resource");
760
761                 // update metadata details
762                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
763                 for (int i = 0; i < notValidCharsArray.length; i++, resource_Name.clear()) {
764                         if (i != 1 && i != 46 && /*
765                                                                                  * i != 8 && i != 9 && i != 10 && i != 11 && i != 12 &&
766                                                                                  */ i != 31) // space ("") and dot(.)
767                         {
768                                 // change resourceName parameter
769                                 updatedResourceDetails.setName("UpdatedResourceName" + notValidCharsArray[i]);
770                                 resource_Name.add("UpdatedResourceName" + notValidCharsArray[i]);
771                                 updatedResourceDetails.setTags(resource_Name);
772                                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncAdminModifierDetails, uniqueId, "");
773                                 // validate response
774                                 // ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_TAG.name(),
775                                 // Empty_List, updatedRestResponse.getResponse());
776                                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_COMPONENT_NAME.name(), resourceList, updatedRestResponse.getResponse());
777
778                         }
779                 }
780
781                 // resourceName length more then 50 characters
782                 // Duplicate tags are allowed and should be de-duplicated by server side
783                 resource_Name.add(resourceName);
784                 resource_Name.add("tag1");
785                 resource_Name.add("tag1");
786                 resource_Name.add("tag2");
787                 resource_Name.add("tag2");
788
789                 resourceList.add(1, "1024");
790                 // updatedResourceDetails.setName("123456789012345678901234567890123456789012345678901");
791                 updatedResourceDetails.setName(new String(new char[1025]).replace("\0", "a"));
792                 // resource_Name.add("123456789012345678901234567890123456789012345678901");
793                 updatedResourceDetails.setTags(resource_Name);
794                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncAdminModifierDetails, uniqueId, "");
795                 // validate response
796                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT.name(), resourceList, updatedRestResponse.getResponse());
797
798                 // get resource with original name. original metadata should be returned
799                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncAdminModifierDetails, resourceDetails.getUniqueId());
800                 // validate response
801                 assertNotNull("check response object is not null after get resource", getRestResponse);
802                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
803                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
804                 // parse updated response to javaObject
805                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
806                 // validate that metadata was not changed
807                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
808
809                 // delete resource
810                 RestResponse response = ResourceRestUtils.deleteResourceByNameAndVersion(sdncAdminModifierDetails, updatedResourceDetails.getName(), "0.1");
811                 BaseRestUtils.checkDeleteResponse(response);
812         }
813
814         @Test
815         public void UpdateResourceInformation_NotCheckedOut() throws Exception {
816
817                 String resourceBaseVersion = "0.1";
818                 List<String> resourceList = new ArrayList<String>();
819
820                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
821                 String resourceName = resourceDetails.getName();
822
823                 // CheckIn Resource
824                 logger.debug("Changing resource life cycle ");
825                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN); // NOT_CERTIFIED_CHECKIN
826                 assertNotNull("check response object is not null after checkout resource", checkoutResource);
827                 assertNotNull("check error code exists in response after checkIn resource", checkoutResource.getErrorCode());
828                 assertEquals("Check response code after checkin resource", 200, checkoutResource.getErrorCode().intValue());
829
830                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
831
832                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
833                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
834                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
835                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_OPERATION.name(), resourceList, updatedRestResponse.getResponse());
836                 assertEquals("Check response code after updating resource icon", 409, updatedRestResponse.getErrorCode().intValue());
837
838                 // get resource with original name. original metadata should be returned
839                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
840                 // validate response
841                 assertNotNull("check response object is not null after get resource", getRestResponse);
842                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
843                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
844
845                 // parse updated response to javaObject
846                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
847                 // validate that metadata was not changed
848                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
849
850         }
851
852         @Test
853         public void UpdateResourceInformation_resourceVersion_11() throws Exception {
854
855                 User adminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
856                 String resourceBaseVersion = "0.1";
857
858                 // create resource
859                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
860                 String resourceName = resourceDetails.getName();
861
862                 // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
863                 // restResponse);
864
865                 // Certify Resource
866                 logger.debug("Changing resource life cycle ");
867                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
868                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
869
870                 logger.debug("Changing resource life cycle ");
871                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
872                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
873
874                 logger.debug("Changing resource life cycle ");
875                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
876                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
877
878                 logger.debug("Changing resource life cycle ");
879                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFY);
880                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
881
882                 String resourceCertifyVersion = "1.0";
883                 logger.debug("Changing resource life cycle ");
884                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceDetails.getVersion(), LifeCycleStatesEnum.CHECKOUT);
885                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
886
887                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
888
889                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
890                 // validate response
891                 List<String> resourceList = new ArrayList<String>();
892                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
893                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
894                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_OPERATION.name(), resourceList, updatedRestResponse.getResponse());
895                 // assertEquals("Check response code after updating resource icon", 409,
896                 // updatedRestResponse.getErrorCode().intValue());
897
898                 // get resource with original name. original metadata should be returned
899                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
900                 // validate response
901                 assertNotNull("check response object is not null after get resource", getRestResponse);
902
903                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
904
905                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
906                 // parse updated response to javaObject
907                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
908                 // validate that metadata was not changed
909                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
910
911         }
912
913         @Test
914         public void UpdateResourceInformation_resourceVersion_02() throws Exception {
915
916                 String resourceBaseVersion = "0.1";
917
918                 // create resource
919                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
920                 String resourceName = resourceDetails.getName();
921
922                 // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
923                 // restResponse);
924
925                 // Certify Resource
926                 logger.debug("Changing resource life cycle ");
927                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
928                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
929
930                 // String resourceCertifyVersion = "0.1";
931                 logger.debug("Changing resource life cycle ");
932                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKOUT);
933                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
934
935                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
936
937                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
938                 // validate response
939                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
940                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
941                 assertEquals("Check response code after updating resource icon", 200, updatedRestResponse.getErrorCode().intValue());
942
943                 // get resource with original name. original metadata should be returned
944                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
945                 // validate response
946                 assertNotNull("check response object is not null after get resource", getRestResponse);
947                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
948                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
949
950                 // parse updated response to javaObject
951                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
952                 // validate that metadata was not changed
953                 ResourceValidationUtils.validateResourceReqVsResp(updatedResourceDetails, getResourceRespJavaObject);
954
955                 // delete resource
956                 RestResponse response = ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, updatedResourceDetails.getName(), "0.1");
957                 BaseRestUtils.checkDeleteResponse(response);
958                 response = ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, updatedResourceDetails.getName(), "0.2");
959                 BaseRestUtils.checkDeleteResponse(response);
960
961         }
962
963         @Test
964         public void UpdateResourceIcon_resourceVersion_11() throws Exception {
965                 // Can be changed only if major version is 0.
966
967                 User adminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
968                 String resourceBaseVersion = "0.1";
969
970                 // create resource
971                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
972                 String resourceName = resourceDetails.getName();
973
974                 // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
975                 // restResponse);
976
977                 // Certify Resource
978                 logger.debug("Changing resource life cycle ");
979                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
980                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
981
982                 logger.debug("Changing resource life cycle ");
983                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
984                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
985
986                 logger.debug("Changing resource life cycle ");
987                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
988                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
989
990                 logger.debug("Changing resource life cycle ");
991                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFY);
992                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
993
994                 String resourceCertifyVersion = "1.0";
995                 logger.debug("Changing resource life cycle ");
996                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceCertifyVersion, LifeCycleStatesEnum.CHECKOUT);
997                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
998
999                 // ResourceReqDetails updatedResourceDetails =
1000                 // defineUpdatedResourse(resourceName);
1001                 ResourceReqDetails updatedResourceDetails = defineResourse();
1002                 // updatedResourceDetails.setVendorName("updatedVandorName");
1003                 updatedResourceDetails.setIcon("updatedIcon");
1004
1005                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1006                 // validate response
1007                 List<String> resourceList = new ArrayList<String>();
1008                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED.name(), resourceList, updatedRestResponse.getResponse());
1009
1010                 // get resource with original name. original metadata should be returned
1011                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
1012                 // validate response
1013                 assertNotNull("check response object is not null after get resource", getRestResponse);
1014                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
1015                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
1016                 // parse updated response to javaObject
1017                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
1018                 // validate that metadata was not changed
1019                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
1020
1021         }
1022
1023         @Test
1024         public void UpdateResourceVandorName_resourceVersion_11() throws Exception {
1025                 // Can be changed only if the major resource version is 0.
1026                 User adminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
1027                 String resourceBaseVersion = "0.1";
1028
1029                 // create resource
1030                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1031                 String resourceName = resourceDetails.getName();
1032
1033                 // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
1034                 // restResponse);
1035
1036                 // Certify Resource
1037                 logger.debug("Changing resource life cycle ");
1038                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
1039                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1040
1041                 logger.debug("Changing resource life cycle ");
1042                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
1043                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1044
1045                 logger.debug("Changing resource life cycle ");
1046                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
1047                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1048
1049                 logger.debug("Changing resource life cycle ");
1050                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFY);
1051                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1052
1053                 String resourceCertifyVersion = "1.0";
1054                 logger.debug("Changing resource life cycle ");
1055                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceCertifyVersion, LifeCycleStatesEnum.CHECKOUT);
1056                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1057
1058                 // ResourceReqDetails updatedResourceDetails =
1059                 // defineUpdatedResourse(resourceName);
1060                 ResourceReqDetails updatedResourceDetails = defineResourse();
1061
1062                 updatedResourceDetails.setVendorName("updatedVandorName");
1063
1064                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1065                 // validate response
1066                 List<String> resourceList = new ArrayList<String>();
1067                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1068                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1069                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED.name(), resourceList, updatedRestResponse.getResponse());
1070                 assertEquals("Check response code after updating resource icon", 400, updatedRestResponse.getErrorCode().intValue());
1071
1072                 // get resource with original name. original metadata should be returned
1073                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
1074                 // validate response
1075                 assertNotNull("check response object is not null after get resource", getRestResponse);
1076                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
1077                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
1078                 // parse updated response to javaObject
1079                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
1080                 // validate that metadata was not changed
1081                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
1082
1083         }
1084
1085         @Test
1086         public void UpdateResourceName_resourceVersion_11() throws Exception {
1087                 // Can be changed only if the major resource version is 0.
1088                 User adminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
1089                 String resourceBaseVersion = "0.1";
1090
1091                 // create resource
1092                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1093                 assertEquals("create resource failed", 201, restResponse.getErrorCode().intValue());
1094                 String resourceName = resourceDetails.getName();
1095
1096                 // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
1097                 // restResponse);
1098
1099                 // Certify Resource
1100                 logger.debug("Changing resource life cycle ");
1101                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
1102                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1103
1104                 logger.debug("Changing resource life cycle ");
1105                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
1106                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1107
1108                 logger.debug("Changing resource life cycle ");
1109                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
1110                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1111
1112                 logger.debug("Changing resource life cycle ");
1113                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFY);
1114                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1115
1116                 String resourceCertifyVersion = "1.0";
1117                 logger.debug("Changing resource life cycle ");
1118                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceCertifyVersion, LifeCycleStatesEnum.CHECKOUT);
1119                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1120
1121                 /*
1122                  * //ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName); ResourceReqDetails updatedResourceDetails = defineResourse();
1123                  * 
1124                  * updatedResourceDetails.setResourceName("updatedResourceName"); updatedResourceDetails.setIcon("updatedResourceName");
1125                  */
1126                 resourceDetails.setName("updatedResourceName");
1127                 List<String> tagList = new ArrayList<String>();
1128                 tagList.add(0, "updatedResourceName");
1129                 resourceDetails.setTags(tagList);
1130
1131                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1132                 // validate response
1133                 List<String> resourceList = new ArrayList<String>();
1134                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1135                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1136                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED.name(), resourceList, updatedRestResponse.getResponse());
1137
1138         }
1139
1140         @Test
1141         public void UpdateResourceTag_resourceVersion_11() throws Exception {
1142                 // Tag Can be updated when major version is 0.
1143                 User adminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
1144                 String resourceBaseVersion = "0.1";
1145
1146                 // create resource
1147                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1148                 String resourceName = resourceDetails.getName();
1149
1150                 // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
1151                 // restResponse);
1152
1153                 // Certify Resource
1154                 logger.debug("Changing resource life cycle ");
1155                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
1156                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1157
1158                 logger.debug("Changing resource life cycle ");
1159                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
1160                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1161
1162                 logger.debug("Changing resource life cycle ");
1163                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
1164                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1165
1166                 logger.debug("Changing resource life cycle ");
1167                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFY);
1168                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1169
1170                 String resourceCertifyVersion = "1.0";
1171                 logger.debug("Changing resource life cycle ");
1172                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceCertifyVersion, LifeCycleStatesEnum.CHECKOUT);
1173                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1174
1175                 // ResourceReqDetails updatedResourceDetails =
1176                 // defineUpdatedResourse(resourceName);
1177                 ResourceReqDetails updatedResourceDetails = defineResourse();
1178                 // updatedResourceDetails.setVendorName("updatedVandorName");
1179
1180                 ArrayList<String> resourceTags = new ArrayList<String>();
1181                 resourceTags.add("NewTag");
1182                 resourceTags.add(resourceDetails.getName());
1183
1184                 updatedResourceDetails.setTags(resourceTags);
1185
1186                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1187                 // validate response
1188                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1189                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1190                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1191
1192                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
1193                 assertNotNull("check response object is not null after update resource", getRestResponse);
1194                 parseResponseAndValidate(updatedResourceDetails, getRestResponse);
1195
1196         }
1197
1198         @Test
1199         public void UpdateAllowedParames_resourceVersion_11() throws Exception {
1200
1201                 // Tag, contactId, vendorRelease,tags And description - Can be also
1202                 // updated when major version is NOT 0.
1203                 User adminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
1204                 String resourceBaseVersion = "0.1";
1205
1206                 // create resource
1207                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1208
1209                 // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
1210                 // restResponse);
1211
1212                 // Certify Resource
1213                 logger.debug("Changing resource life cycle ");
1214                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
1215                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1216
1217                 logger.debug("Changing resource life cycle ");
1218                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
1219                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1220
1221                 logger.debug("Changing resource life cycle ");
1222                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
1223                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1224
1225                 logger.debug("Changing resource life cycle ");
1226                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFY);
1227                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1228
1229                 String resourceCertifyVersion = "1.0";
1230                 logger.debug("Changing resource life cycle ");
1231                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceCertifyVersion, LifeCycleStatesEnum.CHECKOUT);
1232                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1233
1234                 // ResourceReqDetails updatedResourceDetails =
1235                 // defineUpdatedResourse(resourceName);
1236                 ResourceReqDetails updatedResourceDetails = defineResourse();
1237                 // updatedResourceDetails.setVendorName("updatedVandorName");
1238
1239                 // updated allowed parameters when major resource version is NOT "0"
1240                 ArrayList<String> resourceTags = new ArrayList<String>();
1241                 resourceTags.add("NewTag");
1242                 resourceTags.add(resourceDetails.getName());
1243                 updatedResourceDetails.setTags(resourceTags);
1244                 updatedResourceDetails.setDescription("UpdatedDescription");
1245                 updatedResourceDetails.setVendorRelease("5.1");
1246                 updatedResourceDetails.setContactId("bt750h");
1247
1248                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1249                 // validate response
1250                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1251                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1252                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1253
1254                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
1255                 assertNotNull("check response object is not null after update resource", getRestResponse);
1256                 parseResponseAndValidate(updatedResourceDetails, getRestResponse);
1257
1258         }
1259
1260         @Test
1261         public void UpdateResourceDerivedFrom_resourceVersion_11() throws Exception {
1262                 // DerivedFrom parameter - Can be updated when major version is 0.
1263                 User adminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
1264                 String resourceBaseVersion = "0.1";
1265
1266                 // create resource
1267                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1268                 String resourceName = resourceDetails.getName();
1269
1270                 // resourceUtils.addResourceMandatoryArtifacts(sdncModifierDetails,
1271                 // restResponse);
1272
1273                 // Certify Resource
1274                 logger.debug("Changing resource life cycle ");
1275                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CHECKIN);
1276                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1277
1278                 logger.debug("Changing resource life cycle ");
1279                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFICATIONREQUEST);
1280                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1281
1282                 logger.debug("Changing resource life cycle ");
1283                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.STARTCERTIFICATION);
1284                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1285
1286                 logger.debug("Changing resource life cycle ");
1287                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, adminModifierDetails, resourceBaseVersion, LifeCycleStatesEnum.CERTIFY);
1288                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1289
1290                 String resourceCertifyVersion = "1.0";
1291                 logger.debug("Changing resource life cycle ");
1292                 checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceCertifyVersion, LifeCycleStatesEnum.CHECKOUT);
1293                 assertEquals("Check response code after checkout resource", 200, checkoutResource.getErrorCode().intValue());
1294
1295                 // ResourceReqDetails updatedResourceDetails =
1296                 // defineUpdatedResourse(resourceName);
1297                 ResourceReqDetails updatedResourceDetails = defineResourse();
1298                 ArrayList<String> drivenFrom = new ArrayList<String>();
1299                 drivenFrom.add(0, "tosca.nodes.Container.Application");
1300                 updatedResourceDetails.setDerivedFrom(drivenFrom);
1301
1302                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1303                 // validate response
1304                 List<String> resourceList = new ArrayList<String>();
1305                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESOURCE_DERIVED_FROM_CANNOT_BE_CHANGED.name(), resourceList, updatedRestResponse.getResponse());
1306
1307                 // get resource with original name. original metadata should be returned
1308                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
1309                 // validate response
1310                 assertNotNull("check response object is not null after get resource", getRestResponse);
1311                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
1312                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
1313                 // parse updated response to javaObject
1314                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
1315                 // validate that metadata was not changed
1316                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
1317
1318         }
1319
1320         @Test
1321         public void UpdateResource_vendorNameValidation() throws Exception {
1322
1323                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1324                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
1325                 String updatedVendorName = "";
1326                 String uniqueId = resourceDetails.getUniqueId();
1327                 resourceDetails.setVendorName(updatedVendorName);
1328                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1329                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1330                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1331                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.MISSING_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1332
1333                 // update resource vendorName metadata: 1 characters
1334                 updatedVendorName = "   ";
1335                 // set vendorName
1336                 resourceDetails.setVendorName(updatedVendorName);
1337                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1338                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1339                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1340                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.MISSING_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1341
1342                 // update resource vendorName metadata: 25 characters
1343                 updatedVendorName = "Verification and validati";
1344                 // set vendorName
1345                 resourceDetails.setVendorName(updatedVendorName);
1346                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1347                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1348                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1349                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1350                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1351
1352                 // update resource vendorName metadata: 26 characters
1353                 updatedVendorName = "Verification and validatii";
1354                 // set vendorName
1355                 List<String> myList = new ArrayList<String>();
1356                 myList.add(0, "25");
1357                 resourceDetails.setVendorName(updatedVendorName);
1358                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1359                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1360                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT.name(), myList, updatedRestResponse.getResponse());
1361
1362                 // update resource VendorRelease metadata: forbidden characters
1363                 updatedVendorName = "A1<";
1364                 // set vendorName
1365                 resourceDetails.setVendorName(updatedVendorName);
1366                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1367                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1368                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1369
1370                 updatedVendorName = "A1>";
1371                 // set vendorName
1372                 resourceDetails.setVendorName(updatedVendorName);
1373                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1374                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1375                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1376
1377                 updatedVendorName = "A1:";
1378                 // set vendorName
1379                 resourceDetails.setVendorName(updatedVendorName);
1380                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1381                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1382                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1383
1384                 updatedVendorName = "A1\"";
1385                 // set vendorName
1386                 resourceDetails.setVendorName(updatedVendorName);
1387                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1388                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1389                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1390
1391                 updatedVendorName = "A1/";
1392                 // set vendorName
1393                 resourceDetails.setVendorName(updatedVendorName);
1394                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1395                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1396                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1397
1398                 updatedVendorName = "A1\\";
1399                 // set vendorName
1400                 resourceDetails.setVendorName(updatedVendorName);
1401                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1402                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1403                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1404
1405                 updatedVendorName = "A1|";
1406                 // set vendorName
1407                 resourceDetails.setVendorName(updatedVendorName);
1408                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1409                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1410                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1411
1412                 updatedVendorName = "A1?";
1413                 // set vendorName
1414                 resourceDetails.setVendorName(updatedVendorName);
1415                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1416                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1417                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1418
1419                 updatedVendorName = "A1*";
1420                 // set vendorName
1421                 resourceDetails.setVendorName(updatedVendorName);
1422                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1423                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1424                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1425
1426                 // update resource vendorName metadata: null
1427                 updatedVendorName = null;
1428                 // set vendorName
1429                 resourceDetails.setVendorName(updatedVendorName);
1430                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1431                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1432                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.MISSING_VENDOR_NAME.name(), Empty_List, updatedRestResponse.getResponse());
1433
1434         }
1435
1436         @Test
1437         public void UpdateResource_vendorReleaseValidation() throws Exception {
1438
1439                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1440                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
1441                 RestResponse updatedRestResponse;
1442                 String uniqueId = resourceDetails.getUniqueId();
1443                 String updatedVendorRelease;
1444                 // set VendorRelease
1445
1446                 // update resource VendorRelease metadata: 1 characters
1447                 updatedVendorRelease = "1";
1448                 // set VendorRelease
1449                 resourceDetails.setVendorRelease(updatedVendorRelease);
1450                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1451                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1452                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1453                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1454                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1455
1456                 // update resource VendorRelease metadata: 25 characters
1457                 updatedVendorRelease = "(!#1.00000000000000000000";
1458                 // set VendorRelease
1459                 resourceDetails.setVendorRelease(updatedVendorRelease);
1460                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1461                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1462                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1463                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1464                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1465
1466                 // update resource VendorRelease metadata: 26 characters
1467                 updatedVendorRelease = "(!#1.000000000000000000005";// set VendorRelease
1468                 resourceDetails.setVendorRelease(updatedVendorRelease);
1469                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1470                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT.name(), Arrays.asList("" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH), updatedRestResponse.getResponse());
1471
1472                 // UpdateAndValidate(sdncModifierDetails, resourceDetails,
1473                 // ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT.name(),
1474                 // Arrays.asList(""+ValidationUtils.VENDOR_RELEASE_MAX_LENGTH));
1475
1476                 // update resource VendorRelease metadata: forbidden characters
1477                 updatedVendorRelease = "A1<";
1478                 // set VendorRelease
1479                 resourceDetails.setVendorRelease(updatedVendorRelease);
1480                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1481                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1482
1483                 updatedVendorRelease = "A1>";
1484                 // set VendorRelease
1485                 resourceDetails.setVendorRelease(updatedVendorRelease);
1486                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1487                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1488
1489                 updatedVendorRelease = "A1:";
1490                 // set VendorRelease
1491                 resourceDetails.setVendorRelease(updatedVendorRelease);
1492                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1493                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1494
1495                 updatedVendorRelease = "A1\"";
1496                 // set VendorRelease
1497                 resourceDetails.setVendorRelease(updatedVendorRelease);
1498                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1499                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1500
1501                 updatedVendorRelease = "A1/";
1502                 // set VendorRelease
1503                 resourceDetails.setVendorRelease(updatedVendorRelease);
1504                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1505                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1506
1507                 updatedVendorRelease = "A1\\";
1508                 // set VendorRelease
1509                 resourceDetails.setVendorRelease(updatedVendorRelease);
1510                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1511                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1512
1513                 updatedVendorRelease = "A1|";
1514                 // set VendorRelease
1515                 resourceDetails.setVendorRelease(updatedVendorRelease);
1516                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1517                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1518
1519                 updatedVendorRelease = "A1?";
1520                 // set VendorRelease
1521                 resourceDetails.setVendorRelease(updatedVendorRelease);
1522                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1523                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1524
1525                 updatedVendorRelease = "A1*";
1526                 // set VendorRelease
1527                 resourceDetails.setVendorRelease(updatedVendorRelease);
1528                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1529                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1530
1531                 // update resource VendorRelease metadata: null
1532                 updatedVendorRelease = null;
1533                 // set VendorRelease
1534                 resourceDetails.setVendorRelease(updatedVendorRelease);
1535                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1536                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1537                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.MISSING_VENDOR_RELEASE.name(), Empty_List, updatedRestResponse.getResponse());
1538
1539         }
1540
1541         @Test
1542         public void UpdateResource_contactIdValidation() throws Exception { // [a-zA-Z]{2}[0-9]{3}[a-zA-Z0-9]{1}
1543                                                                                                                                                         // (6
1544                                                                                                                                                         // characters
1545                                                                                                                                                         // now,
1546                                                                                                                                                         // may
1547                                                                                                                                                         // be
1548                                                                                                                                                         // expanded
1549                                                                                                                                                         // up
1550                                                                                                                                                         // to
1551                                                                                                                                                         // 8
1552                                                                                                                                                         // characters
1553                                                                                                                                                         // in
1554                                                                                                                                                         // the
1555                                                                                                                                                         // future).
1556                                                                                                                                                         // Convert
1557                                                                                                                                                         // Upper
1558                                                                                                                                                         // case
1559                                                                                                                                                         // character
1560                                                                                                                                                         // to
1561                                                                                                                                                         // lower
1562                                                                                                                                                         // case
1563                 RestResponse updatedRestResponse;
1564
1565                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1566                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
1567                 String uniqueId = resourceDetails.getUniqueId();
1568
1569                 List<String> myList = new ArrayList<String>();
1570                 myList.add(0, "Resource");
1571                 String updatedContactId = "";
1572                 resourceDetails.setContactId(updatedContactId);
1573
1574                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1575                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_CONTACT.name(), myList, updatedRestResponse.getResponse());
1576
1577                 updatedContactId = "ab12345";
1578                 resourceDetails.setContactId(updatedContactId);
1579                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1580                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1581
1582                 updatedContactId = "      ";
1583                 resourceDetails.setContactId(updatedContactId);
1584                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1585                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_CONTACT.name(), myList, updatedRestResponse.getResponse());
1586
1587                 updatedContactId = "ab 50h";
1588                 resourceDetails.setContactId(updatedContactId);
1589                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1590                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1591
1592                 updatedContactId = "ab123c";
1593                 resourceDetails.setContactId(updatedContactId);
1594                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1595                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1596                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1597                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1598
1599                 updatedContactId = "cd789E";
1600                 resourceDetails.setContactId(updatedContactId);
1601                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1602                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1603                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1604                 // contactId norm
1605                 resourceDetails.setContactId(updatedContactId.toLowerCase());
1606                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1607
1608                 updatedContactId = "ef4567";
1609                 resourceDetails.setContactId(updatedContactId);
1610                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1611                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1612                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1613                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1614                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1615
1616                 updatedContactId = "AA012A";
1617                 resourceDetails.setContactId(updatedContactId);
1618                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1619                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1620                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1621                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1622                 // contactId norm
1623                 resourceDetails.setContactId(updatedContactId.toLowerCase());
1624                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1625
1626                 updatedContactId = "CD012c";
1627                 resourceDetails.setContactId(updatedContactId);
1628                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1629                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1630                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1631                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1632                 // contactId norm
1633                 resourceDetails.setContactId(updatedContactId.toLowerCase());
1634                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1635
1636                 updatedContactId = "EF0123";
1637                 resourceDetails.setContactId(updatedContactId);
1638                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1639                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1640                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1641                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1642                 // contactId norm
1643                 resourceDetails.setContactId(updatedContactId.toLowerCase());
1644                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1645
1646                 ////////////////////////////// **************//////////////////////////////
1647                 List<String> resource = Arrays.asList("Resource");
1648                 updatedContactId = "01345a";
1649                 resourceDetails.setContactId(updatedContactId);
1650                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1651                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1652
1653                 updatedContactId = "0y000B";
1654                 resourceDetails.setContactId(updatedContactId);
1655                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1656                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1657
1658                 updatedContactId = "Y1000b";
1659                 resourceDetails.setContactId(updatedContactId);
1660                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1661                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1662
1663                 updatedContactId = "abxyzC";
1664                 resourceDetails.setContactId(updatedContactId);
1665                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1666                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1667
1668                 updatedContactId = "cdXYZc";
1669                 resourceDetails.setContactId(updatedContactId);
1670                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1671                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1672
1673                 updatedContactId = "efXY1D";
1674                 resourceDetails.setContactId(updatedContactId);
1675                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1676                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1677
1678                 updatedContactId = "EFabcD";
1679                 resourceDetails.setContactId(updatedContactId);
1680                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1681                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1682
1683                 updatedContactId = "EFABCD";
1684                 resourceDetails.setContactId(updatedContactId);
1685                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1686                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1687
1688                 updatedContactId = "EFABC1";
1689                 resourceDetails.setContactId(updatedContactId);
1690                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1691                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1692
1693                 updatedContactId = "efui1D";
1694                 resourceDetails.setContactId(updatedContactId);
1695                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1696                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1697
1698                 updatedContactId = "efui1!";
1699                 resourceDetails.setContactId(updatedContactId);
1700                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1701                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1702
1703                 updatedContactId = "ef555!";
1704                 resourceDetails.setContactId(updatedContactId);
1705                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1706                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1707
1708                 updatedContactId = ",f555";
1709                 resourceDetails.setContactId(updatedContactId);
1710                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1711                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1712
1713                 updatedContactId = "EF55.5";
1714                 resourceDetails.setContactId(updatedContactId);
1715                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1716                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1717
1718                 // update resource contactId metadata: extended character set (128–255)
1719                 resourceDetails.setContactId(extendedCharsStringBuilder());
1720                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1721                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CONTACT.name(), myList, updatedRestResponse.getResponse());
1722
1723                 // update resource contactId metadata: null
1724                 updatedContactId = null;
1725                 resourceDetails.setContactId(updatedContactId);
1726                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1727                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_CONTACT.name(), myList, updatedRestResponse.getResponse());
1728
1729         }
1730
1731         @Test
1732         public void UpdateResource_TagsFieldValidation() throws Exception {
1733                 RestResponse updatedRestResponse;
1734                 // define and create resource
1735
1736                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1737                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
1738                 String uniqueId = resourceDetails.getUniqueId();
1739
1740                 String updatedTagField = "";
1741                 ArrayList<String> resourceTags = new ArrayList<String>();
1742                 resourceTags.add(updatedTagField);
1743                 // set description
1744                 resourceDetails.setTags(resourceTags);
1745                 List<String> variables = Arrays.asList("Resource", "tag");
1746                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1747                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_FIELD_FORMAT.name(), variables, updatedRestResponse.getResponse());
1748
1749                 // update resource tags metadata: empty
1750                 resourceTags = new ArrayList<String>();
1751                 // set Tags
1752                 resourceDetails.setTags(resourceTags);
1753                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1754                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_TAGS.name(), Empty_List, updatedRestResponse.getResponse());
1755
1756                 // update resource description metadata: 1 characters
1757                 updatedTagField = "A";
1758                 resourceTags = new ArrayList<String>();
1759                 resourceTags.add(updatedTagField);
1760                 resourceTags.add(resourceDetails.getName());
1761                 // set description
1762                 resourceDetails.setTags(resourceTags);
1763                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1764                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1765                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1766                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1767                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1768
1769                 // OK - tag up to 50 chars
1770                 updatedTagField = "The Indian-crested.porcupine_The Indian cresteddds";
1771                 resourceTags.add(updatedTagField);
1772                 resourceDetails.setTags(resourceTags);
1773                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1774                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1775                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1776                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1777                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1778
1779                 // OK - sum is 1024, 50x20+48+20(commas)+6(cisco4 - resource name)
1780                 String updatedTagField1 = "The Indian-crested.porcupine_The Indian crestedd01";
1781                 String updatedTagField2 = "The Indian-crested.porcupine_The Indian crestedd02";
1782                 String updatedTagField3 = "The Indian-crested.porcupine_The Indian crestedd03";
1783                 String updatedTagField4 = "The Indian-crested.porcupine_The Indian crestedd04";
1784                 String updatedTagField5 = "The Indian-crested.porcupine_The Indian crestedd05";
1785                 String updatedTagField6 = "The Indian-crested.porcupine_The Indian crestedd06";
1786                 String updatedTagField7 = "The Indian-crested.porcupine_The Indian crestedd07";
1787                 String updatedTagField8 = "The Indian-crested.porcupine_The Indian crestedd08";
1788                 String updatedTagField9 = "The Indian-crested.porcupine_The Indian crestedd09";
1789                 String updatedTagField10 = "The Indian-crested.porcupine_The Indian crestedd10";
1790                 String updatedTagField11 = "The Indian-crested.porcupine_The Indian crestedd11";
1791                 String updatedTagField12 = "The Indian-crested.porcupine_The Indian crestedd12";
1792                 String updatedTagField13 = "The Indian-crested.porcupine_The Indian crestedd13";
1793                 String updatedTagField14 = "The Indian-crested.porcupine_The Indian crestedd14";
1794                 String updatedTagField15 = "The Indian-crested.porcupine_The Indian crestedd15";
1795                 String updatedTagField16 = "The Indian-crested.porcupine_The Indian crestedd16";
1796                 String updatedTagField17 = "The Indian-crested.porcupine_The Indian crestedd17";
1797                 String updatedTagField18 = "The Indian-crested.porcupine_The Indian crestedd18";
1798                 String updatedTagField19 = "The Indian-crested.porcupine_The Indian crestaa";
1799
1800                 resourceTags = new ArrayList<String>();
1801                 resourceTags.add(updatedTagField);
1802                 resourceTags.add(updatedTagField1);
1803                 resourceTags.add(updatedTagField2);
1804                 resourceTags.add(updatedTagField3);
1805                 resourceTags.add(updatedTagField4);
1806                 resourceTags.add(updatedTagField5);
1807                 resourceTags.add(updatedTagField6);
1808                 resourceTags.add(updatedTagField7);
1809                 resourceTags.add(updatedTagField8);
1810                 resourceTags.add(updatedTagField9);
1811                 resourceTags.add(updatedTagField10);
1812                 resourceTags.add(updatedTagField11);
1813                 resourceTags.add(updatedTagField12);
1814                 resourceTags.add(updatedTagField13);
1815                 resourceTags.add(updatedTagField14);
1816                 resourceTags.add(updatedTagField15);
1817                 resourceTags.add(updatedTagField16);
1818                 resourceTags.add(updatedTagField17);
1819                 resourceTags.add(updatedTagField18);
1820                 resourceTags.add(updatedTagField19);
1821                 resourceTags.add(resourceDetails.getName());
1822                 // set description
1823                 resourceDetails.setTags(resourceTags);
1824                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1825                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1826                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1827                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1828                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1829
1830                 // Add another tag-exceeds limit
1831                 resourceTags.add("d");
1832                 resourceDetails.setTags(resourceTags);
1833                 ArrayList<String> myArray = new ArrayList<String>();
1834                 myArray.add(0, "1024");
1835                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1836                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT.name(), myArray, updatedRestResponse.getResponse());
1837
1838                 // Tag exceeds limit - 51
1839                 resourceTags = new ArrayList<String>();
1840                 updatedTagField = "The Indian-crested.porcupine_The Indian crestedddsw";
1841                 resourceTags.add(updatedTagField);
1842                 resourceTags.add(resourceDetails.getName());
1843                 // set description
1844                 resourceDetails.setTags(resourceTags);
1845                 myArray.remove(0);
1846                 myArray.add(0, "50");
1847                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1848                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT.name(), myArray, updatedRestResponse.getResponse());
1849
1850         }
1851
1852         @Test
1853         public void UpdateResource_DesriptionFieldValidation() throws Exception {
1854                 // define and create resource
1855                 RestResponse updatedRestResponse;
1856
1857                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1858                 String uniqueId = resourceDetails.getUniqueId();
1859                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
1860                 List<String> resource = new ArrayList<>();
1861                 resource.add("Resource");
1862                 // update resource description metadata: 0 characters
1863                 String updatedDescription = "";
1864                 // set description
1865                 resourceDetails.setDescription(updatedDescription);
1866                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1867                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_DESCRIPTION.name(), resource, updatedRestResponse.getResponse());
1868
1869                 // update resource description metadata: null
1870                 updatedDescription = null;
1871                 // set description
1872                 resourceDetails.setDescription(updatedDescription);
1873                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1874                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_DESCRIPTION.name(), resource, updatedRestResponse.getResponse());
1875
1876                 // update resource description metadata: 1 characters
1877                 updatedDescription = "A";
1878                 // set description
1879                 resourceDetails.setDescription(updatedDescription);
1880                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1881                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1882                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1883                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1884                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1885
1886                 // update resource description metadata: 1024 characters
1887                 updatedDescription = "The Indian crested porcupine *{Hystrix indica}*, or Indian porcupine is a member of the Old World porcupines." + "It is quite an adaptable rodent, found throughout southern Asia and the Middle East."
1888                                 + "It is tolerant of several different habitats: mountains, tropical and subtropical grasslands, scrublands, and forests."
1889                                 + "It is a large rodent, growing more than 0.9 m = (3 ft) long and weighing 14.5 kg = (32 lb)! [citation needed] It is covered in multiple layers of quills."
1890                                 + "The longest quills grow from its shoulders to about a third of the animal's length." + "Its tail is covered in short, hollow quills that can rattle when threatened."
1891                                 + "It has broad feet and long claws for digging. When attacked, the Indian crested porcupine raises its quills and rattles the hollow quills on its tail."
1892                                 + "If the predator persists past these threats, the porcupine launches a backwards assault, hoping to stab its attacker with its quills."
1893                                 + "It does this so effectively that most brushes between predators and the Indian porcupine end in death or severe injury";
1894                 // set description
1895                 resourceDetails.setDescription(updatedDescription);
1896                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1897                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1898                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1899                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
1900                 parseResponseAndValidate(resourceDetails, updatedRestResponse);
1901
1902                 // update resource description metadata: 1025 characters
1903                 updatedDescription = "The Indian crested porcupine *{Hystrix indica}*, or Indian porcupine is a member of the Old World porcupines." + "It is quite an adaptable rodent, found throughout southern Asia and the Middle East."
1904                                 + "It is tolerant of several different habitats: mountains, tropical and subtropical grasslands, scrublands, and forests."
1905                                 + "It is a large rodent, growing more than 0.9 m = (3 ft) long and weighing 14.5 kg = (32 lb)! [citation needed] It is covered in multiple layers of quills."
1906                                 + "The longest quills grow from its shoulders to about a third of the animal's length." + "Its tail is covered in short, hollow quills that can rattle when threatened."
1907                                 + "It has broad feet and long claws for digging. When attacked, the Indian crested porcupine raises its quills and rattles the hollow quills on its tail."
1908                                 + "If the predator persists past these threats, the porcupine launches a backwards assault, hoping to stab its attacker with its quills."
1909                                 + "It does this so effectively that most brushes between predators and the Indian porcupine end in death or severe injury.";
1910                 // set description
1911                 resourceDetails.setDescription(updatedDescription);
1912                 resource.add(1, "1024");
1913                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, uniqueId, "");
1914                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT.name(), resource, updatedRestResponse.getResponse());
1915
1916         }
1917
1918         @Test
1919         public void UpdateResource_TagsFormatValidation() throws Exception {
1920                 char[] notValidCharsArray = getTagInValidFormatChars();
1921
1922                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1923                 assertEquals("Check recourse created ", 201, restResponse.getErrorCode().intValue());
1924                 String resourceName = resourceDetails.getName();
1925
1926                 // update tag details
1927                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
1928                 ArrayList<String> resourceTags = new ArrayList<String>();
1929
1930                 String updatedTagField;
1931                 RestResponse updatedRestResponse;
1932                 List<String> variables = Arrays.asList("Resource", "tag");
1933
1934                 for (int i = 0; i < notValidCharsArray.length; i++) {
1935                         updatedTagField = "UpdatedTag" + notValidCharsArray[i];
1936                         resourceTags = new ArrayList<String>();
1937                         resourceTags.add(updatedTagField);
1938                         resourceTags.add(resourceDetails.getName());
1939                         // set description
1940                         updatedResourceDetails.setTags(resourceTags);
1941
1942                         updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1943                         // validate response
1944                         assertNotNull("check response object is not null after update resource", updatedRestResponse);
1945                         assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1946                         ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_FIELD_FORMAT.name(), variables, updatedRestResponse.getResponse());
1947                         assertEquals("Check response code after updating resource icon", 400, updatedRestResponse.getErrorCode().intValue());
1948                         assertEquals("Check response code after updating resource icon", "Bad Request", updatedRestResponse.getResponseMessage().toString());
1949
1950                 }
1951
1952         }
1953
1954         @Test
1955         public void UpdateResourceCategory_negativeFlow() throws Exception {
1956
1957                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
1958                 assertEquals("Check response code after update resource", 201, restResponse.getErrorCode().intValue());
1959                 Resource resourceBeforeUpdate = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
1960                 String uniqueID = resourceDetails.getUniqueId();
1961
1962                 // Update resource Category Successfully
1963                 ResourceReqDetails updatedResourceDetails = resourceDetails;
1964
1965                 updatedResourceDetails.removeAllCategories();
1966                 updatedResourceDetails.addCategoryChain(ServiceCategoriesEnum.MOBILITY.getValue(), ResourceCategoryEnum.APPLICATION_L4_DATABASE.getSubCategory());
1967                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1968
1969                 // validate response
1970                 List<String> resourceList = new ArrayList<String>();
1971                 resourceList.add(0, "Resource");
1972                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1973                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1974                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CATEGORY.name(), resourceList, updatedRestResponse.getResponse());
1975                 assertEquals("Check response code after updating resource", 400, updatedRestResponse.getErrorCode().intValue());
1976
1977                 // Updating resource category
1978                 updatedResourceDetails = defineUpdateResourceWithNonUpdatableFields(resourceBeforeUpdate);
1979                 updatedResourceDetails.addCategory("");
1980                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1981                 // validate response
1982                 resourceList = new ArrayList<String>();
1983                 resourceList.add(0, "Resource");
1984                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1985                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1986                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_CATEGORY.name(), resourceList, updatedRestResponse.getResponse());
1987                 assertEquals("Check response code after updating resource", 400, updatedRestResponse.getErrorCode().intValue());
1988
1989                 // Updating resource category
1990                 updatedResourceDetails = defineUpdateResourceWithNonUpdatableFields(resourceBeforeUpdate);
1991                 updatedResourceDetails.addCategory("XXXXXX");
1992                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
1993                 // validate response
1994                 resourceList = new ArrayList<String>();
1995                 resourceList.add(0, "Resource");
1996                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
1997                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
1998                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_CATEGORY.name(), resourceList, updatedRestResponse.getResponse());
1999                 assertEquals("Check response code after updating resource", 400, updatedRestResponse.getErrorCode().intValue());
2000
2001                 // CheckIn Resource
2002                 logger.debug("Changing resource life cycle ");
2003                 RestResponse checkoutResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceDetails.getVersion(), LifeCycleStatesEnum.CHECKIN); // NOT_CERTIFIED_CHECKIN
2004                 assertEquals("Check response code after checkin resource", 200, checkoutResource.getErrorCode().intValue());
2005
2006                 // Update resource Category
2007                 updatedResourceDetails = defineUpdateResourceWithNonUpdatableFields(resourceBeforeUpdate);
2008                 updatedResourceDetails.addCategory(ServiceCategoriesEnum.VOIP.getValue());
2009                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
2010                 // verify response
2011                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
2012                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
2013                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_OPERATION.name(), Empty_List, updatedRestResponse.getResponse());
2014                 assertEquals("Check response code after updating resource", 409, updatedRestResponse.getErrorCode().intValue());
2015
2016                 // CheckIn Resource
2017                 logger.debug("Changing resource life cycle ");
2018                 RestResponse checkinResource = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, resourceDetails.getVersion(), LifeCycleStatesEnum.CHECKOUT); // NOT_CERTIFIED_CHECKIN
2019                 assertNotNull("check response object is not null after checkout resource", checkoutResource);
2020                 assertNotNull("check error code exists in response after checkIn resource", checkoutResource.getErrorCode());
2021                 assertEquals("Check response code after checkin resource", 200, checkoutResource.getErrorCode().intValue());
2022
2023                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, uniqueID);
2024                 assertNotNull("check response object is not null after update resource", getRestResponse);
2025                 parseResponseAndValidate(resourceDetails, getRestResponse);
2026
2027         }
2028
2029         @Test
2030         public void UpdateResourceCategorySuccessfully() throws Exception {
2031
2032                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
2033                 assertEquals("Check response code after update resource", 201, restResponse.getErrorCode().intValue());
2034                 Resource resourceBeforeUpdate = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
2035
2036                 // Update resource Category Successfully
2037                 ResourceReqDetails updatedResourceDetails = resourceDetails;
2038
2039                 updatedResourceDetails.removeAllCategories();
2040                 updatedResourceDetails.addCategoryChain(ResourceCategoryEnum.APPLICATION_L4_DATABASE.getCategory(), ResourceCategoryEnum.APPLICATION_L4_DATABASE.getSubCategory());
2041                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncModifierDetails, resourceDetails.getUniqueId(), "");
2042
2043                 // validate response
2044                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
2045                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
2046                 assertEquals("Check response code after update resource", 200, updatedRestResponse.getErrorCode().intValue());
2047                 // parseResponseAndValidateNonUpdatable(updatedResourceDetails,
2048                 // updatedRestResponse);
2049                 parseResponseAndValidate(updatedResourceDetails, updatedRestResponse);
2050
2051                 // validate category updated
2052                 assertTrue(updatedResourceDetails.getCategories().get(0).getName().equals(ResourceCategoryEnum.APPLICATION_L4_DATABASE.getCategory()));
2053
2054                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncModifierDetails, resourceDetails.getUniqueId());
2055                 assertNotNull("check response object is not null after update resource", getRestResponse);
2056                 parseResponseAndValidate(updatedResourceDetails, getRestResponse);
2057
2058                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncModifierDetails, updatedResourceDetails.getName(), "0.1");
2059         }
2060
2061         // Benny
2062
2063         @Test
2064         public void Validation_UpdateIcon() throws Exception {
2065                 // Fields to update (Forbidden)
2066                 String _updatedIcon = "mySecondIcon.Jpg";
2067
2068                 // administrator permissions
2069                 User sdncAdminModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
2070
2071                 // define and create resource
2072                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncAdminModifierDetails, resourceDetails.getName(), "0.1");
2073
2074                 RestResponse restResponse = createResource(sdncAdminModifierDetails, resourceDetails);
2075                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
2076                 String resourceName = resourceDetails.getName();
2077
2078                 // update metadata details
2079                 ResourceReqDetails updatedResourceDetails = defineUpdatedResourse(resourceName);
2080                 // change icon of metadata
2081                 updatedResourceDetails.setIcon(_updatedIcon);
2082                 // PUT request
2083                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncAdminModifierDetails, resourceDetails.getUniqueId(), "");
2084
2085                 // validate response
2086                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
2087                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
2088                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_INVALID_ICON.name(), Arrays.asList("Resource"), updatedRestResponse.getResponse());
2089
2090                 // empty icon
2091                 _updatedIcon = "";
2092                 updatedResourceDetails.setIcon(_updatedIcon);
2093                 updatedRestResponse = ResourceRestUtils.updateResourceMetadata(updatedResourceDetails, sdncAdminModifierDetails, resourceDetails.getUniqueId(), "");
2094                 assertNotNull("check response object is not null after update resource", updatedRestResponse);
2095                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
2096                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.COMPONENT_MISSING_ICON.name(), Arrays.asList("Resource"), updatedRestResponse.getResponse());
2097
2098                 // get resource with original name. original metadata should be returned
2099                 RestResponse getRestResponse = ResourceRestUtils.getResource(sdncAdminModifierDetails, resourceDetails.getUniqueId());
2100                 // validate response
2101                 assertNotNull("check response object is not null after get resource", getRestResponse);
2102                 assertNotNull("check error code exists in response after get resource", getRestResponse.getErrorCode());
2103                 assertEquals("Check response code after update resource", 200, getRestResponse.getErrorCode().intValue());
2104
2105                 // parse updated response to javaObject
2106                 Resource getResourceRespJavaObject = ResponseParser.convertResourceResponseToJavaObject(getRestResponse.getResponse());
2107                 // validate that metadata was not changed
2108                 ResourceValidationUtils.validateResourceReqVsResp(resourceDetails, getResourceRespJavaObject);
2109
2110                 ResourceRestUtils.deleteResourceByNameAndVersion(sdncAdminModifierDetails, updatedResourceDetails.getName(), "0.1");
2111
2112         }
2113
2114         @Test
2115         public void UpdateResourceTypeSuccess() throws Exception {
2116                 // LCS is CheckOut
2117                 String newResourceType = ResourceTypeEnum.VL.toString();
2118                 String currentResourceType = resourceDetails.getResourceType();
2119                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
2120                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
2121                 Resource currentResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
2122
2123                 resourceDetails.setResourceType(newResourceType);
2124                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, currentResourceJavaObject.getUniqueId(), "");
2125                 assertEquals("Check response code after create resource", 200, updatedRestResponse.getErrorCode().intValue());
2126                 Resource updatedResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(updatedRestResponse.getResponse());
2127                 // assertTrue("Check resource type after update resource",
2128                 // updatedResourceJavaObject.getResourceType().toString().equals(resourceType));
2129                 assertTrue("Check resource type after update resource", updatedResourceJavaObject.getResourceType().toString().equals(currentResourceType));
2130
2131         }
2132
2133         @Test
2134         public void UpdateResourceTypeAndNameSuccess() throws Exception {
2135                 // LCS is CheckOut
2136                 String newResourceType = ResourceTypeEnum.VL.toString();
2137                 String currentResourceType = resourceDetails.getResourceType();
2138                 String newResourceName = "new Name";
2139
2140                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
2141                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
2142                 Resource currentResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
2143
2144                 resourceDetails.setResourceType(newResourceType);
2145                 resourceDetails.setName(newResourceName);
2146                 List<String> tags = resourceDetails.getTags();
2147                 tags.add(newResourceName);
2148                 resourceDetails.setTags(tags);
2149
2150                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, currentResourceJavaObject.getUniqueId(), "");
2151                 assertEquals("Check response code after create resource", 200, updatedRestResponse.getErrorCode().intValue());
2152                 Resource updatedResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(updatedRestResponse.getResponse());
2153                 assertTrue("Check resource type after update resource", updatedResourceJavaObject.getResourceType().toString().equals(currentResourceType));
2154                 assertTrue("Check resource name after update resource", updatedResourceJavaObject.getName().equals(newResourceName));
2155
2156         }
2157
2158         @Test
2159         public void UpdateResourceTypeAfterResourceCertification() throws Exception {
2160
2161                 String newResourceType = ResourceTypeEnum.VF.toString();
2162                 String currentResourceType = resourceDetails.getResourceType();
2163                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
2164                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
2165                 Resource currentResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
2166
2167                 resourceDetails.setResourceType(newResourceType);
2168                 restResponse = LifecycleRestUtils.certifyResource(resourceDetails);
2169                 assertEquals("Check response code after resource CheckIn", 200, restResponse.getErrorCode().intValue());
2170                 restResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKOUT);
2171                 assertEquals("Check response code after resource CheckIn", 200, restResponse.getErrorCode().intValue());
2172                 currentResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
2173
2174                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, currentResourceJavaObject.getUniqueId(), "");
2175                 assertEquals("Check response code after create resource", 200, updatedRestResponse.getErrorCode().intValue());
2176                 Resource updatedResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(updatedRestResponse.getResponse());
2177                 // assertTrue("Check resource type after update resource",
2178                 // updatedResourceJavaObject.getResourceType().toString().equals(newResourceType));
2179                 assertTrue("Check resource type after update resource", updatedResourceJavaObject.getResourceType().toString().equals(currentResourceType));
2180
2181         }
2182
2183         @Test
2184         public void UpdateResourceTypeCheckInLCS() throws Exception {
2185
2186                 String resourceType = ResourceTypeEnum.VL.toString();
2187                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
2188                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
2189                 Resource currentResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
2190
2191                 resourceDetails.setResourceType(resourceType);
2192                 restResponse = LifecycleRestUtils.changeResourceState(resourceDetails, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
2193                 assertEquals("Check response code after resource CheckIn", 200, restResponse.getErrorCode().intValue());
2194
2195                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, currentResourceJavaObject.getUniqueId(), "");
2196
2197                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_OPERATION.name());
2198
2199                 assertNotNull("check response object is not null after create resouce", updatedRestResponse);
2200                 assertNotNull("check error code exists in response after create resource", updatedRestResponse.getErrorCode());
2201                 assertEquals("Check response code after create resource", errorInfo.getCode(), updatedRestResponse.getErrorCode());
2202
2203                 List<String> variables = new ArrayList<>();
2204                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_OPERATION.name(), variables, updatedRestResponse.getResponse());
2205
2206         }
2207
2208         @Test
2209         public void UpdateResourceTypeCertifiedLCS() throws Exception {
2210
2211                 String resourceType = ResourceTypeEnum.VL.toString();
2212                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
2213                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
2214                 Resource currentResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
2215
2216                 restResponse = LifecycleRestUtils.certifyResource(resourceDetails);
2217                 assertEquals("Check response code after resource CheckIn", 200, restResponse.getErrorCode().intValue());
2218
2219                 resourceDetails.setResourceType(resourceType);
2220                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, currentResourceJavaObject.getUniqueId(), "");
2221
2222                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_OPERATION.name());
2223
2224                 assertNotNull("check response object is not null after create resouce", updatedRestResponse);
2225                 assertNotNull("check error code exists in response after create resource", updatedRestResponse.getErrorCode());
2226                 assertEquals("Check response code after create resource", errorInfo.getCode(), updatedRestResponse.getErrorCode());
2227
2228                 List<String> variables = new ArrayList<>();
2229                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_OPERATION.name(), variables, updatedRestResponse.getResponse());
2230
2231         }
2232
2233         @Test
2234         public void UpdateResourceTypeInvalidType() throws Exception {
2235
2236                 String resourceType = "INVALID TYPE";
2237                 RestResponse restResponse = createResource(sdncModifierDetails, resourceDetails);
2238                 assertEquals("Check response code after create resource", 201, restResponse.getErrorCode().intValue());
2239                 Resource currentResourceJavaObject = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
2240
2241                 resourceDetails.setResourceType(resourceType);
2242                 RestResponse updatedRestResponse = ResourceRestUtils.updateResourceMetadata(resourceDetails, sdncModifierDetails, currentResourceJavaObject.getUniqueId(), "");
2243
2244                 ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_CONTENT.name());
2245
2246                 assertNotNull("check response object is not null after update resouce", updatedRestResponse);
2247                 assertNotNull("check error code exists in response after update resource", updatedRestResponse.getErrorCode());
2248                 assertEquals("Check response code after update resource", errorInfo.getCode(), updatedRestResponse.getErrorCode());
2249
2250                 List<String> variables = new ArrayList<>();
2251                 ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.INVALID_CONTENT.name(), variables, updatedRestResponse.getResponse());
2252
2253         }
2254 }