Sync Integ to Master
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / api / ComponentBaseTest.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
26 import java.io.File;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.Collection;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.function.Consumer;
35 import java.util.stream.Collectors;
36
37 import org.apache.commons.collections.CollectionUtils;
38 import org.apache.commons.lang3.tuple.ImmutablePair;
39 import org.apache.commons.lang3.tuple.ImmutableTriple;
40 import org.apache.log4j.Logger;
41 import org.apache.tinkerpop.gremlin.structure.Direction;
42 import org.apache.tinkerpop.gremlin.structure.Vertex;
43 import org.junit.rules.TestName;
44 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
45 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
46 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
47 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
48 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
49 import org.openecomp.sdc.be.model.Component;
50 import org.openecomp.sdc.be.model.Product;
51 import org.openecomp.sdc.be.model.Resource;
52 import org.openecomp.sdc.be.model.Service;
53 import org.openecomp.sdc.be.model.User;
54 import org.openecomp.sdc.ci.tests.config.Config;
55 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
56 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
57 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
58 import org.openecomp.sdc.ci.tests.utils.Utils;
59 import org.openecomp.sdc.ci.tests.utils.cassandra.CassandraUtils;
60 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
61 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
62 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
63 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
64 import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils;
65 import org.openecomp.sdc.ci.tests.utils.rest.CategoryRestUtils;
66 import org.openecomp.sdc.ci.tests.utils.rest.ProductRestUtils;
67 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
68 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
69 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
70 import org.slf4j.LoggerFactory;
71 import org.testng.ITestContext;
72 import org.testng.ITestResult;
73 import org.testng.annotations.*;
74
75 import com.aventstack.extentreports.ExtentTest;
76 import com.aventstack.extentreports.Status;
77 import com.thinkaurelius.titan.core.TitanFactory;
78 import com.thinkaurelius.titan.core.TitanGraph;
79 import com.thinkaurelius.titan.core.TitanVertex;
80
81 import ch.qos.logback.classic.Level;
82 import ch.qos.logback.classic.LoggerContext;
83
84 public abstract class ComponentBaseTest {
85
86 //      private static Logger logger = LoggerFactory.getLogger(ComponentBaseTest.class.getName());
87         
88         protected static Logger logger= Logger.getLogger(ComponentBaseTest.class);      
89         
90
91 //       public ComponentBaseTest(TestName testName, String className) {
92 //       super(testName, className);
93 //       }
94
95         protected static final String REPORT_FOLDER = "." + File.separator + "ExtentReport" + File.separator;
96         private static final String VERSIONS_INFO_FILE_NAME = "versions.info";
97         private static final String REPORT_FILE_NAME = "SDC_CI_Extent_Report.html";
98         protected static TitanGraph titanGraph;
99         public static Config config;
100         protected static ITestContext myContext;
101         
102         
103         
104         /**************** METHODS ****************/
105         public static ExtentTest getExtendTest() {
106                 SomeInterface testManager = new ExtentTestManager(); 
107                 return testManager.getTest();
108         }
109
110         public static enum ComponentOperationEnum {
111                 CREATE_COMPONENT, UPDATE_COMPONENT, GET_COMPONENT, DELETE_COMPONENT, CHANGE_STATE_CHECKIN, CHANGE_STATE_CHECKOUT, CHANGE_STATE_UNDO_CHECKOUT
112         };
113
114         public ComponentBaseTest(TestName name, String name2) {
115                 LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
116                 lc.getLogger("com.thinkaurelius").setLevel(Level.INFO);
117                 lc.getLogger("com.datastax").setLevel(Level.INFO);
118                 lc.getLogger("io.netty").setLevel(Level.INFO);
119                 lc.getLogger("c.d").setLevel(Level.INFO);
120         }
121         
122         public static String getReportFolder() {
123                 return REPORT_FOLDER;
124         }
125
126         @BeforeSuite(alwaysRun = true)
127         public void setupBeforeSuite(ITestContext context) throws Exception {
128                 config = Utils.getConfig();
129                 myContext=context;
130                 ExtentManager.initReporter(getReportFolder(), REPORT_FILE_NAME, context);       
131                 AtomicOperationUtils.createDefaultConsumer(true);
132 //              openTitanLogic();
133                 performClean();
134                 
135                 
136
137         }
138         
139         @BeforeMethod(alwaysRun = true)
140         public void setupBeforeTest(java.lang.reflect.Method method, ITestContext context) throws Exception {
141                 
142                 System.out.println(" method.getName() " + method.getName());
143                 if (!method.getName().equals("onboardVNFShotFlow"))  {
144 //                      System.out.println("ExtentReport instance started from BeforeMethod...");
145                         logger.info("ExtentReport instance started from BeforeMethod...");
146                         ExtentTestManager.startTest(method.getName());
147                         ExtentTestManager.assignCategory(this.getClass());
148
149                 } else {
150 //                      System.out.println("ExtentReport instance started from Test...");
151                         logger.debug("ExtentReport instance started from Test...");
152                 }
153       
154         }
155         
156         @AfterMethod(alwaysRun = true)
157         public void quitAfterTest(ITestResult result, ITestContext context) throws Exception {
158
159                 String testName = result.getName();
160                 Throwable throwable = result.getThrowable();
161                 int status = result.getStatus();
162                 
163                 switch(status){
164                 case ITestResult.SUCCESS:                               
165                         getExtendTest().log(Status.PASS, "Test Result : <span class='label success'>Success</span>");
166                         break;
167                                 
168                 case ITestResult.FAILURE:
169                         getExtendTest().log(Status.ERROR, "ERROR - The following exepction occured");
170                         getExtendTest().log(Status.ERROR, result.getThrowable());
171                         getExtendTest().log(Status.FAIL, "<span class='label failure'>Failure</span>");
172                         break;
173                         
174                 case ITestResult.SKIP:
175                         getExtendTest().log(Status.SKIP, "SKIP - The following exepction occured");
176                         break;
177                 default:
178                         break;
179                 }
180
181
182                 ExtentTestManager.endTest();
183         
184                 
185         }
186
187 /*      @AfterClass(alwaysRun = true)
188         public synchronized static void cleanAfterClass() throws Exception{
189
190 //              System.out.println("<<<<<<<<class name>>>>>"+method.getDeclaringClass());
191 //              System.out.println("<<<<<<<<class name>>>>>"+method.getName());
192
193
194                 System.out.println("delete components AfterClass");
195                 if(!config.getSystemUnderDebug()){
196                         deleteCreatedComponents(getCatalogAsMap());
197 //                      CassandraUtils.truncateAllKeyspaces();
198                 }else{
199                         System.out.println("Accordindig to configuration components will not be deleted, in case to unable option to delete, please change systemUnderDebug parameter value to false ...");
200                 }
201 //              extentReport.flush();
202
203         }*/
204         
205         @AfterSuite(alwaysRun = true)
206         public static void shutdownTitan() throws Exception {
207                 
208                 performClean();
209 //              shutdownTitanLogic();
210
211         }
212         protected static void openTitanLogic() throws Exception {
213         
214                 logger.trace(config.toString());
215                 String titanConfigFilePath = config.getTitanPropertiesFile();
216                 titanGraph = TitanFactory.open(titanConfigFilePath);
217                 assertNotNull(titanGraph);
218                 
219         }
220
221
222         protected static void shutdownTitanLogic() {
223                 if (titanGraph.isOpen()) {
224                         titanGraph.close();
225                 }
226                 CassandraUtils.close();
227         }
228
229         
230
231         public void setLog(String fromDataProvider) {
232
233                 String suiteName = ExtentManager.getSuiteName(myContext);
234                 ExtentTestManager.startTest(Thread.currentThread().getStackTrace()[2].getMethodName() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + fromDataProvider);
235                 ExtentTestManager.assignCategory(this.getClass());
236
237         }
238
239         protected static void performClean() throws Exception, FileNotFoundException {
240 //              cleanComponents();
241                 if(!config.getSystemUnderDebug()){
242                         deleteCreatedComponents(getCatalogAsMap());
243 //                      CassandraUtils.truncateAllKeyspaces();
244                         FileHandling.overWriteExistindDir("outputCsar");
245                 }else{
246                         System.out.println("Accordindig to configuration components will not be deleted, in case to unable option to delete, please change systemUnderDebug parameter value to false ...");
247                 }
248         }
249
250         public void verifyErrorCode(RestResponse response, String action, int expectedCode) {
251                 assertNotNull("check response object is not null after " + action, response);
252                 assertNotNull("check error code exists in response after " + action, response.getErrorCode());
253                 assertEquals("Check response code after  + action" + action, expectedCode, response.getErrorCode().intValue());
254         }
255
256         private static void cleanComponents() throws Exception {
257
258                 // Components to delete
259                 List<String> vfResourcesToDelete = new ArrayList<String>();
260                 List<String> nonVfResourcesToDelete = new ArrayList<String>();
261                 List<String> servicesToDelete = new ArrayList<String>();
262                 List<String> productsToDelete = new ArrayList<String>();
263
264                 // Categories to delete
265                 List<ImmutableTriple<String, String, String>> productGroupingsToDelete = new ArrayList<>();
266                 List<ImmutablePair<String, String>> productSubsToDelete = new ArrayList<>();
267                 List<ImmutablePair<String, String>> resourceSubsToDelete = new ArrayList<>();
268                 List<String> productCategoriesToDelete = new ArrayList<>();
269                 List<String> resourceCategoriesToDelete = new ArrayList<String>();
270                 List<String> serviceCategoriesToDelete = new ArrayList<String>();
271
272                 List<String> resourcesNotToDelete = config.getResourcesNotToDelete();
273                 List<String> resourceCategoriesNotToDelete = config.getResourceCategoriesNotToDelete();
274                 List<String> serviceCategoriesNotToDelete = config.getServiceCategoriesNotToDelete();
275
276                 Iterable<TitanVertex> vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Resource.getName()).vertices();
277                 if (vertices != null) {
278                         Iterator<TitanVertex> iter = vertices.iterator();
279                         while (iter.hasNext()) {
280                                 Vertex vertex = iter.next();
281                                 Boolean isAbstract = vertex.value(GraphPropertiesDictionary.IS_ABSTRACT.getProperty());
282                                 // if (!isAbstract) {
283                                 String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
284                                 String version = vertex.value(GraphPropertiesDictionary.VERSION.getProperty());
285
286                                 if ((resourcesNotToDelete != null && !resourcesNotToDelete.contains(name)) || (version != null && !version.equals("1.0"))) {
287                                         String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
288                                         String resourceType = vertex.value(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty());
289                                         if (name.startsWith("ci")) {
290                                                 if (resourceType.equals(ResourceTypeEnum.VF.name())) {
291                                                         vfResourcesToDelete.add(id);
292                                                 } else {
293                                                         nonVfResourcesToDelete.add(id);
294                                                 }
295                                         }
296                                 } else if ((resourcesNotToDelete != null && !resourcesNotToDelete.contains(name)) || (version != null && version.equals("1.0"))) {
297                                         if ((boolean) vertex.value(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()) == false) {
298                                                 vertex.property(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
299                                         }
300                                 }
301                                 // }
302                         }
303                 }
304                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Service.getName()).vertices();
305                 if (vertices != null) {
306                         Iterator<TitanVertex> iter = vertices.iterator();
307                         while (iter.hasNext()) {
308                                 Vertex vertex = iter.next();
309                                 String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
310                                 String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
311                                 if (name.startsWith("ci")) {
312                                         servicesToDelete.add(id);
313                                 }
314                         }
315                 }
316
317                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices();
318                 if (vertices != null) {
319                         Iterator<TitanVertex> iter = vertices.iterator();
320                         while (iter.hasNext()) {
321                                 Vertex vertex = iter.next();
322                                 String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
323                                 String name = vertex.value(GraphPropertiesDictionary.NAME.getProperty());
324                                 if (name.startsWith("Ci")) {
325                                         productsToDelete.add(id);
326                                 }
327                         }
328                 }
329
330                 // Getting categories
331
332                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ResourceNewCategory.getName()).vertices();
333                 if (vertices != null) {
334                         Iterator<TitanVertex> iter = vertices.iterator();
335                         while (iter.hasNext()) {
336                                 Vertex category = iter.next();
337                                 String name = category.value(GraphPropertiesDictionary.NAME.getProperty());
338                                 if (!resourceCategoriesNotToDelete.contains(name)) {
339                                         String catId = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
340                                         resourceCategoriesToDelete.add(catId);
341                                         Iterator<Vertex> subs = category.vertices(Direction.OUT, GraphEdgeLabels.SUB_CATEGORY.getProperty());
342                                         while (subs.hasNext()) {
343                                                 Vertex sub = subs.next();
344                                                 String subCatId = sub.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
345                                                 resourceSubsToDelete.add(new ImmutablePair<String, String>(catId, subCatId));
346                                         }
347                                 }
348                         }
349                 }
350
351                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ServiceNewCategory.getName()).vertices();
352                 if (vertices != null) {
353                         Iterator<TitanVertex> iter = vertices.iterator();
354                         while (iter.hasNext()) {
355                                 Vertex category = iter.next();
356                                 String name = category.value(GraphPropertiesDictionary.NAME.getProperty());
357                                 if (!serviceCategoriesNotToDelete.contains(name)) {
358                                         String id = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
359                                         serviceCategoriesToDelete.add(id);
360                                 }
361                         }
362                 }
363
364                 vertices = titanGraph.query().has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.ProductCategory.getName()).vertices();
365                 if (vertices != null) {
366                         Iterator<TitanVertex> iter = vertices.iterator();
367                         while (iter.hasNext()) {
368                                 Vertex category = iter.next();
369                                 String catId = category.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
370                                 productCategoriesToDelete.add(catId);
371                                 Iterator<Vertex> subs = category.vertices(Direction.OUT, GraphEdgeLabels.SUB_CATEGORY.getProperty());
372                                 while (subs.hasNext()) {
373                                         Vertex sub = subs.next();
374                                         String subCatId = sub.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
375                                         productSubsToDelete.add(new ImmutablePair<String, String>(catId, subCatId));
376                                         Iterator<Vertex> groupings = sub.vertices(Direction.OUT, GraphEdgeLabels.GROUPING.getProperty());
377                                         while (groupings.hasNext()) {
378                                                 Vertex grouping = groupings.next();
379                                                 String groupId = grouping.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
380                                                 productGroupingsToDelete.add(new ImmutableTriple<String, String, String>(catId, subCatId, groupId));
381                                         }
382                                 }
383
384                         }
385                 }
386
387                 titanGraph.tx().commit();
388
389                 String adminId = UserRoleEnum.ADMIN.getUserId();
390         /*      String productStrategistId = UserRoleEnum.PRODUCT_STRATEGIST1.getUserId();*/
391
392                 // Component delete
393                 
394 /*              for (String id : productsToDelete) {
395                         RestResponse deleteProduct = ProductRestUtils.deleteProduct(id, productStrategistId);
396
397                 }*/
398                 for (String id : servicesToDelete) {
399                         RestResponse deleteServiceById = ServiceRestUtils.deleteServiceById(id, adminId);
400
401                 }
402                 for (String id : vfResourcesToDelete) {
403                         RestResponse deleteResource = ResourceRestUtils.deleteResource(id, adminId);
404
405                 }
406
407                 for (String id : nonVfResourcesToDelete) {
408                         RestResponse deleteResource = ResourceRestUtils.deleteResource(id, adminId);
409
410                 }
411
412                 // Categories delete - product
413                 /*String componentType = BaseRestUtils.PRODUCT_COMPONENT_TYPE;
414                 for (ImmutableTriple<String, String, String> triple : productGroupingsToDelete) {
415                         CategoryRestUtils.deleteGrouping(triple.getRight(), triple.getMiddle(), triple.getLeft(), productStrategistId, componentType);
416                 }
417                 for (ImmutablePair<String, String> pair : productSubsToDelete) {
418                         CategoryRestUtils.deleteSubCategory(pair.getRight(), pair.getLeft(), productStrategistId, componentType);
419                 }
420                 for (String id : productCategoriesToDelete) {
421                         CategoryRestUtils.deleteCategory(id, productStrategistId, componentType);
422                 }*/
423
424                 // Categories delete - resource
425                 String componentType = BaseRestUtils.RESOURCE_COMPONENT_TYPE;
426                 for (ImmutablePair<String, String> pair : resourceSubsToDelete) {
427                         CategoryRestUtils.deleteSubCategory(pair.getRight(), pair.getLeft(), adminId, componentType);
428                 }
429                 for (String id : resourceCategoriesToDelete) {
430                         CategoryRestUtils.deleteCategory(id, adminId, componentType);
431                 }
432                 // Categories delete - resource
433                 componentType = BaseRestUtils.SERVICE_COMPONENT_TYPE;
434                 for (String id : serviceCategoriesToDelete) {
435                         CategoryRestUtils.deleteCategory(id, adminId, componentType);
436                 }
437
438         }
439
440         private static void deleteCreatedComponents(Map<String, List<Component>> convertCatalogResponseToJavaObject) throws IOException {
441                 final String userId = UserRoleEnum.DESIGNER.getUserId();
442                 
443                 List<Component> resourcesArrayList = convertCatalogResponseToJavaObject.get(ComponentTypeEnum.PRODUCT_PARAM_NAME);
444                 if (resourcesArrayList.size() > 0) {
445                         List<String> collect = buildCollectionUniqueId(resourcesArrayList);
446                         for (String uId : collect) {
447                                 ProductRestUtils.deleteProduct(uId, userId);
448                         }
449                 }
450                 
451                 
452                 resourcesArrayList = convertCatalogResponseToJavaObject.get(ComponentTypeEnum.SERVICE_PARAM_NAME);
453                 if (resourcesArrayList.size() > 0) {
454                         List<String> collect = buildCollectionUniqueId(resourcesArrayList);
455                         for (String uId : collect) {
456                                 ServiceRestUtils.markServiceToDelete(uId, userId);
457                         }
458                         ServiceRestUtils.deleteMarkedServices(userId);
459                 }
460
461                 
462                 resourcesArrayList = convertCatalogResponseToJavaObject.get(ComponentTypeEnum.RESOURCE_PARAM_NAME);
463
464                 // List<String> collect = resourcesArrayList.stream().filter(s ->
465                 // s.getName().startsWith("ci")).map(e ->
466                 // e.getUniqueId()).collect(Collectors.toList());
467
468                 // List<Map<String, String>> collect =
469                 // resourcesArrayList.stream().filter(s ->
470                 // s.getName().startsWith("ci")).map(e ->
471                 // e.getAllVersions()).collect(Collectors.toList());
472                 /*
473                  * List<String> collect = resourcesArrayList.stream().filter(s -> s.getName().startsWith("ci")) .flatMap(e -> e.getAllVersions().values().stream()).collect(Collectors.toList());
474                  */
475
476                 if (!CollectionUtils.isEmpty(resourcesArrayList)) {
477                         List<String> collect = buildCollectionUniqueId(resourcesArrayList);
478                         for (String uId : collect) {
479                                 ResourceRestUtils.markResourceToDelete(uId, userId);
480                         }
481                         ResourceRestUtils.deleteMarkedResources(userId);
482                 }
483
484         
485
486         }
487
488         private void deleteCollection(List<Component> componentArrayList, Consumer<String> deleteHandler) {
489
490                 if (componentArrayList.size() > 0) {
491                         List<String> collect = buildCollectionUniqueId(componentArrayList);
492                         for (String uId : collect) {
493                                 deleteHandler.accept(uId);
494                                 // ProductRestUtils.deleteProduct(uId, userId);
495                         }
496                 }
497         }
498
499         protected static List<String> buildCollectionUniqueId(List<Component> resourcesArrayList) {
500
501                 // Stream<String> flatMap = resourcesArrayList.stream().filter(s ->
502                 // s.getName().startsWith("ci")).map(e -> e.getAllVersions()).map( e ->
503                 // e.values()).flatMap( e -> e.stream());
504
505                 // List<String> collect = resourcesArrayList.stream()
506                 // //
507                 // .filter(s -> s.getName().startsWith("ci") )
508                 // //
509                 // .map(e -> e.getUniqueId())
510
511                 // .map( e -> e.values())
512                 // .filter(out -> out!=null )
513                 // .flatMap( e -> e.stream())
514                 // .collect(Collectors.toList());
515
516                 // List<String> collect = resourcesArrayList.stream().filter(s ->
517                 // s.getName().startsWith("ci"))
518                 // .flatMap(e ->
519                 // e.getAllVersions().values().stream()).collect(Collectors.toList());
520                 ComponentTypeEnum componentTypeEnum = resourcesArrayList.get(0).getComponentType();
521  
522                 List<String> genericCollection = new ArrayList<String>();
523                 
524                 resourcesArrayList.stream().filter(s -> s.getName().toLowerCase().startsWith("ci") && !s.getName().toLowerCase().equals("cindervolume")).map(e -> e.getUniqueId()).collect(Collectors.toList()).forEach((i) -> {
525                         buildCollectionBaseOnComponentType(componentTypeEnum, genericCollection, i);
526                 });
527                 
528         
529                 //
530
531                 // List<String> collect =
532                 // genericCollection.stream().collect(Collectors.toList());
533
534                 return genericCollection;
535         }
536
537         public static void buildCollectionBaseOnComponentType(ComponentTypeEnum componentTypeEnum,
538                         List<String> genericCollection, String i) {
539                 try {
540                         switch (componentTypeEnum) {
541                         case RESOURCE:
542                                 RestResponse resource = ResourceRestUtils.getResource(i);
543                                 Resource convertResourceResponseToJavaObject = ResponseParser.convertResourceResponseToJavaObject(resource.getResponse());
544                                 Map<String, String> allVersions = convertResourceResponseToJavaObject.getAllVersions();
545                                 Collection<String> values = allVersions.values();
546                                 genericCollection.addAll(values);
547                                         
548                                 break;
549                         case SERVICE:
550                                 RestResponse service = ServiceRestUtils.getService(i);
551                                 Service convertServiceResponseToJavaObject = ResponseParser.convertServiceResponseToJavaObject(service.getResponse());
552                                 allVersions = convertServiceResponseToJavaObject.getAllVersions();
553                                 values = allVersions.values();
554                                 genericCollection.addAll(values);
555
556                                 break;
557                                         
558
559                         case PRODUCT:
560                                 RestResponse product = ProductRestUtils.getProduct(i);
561                                 Product convertProductResponseToJavaObject = ResponseParser.convertProductResponseToJavaObject(product.getResponse());
562                                 allVersions = convertProductResponseToJavaObject.getAllVersions();
563                                 values = allVersions.values();
564                                 genericCollection.addAll(values);
565
566                                 break;
567
568                         // default:
569                         // break;
570                         }
571                 } catch (Exception e1) {
572                         // TODO Auto-generated catch block
573                         e1.printStackTrace();
574                 }
575         }
576
577         protected static Map<String, List<Component>> getCatalogAsMap() throws Exception {
578                 RestResponse catalog = CatalogRestUtils.getCatalog(UserRoleEnum.DESIGNER.getUserId());
579                 Map<String, List<Component>> convertCatalogResponseToJavaObject = ResponseParser.convertCatalogResponseToJavaObject(catalog.getResponse());
580                 return convertCatalogResponseToJavaObject;
581         }
582         protected Resource createVfFromCSAR(User sdncModifierDetails, String csarId) throws Exception {
583                 // create new resource from Csar
584                 ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
585
586                 resourceDetails.setCsarUUID(csarId);
587                 resourceDetails.setResourceType(ResourceTypeEnum.VF.name());
588                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
589                 BaseRestUtils.checkCreateResponse(createResource);
590                 Resource createdResource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
591                 return createdResource;
592         }
593         
594
595
596 }