2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.dataProviders;
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;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.List;
32 public class OnboardingDataProviders {
34 protected static String filepath = FileHandling.getVnfRepositoryPath();
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);
46 @DataProvider(name = "VNF_List" , parallel = true)
47 private static final Object[][] VnfList() throws Exception {
49 List<String> fileNamesFromFolder = OnboardingUtils.getXnfNamesFileList(XnfTypeEnum.VNF);
51 System.out.println(String.format("There are %s zip file(s) to test", fileNamesFromFolder.size()));
52 return provideData(fileNamesFromFolder, filepath);
55 // -----------------------factories-----------------------------------------
60 // -----------------------methods-----------------------------------------
61 public static Object[][] provideData(List<String> fileNamesFromFolder, String filepath) {
63 Object[][] arObject = new Object[fileNamesFromFolder.size()][];
65 for (Object obj : fileNamesFromFolder) {
66 arObject[index++] = new Object[] { filepath, obj };
71 private static List<String> getRandomElements(int randomElementNumber, List<String> fileNamesFromFolder) {
72 if(fileNamesFromFolder.size() == 0 || fileNamesFromFolder.size() < randomElementNumber){
75 List<Integer> indexList = new ArrayList<>();
76 List<String> newRandomFileNamesFromFolder = new ArrayList<>();
77 for(int i = 0; i < fileNamesFromFolder.size(); i++){
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]));
85 return newRandomFileNamesFromFolder;