[SDC] rebase 1710 code
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / api / ComponentInstanceBaseTest.java
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.api;
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.IOException;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.LinkedHashMap;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Map.Entry;
36 import java.util.Set;
37 import java.util.function.Function;
38 import java.util.stream.Collectors;
39
40 import org.apache.commons.lang3.tuple.ImmutablePair;
41 import org.junit.rules.TestName;
42 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
43 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
44 import org.openecomp.sdc.be.model.CapReqDef;
45 import org.openecomp.sdc.be.model.CapabilityDefinition;
46 import org.openecomp.sdc.be.model.Component;
47 import org.openecomp.sdc.be.model.ComponentInstance;
48 import org.openecomp.sdc.be.model.Product;
49 import org.openecomp.sdc.be.model.RequirementAndRelationshipPair;
50 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
51 import org.openecomp.sdc.be.model.RequirementDefinition;
52 import org.openecomp.sdc.be.model.Resource;
53 import org.openecomp.sdc.be.model.Service;
54 import org.openecomp.sdc.be.model.User;
55 import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
56 import org.openecomp.sdc.ci.tests.datatypes.ComponentReqDetails;
57 import org.openecomp.sdc.ci.tests.datatypes.ProductReqDetails;
58 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
59 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
60 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
61 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
62 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
63 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
64 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
65 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
66 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
67 import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
68 import org.openecomp.sdc.ci.tests.utils.rest.ComponentRestUtils;
69 import org.openecomp.sdc.ci.tests.utils.rest.ProductRestUtils;
70 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
71 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
72 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
73 import org.testng.Assert;
74
75 public class ComponentInstanceBaseTest extends ComponentBaseTest {
76         public static final String acceptHeaderData = "application/json";
77         // Req/cap of container component
78         protected Map<String, List<CapabilityDefinition>> expectedContainerCapabilities;
79         protected Map<String, List<RequirementDefinition>> expectedContainerRequirements;
80         protected Map<String, Map<String, List<RequirementDefinition>>> removedRequirements;
81         protected Map<String, ImmutablePair<Map<String, List<CapabilityDefinition>>, Map<String, List<RequirementDefinition>>>> expectedContInstReqCap;
82
83         protected User sdncPsDetails1;
84         protected User sdncPsDetails2;
85         protected User sdncPmDetails1;
86         protected User sdncPmDetails2;
87         protected User sdncDesignerDetails;
88         protected User sdncAdminDetails;
89         protected User sdncTesterDetails;
90         protected ResourceReqDetails resourceDetailsVFC_01;
91         protected ResourceReqDetails resourceDetailsVFC_02;
92         protected ResourceReqDetails resourceDetailsVF_01;
93         protected ResourceReqDetails resourceDetailsVF_02;
94         protected ResourceReqDetails resourceDetailsPNF_01;
95         protected ResourceReqDetails resourceDetailsCP_01;
96         protected ResourceReqDetails resourceDetailsCP_02;
97         protected ResourceReqDetails resourceDetailsVL_01;
98         protected ResourceReqDetails resourceDetailsVL_02;
99         protected ServiceReqDetails serviceDetails_01;
100         protected ServiceReqDetails serviceDetails_02;
101         protected ServiceReqDetails serviceDetails_03;
102         protected ProductReqDetails productDetails_01;
103         protected ProductReqDetails productDetails_02;
104
105         public void init() {
106                 // Req/caps of inner componentInstances
107                 expectedContainerCapabilities = new LinkedHashMap<String, List<CapabilityDefinition>>();
108                 expectedContainerRequirements = new LinkedHashMap<String, List<RequirementDefinition>>();
109                 removedRequirements = new HashMap<>();
110                 expectedContInstReqCap = new HashMap<>();
111
112                 sdncPsDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_STRATEGIST1);
113                 sdncPsDetails2 = ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_STRATEGIST2);
114                 sdncPmDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_MANAGER1);
115                 sdncPmDetails2 = ElementFactory.getDefaultUser(UserRoleEnum.PRODUCT_MANAGER2);
116                 sdncDesignerDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
117                 sdncAdminDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
118                 sdncTesterDetails = ElementFactory.getDefaultUser(UserRoleEnum.TESTER);
119                 resourceDetailsVFC_01 = ElementFactory.getDefaultResourceByType("ciVFC100", NormativeTypesEnum.SOFTWARE_COMPONENT, ResourceCategoryEnum.GENERIC_DATABASE, sdncDesignerDetails.getUserId(), ResourceTypeEnum.VFC.toString()); // resourceType = VFC
120                 resourceDetailsVFC_02 = ElementFactory.getDefaultResourceByType("ciVFC200", NormativeTypesEnum.COMPUTE, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, sdncDesignerDetails.getUserId(), ResourceTypeEnum.VFC.toString());
121                 resourceDetailsVF_01 = ElementFactory.getDefaultResourceByType("ciVF100", NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, sdncDesignerDetails.getUserId(), ResourceTypeEnum.VF.toString());
122                 resourceDetailsVF_02 = ElementFactory.getDefaultResourceByType("ciVF200", NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, sdncDesignerDetails.getUserId(), ResourceTypeEnum.VF.toString());
123                 resourceDetailsPNF_01 = ElementFactory.getDefaultResourceByType("ciPNF100", NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, sdncDesignerDetails.getUserId(), ResourceTypeEnum.PNF.toString());
124                 resourceDetailsCP_01 = ElementFactory.getDefaultResourceByType("ciCP100", NormativeTypesEnum.PORT, ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS, sdncDesignerDetails.getUserId(), ResourceTypeEnum.CP.toString());
125                 resourceDetailsCP_02 = ElementFactory.getDefaultResourceByType("ciCP200", NormativeTypesEnum.PORT, ResourceCategoryEnum.GENERIC_DATABASE, sdncDesignerDetails.getUserId(), ResourceTypeEnum.CP.toString());
126                 resourceDetailsVL_01 = ElementFactory.getDefaultResourceByType("ciVL100", NormativeTypesEnum.NETWORK, ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS, sdncDesignerDetails.getUserId(), ResourceTypeEnum.VL.toString());
127                 resourceDetailsVL_02 = ElementFactory.getDefaultResourceByType("ciVL200", NormativeTypesEnum.NETWORK, ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS, sdncDesignerDetails.getUserId(), ResourceTypeEnum.VL.toString());
128                 serviceDetails_01 = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncDesignerDetails.getUserId());
129                 serviceDetails_02 = ElementFactory.getDefaultService("ciNewtestservice2", ServiceCategoriesEnum.MOBILITY, sdncDesignerDetails.getUserId());
130                 serviceDetails_03 = ElementFactory.getDefaultService("ciNewtestservice3", ServiceCategoriesEnum.MOBILITY, sdncDesignerDetails.getUserId());
131                 productDetails_01 = ElementFactory.getDefaultProduct("ciProduct01");
132                 productDetails_02 = ElementFactory.getDefaultProduct("ciProduct02");
133         }
134
135         public ComponentInstanceBaseTest(TestName testName, String className) {
136                 super(testName, className);
137         }
138
139         public void verifyVFReqCap(String componentId) throws Exception {
140                 RestResponse restResponse = ResourceRestUtils.getResource(componentId);
141                 Resource resource = ResponseParser.parseToObject(restResponse.getResponse(), Resource.class);
142                 verifyReqCap(resource);
143         }
144
145         public void verifyServiceReqCap(String componentId) throws Exception {
146                 RestResponse restResponse = ServiceRestUtils.getService(componentId, sdncDesignerDetails);
147                 Service service = ResponseParser.parseToObject(restResponse.getResponse(), Service.class);
148                 verifyReqCap(service);
149         }
150
151         public void verifyProductReqCap(String componentId) throws Exception {
152                 RestResponse restResponse = ProductRestUtils.getProduct(componentId, sdncPsDetails1.getUserId());
153                 Product product = ResponseParser.parseToObject(restResponse.getResponse(), Product.class);
154                 verifyReqCap(product);
155         }
156
157         public void verifyReqCap(Component actualComponent) {
158                 verifyContainerReqCap(actualComponent);
159                 verifyCompInstReqCap(actualComponent);
160         }
161
162         public RestResponse changeServiceInstanceVersion(String componentUniqueId, String serviceInstanceToReplaceUniqueId, String serviceUniqueId, User sdncModifierDetails, ComponentTypeEnum componentType, boolean isHighestLevel) throws Exception {
163                 RestResponse changeResourceInstanceVersion = ProductRestUtils.changeServiceInstanceVersion(componentUniqueId, serviceInstanceToReplaceUniqueId, serviceUniqueId, sdncModifierDetails, componentType);
164                 if (changeResourceInstanceVersion.getErrorCode().equals(BaseRestUtils.STATUS_CODE_SUCCESS) && isHighestLevel) {
165                         /*
166                          * // Add RI Capabilities and Requirements to expected MAP --> expectedVfCapabilities and expectedVfRequirements
167                          * 
168                          * ComponentInstance componentInstance = ResponseParser.parseToObjectUsingMapper( changeResourceInstanceVersion.getResponse(), ComponentInstance.class); addCompInstReqCapToExpected(componentInstance, componentType);
169                          */
170                 }
171                 return changeResourceInstanceVersion;
172         }
173
174         protected void updateExpectedReqCapAfterChangeLifecycleState(String oldContainerUniqueIdToReplace, String newContainerUniqueId) {
175
176                 // Update of container req/cap
177
178                 Set<String> compInstKeysToChange = new HashSet<>();
179
180                 for (String expKey : expectedContainerCapabilities.keySet()) {
181                         List<CapabilityDefinition> expCapList = expectedContainerCapabilities.get(expKey);
182                         for (CapabilityDefinition cap : expCapList) {
183                                 String ownerId = cap.getOwnerId();
184
185                                 if (ownerId.contains(oldContainerUniqueIdToReplace)) {
186                                         compInstKeysToChange.add(ownerId);
187                                         cap.setOwnerId(cap.getOwnerId().replaceAll(oldContainerUniqueIdToReplace, newContainerUniqueId));
188                                 }
189                         }
190                 }
191
192                 for (String expKey : expectedContainerRequirements.keySet()) {
193                         List<RequirementDefinition> expCapList = expectedContainerRequirements.get(expKey);
194                         for (RequirementDefinition cap : expCapList) {
195                                 String ownerId = cap.getOwnerId();
196                                 if (ownerId.contains(oldContainerUniqueIdToReplace)) {
197                                         compInstKeysToChange.add(ownerId);
198                                         cap.setOwnerId(cap.getOwnerId().replaceAll(oldContainerUniqueIdToReplace, newContainerUniqueId));
199                                 }
200                         }
201                 }
202
203                 // Update of internal comp instances req/cap
204                 for (String oldKey : compInstKeysToChange) {
205                         ImmutablePair<Map<String, List<CapabilityDefinition>>, Map<String, List<RequirementDefinition>>> immutablePair = expectedContInstReqCap.get(oldKey);
206                         if (immutablePair != null) {
207                                 expectedContInstReqCap.remove(oldKey);
208                                 String newKey = oldKey.replaceAll(oldContainerUniqueIdToReplace, newContainerUniqueId);
209                                 expectedContInstReqCap.put(newKey, immutablePair);
210                         }
211                 }
212
213                 // Update of removed req
214                 for (String oldKey : compInstKeysToChange) {
215                         Map<String, List<RequirementDefinition>> map = removedRequirements.get(oldKey);
216                         if (map != null) {
217                                 removedRequirements.remove(oldKey);
218                                 String newKey = oldKey.replaceAll(oldContainerUniqueIdToReplace, newContainerUniqueId);
219                                 Collection<List<RequirementDefinition>> values = map.values();
220                                 if (values != null) {
221                                         for (List<RequirementDefinition> list : values) {
222                                                 for (RequirementDefinition reqDef : list) {
223                                                         reqDef.setOwnerId(reqDef.getOwnerId().replaceAll(oldContainerUniqueIdToReplace, newContainerUniqueId));
224                                                 }
225                                         }
226                                 }
227                                 removedRequirements.put(newKey, map);
228                         }
229                 }
230         }
231
232         private void verifyCompInstReqCap(Component actualComponent) {
233                 List<ComponentInstance> componentInstances = actualComponent.getComponentInstances();
234                 if (componentInstances != null) {
235                         assertEquals(expectedContInstReqCap.size(), componentInstances.size());
236                         for (ComponentInstance compInst : componentInstances) {
237                                 String uniqueId = compInst.getUniqueId();
238                                 // System.out.println("Verifying req/cap of component instance
239                                 // "+ uniqueId);
240                                 Map<String, List<RequirementDefinition>> actualCompInstReq = compInst.getRequirements();
241                                 if (actualCompInstReq == null) {
242                                         actualCompInstReq = new HashMap<>();
243                                 }
244                                 Map<String, List<CapabilityDefinition>> actualCompInstCap = compInst.getCapabilities();
245                                 if (actualCompInstCap == null) {
246                                         actualCompInstCap = new HashMap<>();
247                                 }
248                                 ImmutablePair<Map<String, List<CapabilityDefinition>>, Map<String, List<RequirementDefinition>>> expReqCap = expectedContInstReqCap.get(uniqueId);
249                                 assertNotNull(expReqCap);
250                                 // System.out.println("expected instance requirements:
251                                 // "+expReqCap.right);
252                                 // System.out.println("expected instance capabilities:
253                                 // "+expReqCap.left);
254                                 // System.out.println("actual instance requirements:
255                                 // "+actualCompInstReq);
256                                 // System.out.println("actual instance capabilities:
257                                 // "+actualCompInstCap);
258
259                                 // REQ comparison
260                                 compareReqCapMaps(expReqCap.right, actualCompInstReq);
261
262                                 // CAP comparison
263                                 compareReqCapMaps(expReqCap.left, actualCompInstCap);
264                         }
265
266                 } else {
267                         assertTrue(expectedContInstReqCap.isEmpty());
268                 }
269         }
270
271         private void verifyContainerReqCap(Component actualComponent) {
272                 Map<String, List<RequirementDefinition>> actualContainerRequirements = actualComponent.getRequirements();
273                 if (actualContainerRequirements == null) {
274                         actualContainerRequirements = new HashMap<>();
275                 }
276                 Map<String, List<CapabilityDefinition>> actualContainerCapabilities = actualComponent.getCapabilities();
277                 if (actualContainerCapabilities == null) {
278                         actualContainerCapabilities = new HashMap<>();
279                 }
280                 // System.out.println("Verifying req/cap of container component "+
281                 // actualComponent.getUniqueId());
282                 // System.out.println("expected container requirements:
283                 // "+expectedContainerRequirements);
284                 // System.out.println("expected container capabilities:
285                 // "+expectedContainerCapabilities);
286                 // System.out.println("actual container requirements:
287                 // "+actualContainerRequirements);
288                 // System.out.println("actual container capabilities:
289                 // "+actualContainerCapabilities);
290
291                 // REQ comparison
292                 compareReqCapMaps(expectedContainerRequirements, actualContainerRequirements);
293
294                 // CAP comparison
295                 compareReqCapMaps(expectedContainerCapabilities, actualContainerCapabilities);
296         }
297
298         private <T> void compareReqCapMaps(Map<String, List<T>> expectedMap, Map<String, List<T>> actualMap) {
299                 assertEquals(expectedMap.size(), actualMap.size());
300                 for (String expKey : expectedMap.keySet()) {
301                         List<?> expCapList = expectedMap.get(expKey);
302                         List<?> actCapList = actualMap.get(expKey);
303                         assertEquals(expCapList.size(), actCapList.size());
304                         assertEquals(new HashSet<>(expCapList), new HashSet<>(actCapList));
305                 }
306         }
307
308         public void addCompInstReqCapToExpected(ComponentInstance componentInstance, ComponentTypeEnum containerComponentType) throws Exception {
309                 String uniqueId = componentInstance.getUniqueId();
310                 String name = componentInstance.getName();
311                 String originComponentId = componentInstance.getComponentUid();
312                 RestResponse getResponse = null;
313                 ComponentTypeEnum compInstType = getCompInstTypeByContainerType(containerComponentType);
314                 Component component = null;
315                 if (compInstType == ComponentTypeEnum.RESOURCE) {
316                         getResponse = ResourceRestUtils.getResource(sdncDesignerDetails, originComponentId);
317                         ResourceRestUtils.checkSuccess(getResponse);
318                         component = ResponseParser.parseToObjectUsingMapper(getResponse.getResponse(), Resource.class);
319                 } else if (compInstType == ComponentTypeEnum.SERVICE) {
320                         getResponse = ServiceRestUtils.getService(originComponentId, sdncDesignerDetails);
321                         ResourceRestUtils.checkSuccess(getResponse);
322                         component = ResponseParser.parseToObjectUsingMapper(getResponse.getResponse(), Service.class);
323                 } else {
324                         Assert.fail("Unsupported type - " + containerComponentType);
325                 }
326
327                 Map<String, List<RequirementDefinition>> resourceRequirements = component.getRequirements();
328                 if (resourceRequirements == null) {
329                         resourceRequirements = new HashMap<>();
330                 }
331                 
332                 Function<Entry<String, List<RequirementDefinition>>, List<RequirementDefinition>> requirementDefinitionMapper = e -> new ArrayList<>(e.getValue().stream().map(item -> new RequirementDefinition(item)).collect(Collectors.toList()));
333                 Map<String, List<RequirementDefinition>> reqCopy = resourceRequirements.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), requirementDefinitionMapper));
334                 
335                 Map<String, List<CapabilityDefinition>> resourceCapabilities = component.getCapabilities();
336                 if (resourceCapabilities == null) {
337                         resourceCapabilities = new HashMap<>();
338                 }
339
340                 Function<? super Entry<String, List<CapabilityDefinition>>, List<CapabilityDefinition>> capabilityDefinitionMapper = e -> new ArrayList<>(e.getValue().stream().map(item -> new CapabilityDefinition(item)).collect(Collectors.toList()));
341                 Map<String, List<CapabilityDefinition>> capCopy = resourceCapabilities.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), capabilityDefinitionMapper));
342
343                 setupContainerExpectedReqCap(uniqueId, name, originComponentId, resourceRequirements, resourceCapabilities);
344                 if (component.getComponentType().equals(ComponentTypeEnum.RESOURCE) && ((Resource) component).getResourceType() != ResourceTypeEnum.VF) {
345                         setupConstInstExpectedReqCap(uniqueId, name, originComponentId, reqCopy, capCopy);
346                 }
347
348                 // adding entry for expected componentInstance
349                 ImmutablePair<Map<String, List<CapabilityDefinition>>, Map<String, List<RequirementDefinition>>> compInstReqCapPair = new ImmutablePair<Map<String, List<CapabilityDefinition>>, Map<String, List<RequirementDefinition>>>(capCopy, reqCopy);
350                 expectedContInstReqCap.put(uniqueId, compInstReqCapPair);
351         }
352
353         private void setupContainerExpectedReqCap(String uniqueId, String name, String componentId, Map<String, List<RequirementDefinition>> componentRequirements, Map<String, List<CapabilityDefinition>> componentCapabilities) {
354                 for (Entry<String, List<RequirementDefinition>> resReq : componentRequirements.entrySet()) {
355                         List<RequirementDefinition> reqListToAdd = resReq.getValue();
356                         for (RequirementDefinition requirementDefinition : reqListToAdd) {
357                                 requirementDefinition.setOwnerId(uniqueId);
358                                 requirementDefinition.setOwnerName(name);
359                                 requirementDefinition.addToPath(uniqueId);
360                                 requirementDefinition.setSource(componentId);
361                                 requirementDefinition.setLeftOccurrences(requirementDefinition.getMaxOccurrences());
362                         }
363                         List<RequirementDefinition> expectedReqList = expectedContainerRequirements.get(resReq.getKey());
364                         if (expectedReqList == null) {
365                                 expectedReqList = reqListToAdd;
366                         } else {
367                                 expectedReqList.addAll(reqListToAdd);
368                         }
369                         expectedContainerRequirements.put(resReq.getKey(), expectedReqList);
370                 }
371
372                 for (Entry<String, List<CapabilityDefinition>> resCap : componentCapabilities.entrySet()) {
373                         List<CapabilityDefinition> capListToAdd = resCap.getValue();
374                         for (CapabilityDefinition capDefinition : capListToAdd) {
375                                 capDefinition.setOwnerId(uniqueId);
376                                 capDefinition.setOwnerName(name);
377                                 capDefinition.addToPath(uniqueId);
378                                 capDefinition.setSource(componentId);
379                                 capDefinition.setLeftOccurrences(capDefinition.getMaxOccurrences());
380                         }
381                         List<CapabilityDefinition> expectedCapList = expectedContainerCapabilities.get(resCap.getKey());
382                         if (expectedCapList == null) {
383                                 expectedCapList = capListToAdd;
384                         } else {
385                                 expectedCapList.addAll(capListToAdd);
386                         }
387                         expectedContainerCapabilities.put(resCap.getKey(), expectedCapList);
388                 }
389         }
390
391         private void setupConstInstExpectedReqCap(String uniqueId, String name, String componentId, Map<String, List<RequirementDefinition>> componentRequirements, Map<String, List<CapabilityDefinition>> componentCapabilities) {
392                 for (Entry<String, List<RequirementDefinition>> resReq : componentRequirements.entrySet()) {
393                         List<RequirementDefinition> reqListToAdd = resReq.getValue();
394                         for (RequirementDefinition requirementDefinition : reqListToAdd) {
395                                 requirementDefinition.setOwnerId(uniqueId);
396                                 requirementDefinition.setOwnerName(name);
397                                 requirementDefinition.addToPath(uniqueId);
398                                 requirementDefinition.setSource(componentId);
399                                 requirementDefinition.setLeftOccurrences(requirementDefinition.getMaxOccurrences());
400                         }
401                 }
402
403                 for (Entry<String, List<CapabilityDefinition>> resCap : componentCapabilities.entrySet()) {
404                         List<CapabilityDefinition> capListToAdd = resCap.getValue();
405                         for (CapabilityDefinition capDefinition : capListToAdd) {
406                                 capDefinition.setOwnerId(uniqueId);
407                                 capDefinition.setOwnerName(name);
408                                 capDefinition.addToPath(uniqueId);
409                                 capDefinition.setSource(componentId);
410                         }
411                 }
412         }
413
414         private ComponentTypeEnum getCompInstTypeByContainerType(ComponentTypeEnum componentType) {
415                 switch (componentType) {
416                 case RESOURCE:
417                         return ComponentTypeEnum.RESOURCE;
418                 case SERVICE:
419                         return ComponentTypeEnum.RESOURCE;
420                 case PRODUCT:
421                         return ComponentTypeEnum.SERVICE;
422                 default:
423                         break;
424                 }
425                 return null;
426         }
427
428         public void deleteCompInstReqCapFromExpected(String componentInstanceId) {
429                 List<String> entriesRequirementsToRemove = new ArrayList<>();
430                 List<String> entriesCapabilitiesToRemove = new ArrayList<>();
431                 for (Entry<String, List<RequirementDefinition>> reqEntry : expectedContainerRequirements.entrySet()) {
432                         List<RequirementDefinition> reqList = reqEntry.getValue();
433                         List<RequirementDefinition> reqListToDelete = new ArrayList<>();
434                         for (RequirementDefinition requirementDefinition : reqList) {
435                                 if (requirementDefinition.getOwnerId().equals(componentInstanceId)) {
436                                         reqListToDelete.add(requirementDefinition);
437                                 }
438                         }
439                         reqList.removeAll(reqListToDelete);
440                         if (reqList.isEmpty()) {
441                                 entriesRequirementsToRemove.add(reqEntry.getKey());
442                         }
443                 }
444
445                 for (String ekey : entriesRequirementsToRemove) {
446                         expectedContainerRequirements.remove(ekey);
447                 }
448
449                 for (Entry<String, List<CapabilityDefinition>> capEntry : expectedContainerCapabilities.entrySet()) {
450                         List<CapabilityDefinition> capList = capEntry.getValue();
451                         List<CapabilityDefinition> capListToDelete = new ArrayList<>();
452                         for (CapabilityDefinition capabilityDefinition : capList) {
453                                 if (capabilityDefinition.getOwnerId().equals(componentInstanceId)) {
454                                         capListToDelete.add(capabilityDefinition);
455                                 }
456                         }
457                         capList.removeAll(capListToDelete);
458                         if (capList.isEmpty()) {
459                                 entriesCapabilitiesToRemove.add(capEntry.getKey());
460                         }
461                 }
462                 for (String ekey : entriesCapabilitiesToRemove) {
463                         expectedContainerCapabilities.remove(ekey);
464                 }
465
466                 expectedContInstReqCap.remove(componentInstanceId);
467
468         }
469
470         // Automatically updates the expected req/cap of the container
471         protected RestResponse createAtomicInstanceForVF(ResourceReqDetails containerDetails, ResourceReqDetails compInstOriginDetails, User modifier) throws Exception {
472                 return createComponentInstance(containerDetails, compInstOriginDetails, modifier, ComponentTypeEnum.RESOURCE, true);
473         }
474
475         // Automatically updates the expected req/cap of the container
476         protected RestResponse createAtomicInstanceForService(ServiceReqDetails containerDetails, ResourceReqDetails compInstOriginDetails, User modifier) throws Exception {
477                 return createComponentInstance(containerDetails, compInstOriginDetails, modifier, ComponentTypeEnum.SERVICE, true);
478         }
479
480         // Automatically updates the expected req/cap of the container
481         protected RestResponse createVFInstance(ServiceReqDetails containerDetails, ResourceReqDetails compInstOriginDetails, User modifier) throws Exception {
482                 return createComponentInstance(containerDetails, compInstOriginDetails, modifier, ComponentTypeEnum.SERVICE, true);
483         }
484
485         // Automatically updates the expected req/cap of the container
486         protected RestResponse createServiceInstance(ProductReqDetails containerDetails, ServiceReqDetails compInstOriginDetails, User modifier) throws Exception {
487                 return createComponentInstance(containerDetails, compInstOriginDetails, modifier, ComponentTypeEnum.PRODUCT, true);
488         }
489
490         // Automatically updates the expected req/cap of the container
491         protected RestResponse deleteAtomicInstanceForVF(String compInstUniqueId, ResourceReqDetails containerDetails, User modifier) throws IOException, Exception {
492                 return deleteComponentInstance(compInstUniqueId, containerDetails, modifier, ComponentTypeEnum.RESOURCE, true);
493         }
494
495         // Automatically updates the expected req/cap of the container
496         protected RestResponse deleteAtomicInstanceForService(String compInstUniqueId, ServiceReqDetails containerDetails, User modifier) throws IOException, Exception {
497                 return deleteComponentInstance(compInstUniqueId, containerDetails, modifier, ComponentTypeEnum.SERVICE, true);
498         }
499
500         // Automatically updates the expected req/cap of the container
501         protected RestResponse deleteVFInstance(String compInstUniqueId, ServiceReqDetails containerDetails, User modifier) throws IOException, Exception {
502                 return deleteComponentInstance(compInstUniqueId, containerDetails, modifier, ComponentTypeEnum.SERVICE, true);
503
504         }
505
506         // Automatically updates the expected req/cap of the container
507         protected RestResponse deleteServiceInstance(String compInstUniqueId, ProductReqDetails containerDetails, User modifier) throws IOException, Exception {
508                 return deleteComponentInstance(compInstUniqueId, containerDetails, modifier, ComponentTypeEnum.PRODUCT, true);
509         }
510
511         // Setup of lower components - Doesn't affect req/cap of the container (for
512         // example, setup of VF for testing a Product)
513         protected RestResponse createAtomicInstanceForVFDuringSetup(ResourceReqDetails containerDetails, ResourceReqDetails compInstOriginDetails, User modifier) throws Exception {
514                 return createComponentInstance(containerDetails, compInstOriginDetails, modifier, ComponentTypeEnum.RESOURCE, false);
515         }
516
517         // Setup of lower components - Doesn't affect req/cap of the container (for
518         // example, setup of VF for testing a Product)
519         protected RestResponse createAtomicInstanceForServiceDuringSetup(ServiceReqDetails containerDetails, ResourceReqDetails compInstOriginDetails, User modifier) throws Exception {
520                 return createComponentInstance(containerDetails, compInstOriginDetails, modifier, ComponentTypeEnum.SERVICE, false);
521         }
522
523         // Setup of lower components - Doesn't affect req/cap of the container (for
524         // example, setup of VF for testing a Product)
525         protected RestResponse createVFInstanceDuringSetup(ServiceReqDetails containerDetails, ResourceReqDetails compInstOriginDetails, User modifier) throws Exception {
526                 return createComponentInstance(containerDetails, compInstOriginDetails, modifier, ComponentTypeEnum.SERVICE, false);
527         }
528
529         // Setup of lower components - Doesn't affect req/cap of the container (for
530         // example, setup of VF for testing a Product)
531         protected RestResponse createServiceInstanceDuringSetup(ProductReqDetails containerDetails, ServiceReqDetails compInstOriginDetails, User modifier) throws Exception {
532                 return createComponentInstance(containerDetails, compInstOriginDetails, modifier, ComponentTypeEnum.PRODUCT, false);
533         }
534
535         // Setup of lower components - Doesn't affect req/cap of the container (for
536         // example, setup of VF for testing a Product)
537         protected RestResponse deleteAtomicInstanceForVFDuringSetup(String compInstUniqueId, ResourceReqDetails containerDetails, User modifier) throws IOException, Exception {
538                 return deleteComponentInstance(compInstUniqueId, containerDetails, modifier, ComponentTypeEnum.RESOURCE, false);
539         }
540
541         // Setup of lower components - Doesn't affect req/cap of the container (for
542         // example, setup of VF for testing a Product)
543         protected RestResponse deleteAtomicInstanceForServiceDuringSetup(String compInstUniqueId, ServiceReqDetails containerDetails, User modifier) throws IOException, Exception {
544                 return deleteComponentInstance(compInstUniqueId, containerDetails, modifier, ComponentTypeEnum.SERVICE, false);
545         }
546
547         // Setup of lower components - Doesn't affect req/cap of the container (for
548         // example, setup of VF for testing a Product)
549         protected RestResponse deleteVFInstanceDuringSetup(String compInstUniqueId, ServiceReqDetails containerDetails, User modifier) throws IOException, Exception {
550                 return deleteComponentInstance(compInstUniqueId, containerDetails, modifier, ComponentTypeEnum.SERVICE, false);
551
552         }
553
554         // Setup of lower components - Doesn't affect req/cap of the container (for
555         // example, setup of VF for testing a Product)
556         protected RestResponse deleteServiceInstanceDuringSetup(String compInstUniqueId, ProductReqDetails containerDetails, User modifier) throws IOException, Exception {
557                 return deleteComponentInstance(compInstUniqueId, containerDetails, modifier, ComponentTypeEnum.PRODUCT, false);
558         }
559
560         protected Component getComponentAndValidateRIs(ComponentReqDetails componentDetails, int numberOfRIs, int numberOfRelations) throws IOException, Exception {
561
562                 RestResponse getResponse = null;
563                 Component component = null;
564                 if (componentDetails instanceof ResourceReqDetails) {
565                         getResponse = ResourceRestUtils.getResource(sdncAdminDetails, componentDetails.getUniqueId());
566                         component = ResponseParser.parseToObjectUsingMapper(getResponse.getResponse(), Resource.class);
567                 } else if (componentDetails instanceof ServiceReqDetails) {
568                         getResponse = ServiceRestUtils.getService((ServiceReqDetails) componentDetails, sdncAdminDetails);
569                         component = ResponseParser.parseToObjectUsingMapper(getResponse.getResponse(), Service.class);
570                 } else if (componentDetails instanceof ProductReqDetails) {
571                         getResponse = ProductRestUtils.getProduct(componentDetails.getUniqueId(), sdncAdminDetails.getUserId());
572                         component = ResponseParser.parseToObjectUsingMapper(getResponse.getResponse(), Product.class);
573                 } else {
574                         Assert.fail("Unsupported type of componentDetails - " + componentDetails.getClass().getSimpleName());
575                 }
576                 ResourceRestUtils.checkSuccess(getResponse);
577                 int numberOfActualRIs = component.getComponentInstances() != null ? component.getComponentInstances().size() : 0;
578                 int numberOfActualRelations = component.getComponentInstancesRelations() != null ? component.getComponentInstancesRelations().size() : 0;
579                 assertEquals("Check number of RIs meet the expected number", numberOfRIs, numberOfActualRIs);
580                 assertEquals("Check number of RI relations meet the expected number", numberOfRelations, numberOfActualRelations);
581                 verifyReqCap(component);
582
583                 return component;
584         }
585
586         protected Component getComponentAndValidateRIsOnly(ComponentReqDetails componentDetails, int numberOfRIs, int numberOfRelations) throws IOException, Exception {
587
588                 RestResponse getResponse = null;
589                 Component component = null;
590                 if (componentDetails instanceof ResourceReqDetails) {
591                         getResponse = ResourceRestUtils.getResource(sdncAdminDetails, componentDetails.getUniqueId());
592                         component = ResponseParser.parseToObjectUsingMapper(getResponse.getResponse(), Resource.class);
593                 } else if (componentDetails instanceof ServiceReqDetails) {
594                         getResponse = ServiceRestUtils.getService((ServiceReqDetails) componentDetails, sdncAdminDetails);
595                         component = ResponseParser.parseToObjectUsingMapper(getResponse.getResponse(), Service.class);
596                 } else if (componentDetails instanceof ProductReqDetails) {
597                         getResponse = ProductRestUtils.getProduct(componentDetails.getUniqueId(), sdncAdminDetails.getUserId());
598                         component = ResponseParser.parseToObjectUsingMapper(getResponse.getResponse(), Product.class);
599                 } else {
600                         Assert.fail("Unsupported type of componentDetails - " + componentDetails.getClass().getSimpleName());
601                 }
602                 ResourceRestUtils.checkSuccess(getResponse);
603                 int numberOfActualRIs = component.getComponentInstances() != null ? component.getComponentInstances().size() : 0;
604                 int numberOfActualRelations = component.getComponentInstancesRelations() != null ? component.getComponentInstancesRelations().size() : 0;
605                 assertEquals("Check number of RIs meet the expected number", numberOfRIs, numberOfActualRIs);
606                 assertEquals("Check number of RI relations meet the expected number", numberOfRelations, numberOfActualRelations);
607
608                 return component;
609         }
610
611         protected void getComponentAndValidateRIsAfterChangeLifecycleState(String oldComponentUniqueIdToReplace, ComponentReqDetails componentDetails, int numOfRIs, int numOfRelations) throws IOException, Exception {
612                 updateExpectedReqCapAfterChangeLifecycleState(oldComponentUniqueIdToReplace, componentDetails.getUniqueId());
613                 getComponentAndValidateRIs(componentDetails, numOfRIs, numOfRelations);
614         }
615
616         private RestResponse createComponentInstance(ComponentReqDetails containerDetails, ComponentReqDetails compInstOriginDetails, User modifier, ComponentTypeEnum containerComponentTypeEnum, boolean isHighestLevel) throws IOException, Exception {
617                 ComponentInstanceReqDetails resourceInstanceReqDetails = ElementFactory.getComponentResourceInstance(compInstOriginDetails);
618                 RestResponse createResourceInstanceResponse = ComponentInstanceRestUtils.createComponentInstance(resourceInstanceReqDetails, modifier, containerDetails.getUniqueId(), containerComponentTypeEnum);
619                 if (createResourceInstanceResponse.getErrorCode().equals(BaseRestUtils.STATUS_CODE_CREATED) && isHighestLevel) {
620                         // Add RI Capabilities and Requirements to expected MAP -->
621                         // expectedVfCapabilities and expectedVfRequirements
622                         ComponentInstance componentInstance = ResponseParser.parseToObjectUsingMapper(createResourceInstanceResponse.getResponse(), ComponentInstance.class);
623                         addCompInstReqCapToExpected(componentInstance, containerComponentTypeEnum);
624                 }
625                 return createResourceInstanceResponse;
626         }
627
628         private RestResponse deleteComponentInstance(String compInstUniqueId, ComponentReqDetails containerDetails, User modifier, ComponentTypeEnum componentTypeEnum, boolean isHighestLevel) throws Exception {
629                 RestResponse deleteResourceInstanceResponse = ComponentInstanceRestUtils.deleteComponentInstance(modifier, containerDetails.getUniqueId(), compInstUniqueId, componentTypeEnum);
630                 if (deleteResourceInstanceResponse.getErrorCode().equals(BaseRestUtils.STATUS_CODE_DELETE) && isHighestLevel) {
631                         deleteCompInstReqCapFromExpected(compInstUniqueId);
632                 }
633                 return deleteResourceInstanceResponse;
634         }
635
636         // Create Atomic resource ( VFC/CP/VL)
637         protected void createAtomicResource(ResourceReqDetails resourceDetails) throws Exception {
638                 RestResponse createResourceResponse = ResourceRestUtils.createResource(resourceDetails, sdncDesignerDetails);
639                 ResourceRestUtils.checkCreateResponse(createResourceResponse);
640
641         }
642
643         protected void createVF(ResourceReqDetails resourceDetails) throws Exception {
644                 createVF(resourceDetails, sdncDesignerDetails);
645
646         }
647
648         protected void createVF(ResourceReqDetails resourceDetails, User sdncModifier) throws Exception {
649                 RestResponse createVfResponse = ResourceRestUtils.createResource(resourceDetails, sdncModifier);
650                 ResourceRestUtils.checkCreateResponse(createVfResponse);
651         }
652
653         protected void createPNF(ResourceReqDetails resourceDetails) throws Exception {
654                 createVF(resourceDetails, sdncDesignerDetails);
655         }
656
657         protected void createService(ServiceReqDetails serviceDetails) throws Exception {
658                 createService(serviceDetails, sdncDesignerDetails);
659         }
660
661         protected void createService(ServiceReqDetails serviceDetails, User sdncModifier) throws Exception {
662                 RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifier);
663                 ResourceRestUtils.checkCreateResponse(createServiceResponse);
664         }
665
666         protected void createProduct(ProductReqDetails productDetails) throws Exception {
667                 createProduct(productDetails, sdncPmDetails1);
668         }
669
670         protected void createProduct(ProductReqDetails productDetails, User sdncModifier) throws Exception {
671                 RestResponse createProductResponse = ProductRestUtils.createProduct(productDetails, sdncModifier);
672                 ResourceRestUtils.checkCreateResponse(createProductResponse);
673         }
674
675         protected RestResponse associateComponentInstancesForService(RequirementCapabilityRelDef requirementDef, ComponentReqDetails containerDetails, User user) throws IOException {
676
677                 RestResponse associateInstances = ComponentInstanceRestUtils.associateInstances(requirementDef, user, containerDetails.getUniqueId(), ComponentTypeEnum.SERVICE);
678                 ResourceRestUtils.checkSuccess(associateInstances);
679                 deleteAssociatedFromExpected(requirementDef);
680
681                 return associateInstances;
682         }
683
684         private void deleteAssociatedFromExpected(RequirementCapabilityRelDef requirementDef) {
685                 // removing from requirements
686                 RequirementAndRelationshipPair relationship = requirementDef.getRelationships().get(0);
687                 String type = relationship.getRelationship().getType();
688                 String fromId = requirementDef.getFromNode();
689                 List<RequirementDefinition> reqList = expectedContainerRequirements.get(type);
690                 List<CapabilityDefinition> capList = expectedContainerCapabilities.get(type);
691                 RequirementDefinition toDelete = null;
692                 if (reqList != null) {
693                         for (RequirementDefinition reqDef : reqList) {
694                                 if (reqDef.getOwnerId().equals(fromId)) {
695                                         toDelete = reqDef;
696                                 }
697                         }
698                         if (toDelete != null) {
699                                 reqList.remove(toDelete);
700                                 if (reqList.isEmpty()) {
701                                         expectedContainerRequirements.remove(type);
702                                 }
703                                 String ownerId = toDelete.getOwnerId();
704                                 Map<String, List<RequirementDefinition>> map = removedRequirements.get(ownerId);
705                                 if (map == null) {
706                                         map = new HashMap<>();
707                                         removedRequirements.put(ownerId, map);
708                                 }
709                                 List<RequirementDefinition> list = map.get(type);
710                                 if (list == null) {
711                                         list = new ArrayList<>();
712                                         map.put(type, list);
713                                 }
714                                 list.add(toDelete);
715                         }
716                 }
717
718                 for (CapabilityDefinition capabilityDefinition : capList) {
719                         if (capabilityDefinition.getType().equals(type)) {
720                                 int minOccurrences = Integer.parseInt(capabilityDefinition.getMinOccurrences()) - 1;
721                                 if (minOccurrences < 0)
722                                         minOccurrences = 0;
723                                 String minOccurrencesString = Integer.toString(minOccurrences);
724                                 capabilityDefinition.setMinOccurrences(minOccurrencesString);
725                                 if (!capabilityDefinition.getMaxOccurrences().equals("UNBOUNDED")) {
726                                         int maxOccurrences = Integer.parseInt(capabilityDefinition.getMaxOccurrences()) - 1;
727                                         if (maxOccurrences < 0)
728                                                 maxOccurrences = 0;
729                                         String maxOccurrencesString = Integer.toString(maxOccurrences);
730                                         capabilityDefinition.setMaxOccurrences(maxOccurrencesString);
731                                 }
732                         }
733                 }
734                 expectedContainerCapabilities.put(type, capList);
735         }
736
737         protected void dissociateComponentInstancesForService(RequirementCapabilityRelDef requirementDef, ComponentReqDetails containerDetails, User user) throws IOException {
738
739                 RestResponse dissociateInstances = ComponentInstanceRestUtils.dissociateInstances(requirementDef, user, containerDetails.getUniqueId(), ComponentTypeEnum.SERVICE);
740                 ResourceRestUtils.checkSuccess(dissociateInstances);
741                 addDissociatedToExpected(requirementDef);
742         }
743
744         protected void fulfillCpRequirement(ComponentReqDetails component, String cpCompInstId, String cpReqFulfillerCompInstId, String cpReqFulfillerOwnerId, User user, ComponentTypeEnum containerCompType) throws IOException {
745                 // Fulfilling cp's "binding" requirement - US626240
746                 String requirementName = "binding";
747                 String capType = "tosca.capabilities.network.Bindable";
748                 RestResponse getResourceResponse = ComponentRestUtils.getComponentRequirmentsCapabilities(user, component);
749                 ResourceRestUtils.checkSuccess(getResourceResponse);
750                 CapReqDef capReqDef = ResponseParser.parseToObject(getResourceResponse.getResponse(), CapReqDef.class);
751                 List<CapabilityDefinition> capList = capReqDef.getCapabilities().get(capType);
752                 List<RequirementDefinition> reqList = capReqDef.getRequirements().get(capType);
753                 RequirementCapabilityRelDef reqCapRelation = ElementFactory.getReqCapRelation(cpCompInstId, cpReqFulfillerCompInstId, cpCompInstId, cpReqFulfillerOwnerId, capType, requirementName, capList, reqList);
754                 RestResponse associateInstances = ComponentInstanceRestUtils.associateInstances(reqCapRelation, user, component.getUniqueId(), containerCompType);
755                 ResourceRestUtils.checkSuccess(associateInstances);
756         }
757
758         protected void consumeVlCapability(ComponentReqDetails component, String vlCapConsumerCompInstId, String vlCompInstId, String vlCapConsumerOwnerId, User user, ComponentTypeEnum containerCompType) throws IOException {
759                 // Consuming vl's "link" capability - US626240
760                 String requirementName = "link";
761                 String capType = "tosca.capabilities.network.Linkable";
762                 RestResponse getResourceResponse = ComponentRestUtils.getComponentRequirmentsCapabilities(user, component);
763                 ResourceRestUtils.checkSuccess(getResourceResponse);
764                 CapReqDef capReqDef = ResponseParser.parseToObject(getResourceResponse.getResponse(), CapReqDef.class);
765                 List<CapabilityDefinition> capList = capReqDef.getCapabilities().get(capType);
766                 List<RequirementDefinition> reqList = capReqDef.getRequirements().get(capType);
767                 RequirementCapabilityRelDef reqCapRelation = ElementFactory.getReqCapRelation(vlCapConsumerCompInstId, vlCompInstId, vlCapConsumerOwnerId, vlCompInstId, capType, requirementName, capList, reqList);
768                 RestResponse associateInstances = ComponentInstanceRestUtils.associateInstances(reqCapRelation, user, component.getUniqueId(), containerCompType);
769                 ResourceRestUtils.checkSuccess(associateInstances);
770         }
771
772         private void addDissociatedToExpected(RequirementCapabilityRelDef requirementDef) {
773                 // adding to requirements
774                 RequirementAndRelationshipPair relationship = requirementDef.getRelationships().get(0);
775                 String type = relationship.getRelationship().getType();
776                 String fromId = requirementDef.getFromNode();
777                 Map<String, List<RequirementDefinition>> map = removedRequirements.get(fromId);
778                 if (map != null) {
779                         List<RequirementDefinition> list = map.get(type);
780                         if (list != null && !list.isEmpty()) {
781                                 List<RequirementDefinition> reqList = expectedContainerRequirements.get(type);
782                                 if (reqList == null) {
783                                         reqList = new ArrayList<>();
784                                         expectedContainerRequirements.put(type, reqList);
785                                 }
786                                 reqList.add(list.remove(0));
787                         }
788                 }
789
790                 List<CapabilityDefinition> capList = expectedContainerCapabilities.get(type);
791
792                 for (CapabilityDefinition capabilityDefinition : capList) {
793                         if (capabilityDefinition.getType().equals(type)) {
794                                 int minOccurrences = Integer.parseInt(capabilityDefinition.getMinOccurrences()) + 1;
795                                 String minOccurrencesString = Integer.toString(minOccurrences);
796                                 capabilityDefinition.setMinOccurrences(minOccurrencesString);
797                                 if (!capabilityDefinition.getMaxOccurrences().equals("UNBOUNDED")) {
798                                         int maxOccurrences = Integer.parseInt(capabilityDefinition.getMaxOccurrences()) + 1;
799                                         String maxOccurrencesString = Integer.toString(maxOccurrences);
800                                         capabilityDefinition.setMaxOccurrences(maxOccurrencesString);
801                                 }
802                         }
803                 }
804                 expectedContainerCapabilities.put(type, capList);
805         }
806 }