Added oparent to sdc main
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / dataProviders / OnboardingDataProviders.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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.dataProviders;
22
23 import org.openecomp.sdc.ci.tests.datatypes.enums.XnfTypeEnum;
24 import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
25 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtils;
26 import org.testng.annotations.DataProvider;
27
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.List;
31
32 public class OnboardingDataProviders {
33
34         protected static String filepath = FileHandling.getVnfRepositoryPath();
35         
36 //      -----------------------dataProviders-----------------------------------------   
37         @DataProvider(name = "randomVNF_List", parallel = false)
38         private static final Object[][] randomVnfList() throws Exception {
39                 int randomElementNumber = 3; //how many VNFs to onboard randomly
40                 List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
41                 List<String> newRandomFileNamesFromFolder = getRandomElements(randomElementNumber, fileNamesFromFolder);
42                 System.out.println(String.format("There are %s zip file(s) to test", newRandomFileNamesFromFolder.size()));
43                 return provideData(newRandomFileNamesFromFolder, filepath);
44         }
45         
46         @DataProvider(name = "VNF_List" , parallel = true)
47         private static final Object[][] VnfList() throws Exception {
48                 
49                 List<String> fileNamesFromFolder = OnboardingUtils.getXnfNamesFileList(XnfTypeEnum.VNF);
50                 
51                 System.out.println(String.format("There are %s zip file(s) to test", fileNamesFromFolder.size()));
52                 return provideData(fileNamesFromFolder, filepath);
53         }
54         
55 //      -----------------------factories-----------------------------------------
56
57         
58         
59         
60 //      -----------------------methods-----------------------------------------
61         public static Object[][] provideData(List<String> fileNamesFromFolder, String filepath) {
62                 
63                 Object[][] arObject = new Object[fileNamesFromFolder.size()][];
64                 int index = 0;
65                 for (Object obj : fileNamesFromFolder) {
66                         arObject[index++] = new Object[] { filepath, obj };
67                 }
68                 return arObject;
69         }
70         
71         private static List<String> getRandomElements(int randomElementNumber, List<String> fileNamesFromFolder) {
72                 if(fileNamesFromFolder.size() == 0 || fileNamesFromFolder.size() < randomElementNumber){
73                         return null;
74                 }else{
75                         List<Integer> indexList = new ArrayList<>();
76                         List<String> newRandomFileNamesFromFolder = new ArrayList<>(); 
77                         for(int i = 0; i < fileNamesFromFolder.size(); i++){
78                                 indexList.add(i);
79                         }
80                         Collections.shuffle(indexList);
81                         Integer[] randomArray = indexList.subList(0, randomElementNumber).toArray(new Integer[randomElementNumber]);
82                         for(int i = 0; i < randomArray.length; i++){
83                                 newRandomFileNamesFromFolder.add(fileNamesFromFolder.get(randomArray[i]));
84                         }
85                         return newRandomFileNamesFromFolder;
86                 }
87         }
88         
89         
90         
91         
92 }