import java.util.*;
/**
* Created by Mridul on 9/25/2015.
*/
public class DotcomSuiteGenerator {
/**
* method which recursively generates the probable testcases
* @param prefix
* @param lists
*/
private static int counter;
private List<String> randomList=new ArrayList<>();
private List<String> copyOfRandomList=new ArrayList<>();
/* public void generate(String prefix, String spacer, List<String>... lists) {
int len=lists.length;
if(len > 0) {
List<String> list = lists[0];
lists = Arrays.copyOfRange(lists, 1, len);
for (String value : list) {
String name = prefix + value + spacer;
generate(name,spacer,lists); //recursive call
if(lists.length==0) {
System.out.println(name.substring(0,name.length()-1));
++counter;
}
}
}
}*/
public void generate(String prefix, String spacer, List<String>... lists) {
int len=lists.length;
if(len > 0) {
List<String> list = lists[0];
lists = Arrays.copyOfRange(lists, 1, len);
for (String value : list) {
String name = prefix + value + spacer;
generate(name,spacer,lists); //recursive call
if(lists.length==0) {
name = name + getRandomListValue();
System.out.println(name);
++counter;
}
}
}
}
private String getRandomListValue(){
String result="";
int size=copyOfRandomList.size();
if(size==0)
copyOfRandomList=new ArrayList<>(randomList);
if( size >= 0) {
Collections.shuffle(copyOfRandomList);
result = copyOfRandomList.remove(0);
}
return result;
}
public void appendRandomVariables(List<String>... lists) {
//creating combo list containing all the data for booking
List<String> comboBookingParams=new ArrayList<>();
for(int index=0; index < lists.length; index++) {
comboBookingParams.addAll(lists[index]);
}
randomList=comboBookingParams;
copyOfRandomList=new ArrayList<>(randomList);
for(String value: copyOfRandomList){
System.out.println("value : "+value);
}
System.out.println(" copyOfRandomList.size() : "+copyOfRandomList.size());
}
public static void main(String... args){
//constants
//String prefix="Shopping_Calendar_Matrix_Pricing_"; //for shopping
String prefix="Booking_";
String spacer="_";
//parameters
List<String> tripTypeOW=Arrays.asList("OW");
List<String> tripType=Arrays.asList("RT","MC");
List<String> route=Arrays.asList("DOM","INTL");
List<String> paxTypeADT= Arrays.asList("ADT");
List<String> paxTypeSRC= Arrays.asList("SRC");
List<String> payTypeD=Arrays.asList("Dollars");
List<String> payTypeP=Arrays.asList("Points");
List<String> flightType=Arrays.asList("Dir","Conn");
List<String> fareType=Arrays.asList("BUS","ANY","WGA");
List<String> fareTypeRED=Arrays.asList("BUSRED","ANYRED","WGARED");
List<String> scenarioType=Arrays.asList("SameMonth","DifferentMonth");
List<String> discountType=Arrays.asList("AmtDiscount","PercDiscount");
//booking specific parameters
List<String> creditCards=Arrays.asList("Visa","Mastercard","Diner","Discover","UATP","Amex");
List<String> otherPayTypes=Arrays.asList("GIF","LUV");
List<String> comboPayType=Arrays.asList("Visa_GIF","Visa_LUV","Mastercard_GIF","Mastercard_LUV",
"Diner_GIF","Diner_LUV","Discover_GIF","Discover_LUV",
"UATP_GIF","UATP_LUV","Amex_GIF","Amex_LUV");
List<String> cash=Arrays.asList("Cash");
DotcomSuiteGenerator instance=new DotcomSuiteGenerator();
System.out.println("The combination of tests are: ");
/*
ALL VALID COMBINATIONS OF DATA ARE GIVEN BELOW FOR SHOPPING
*/
//generates all Adult Dollars for OW
/* instance.generate(prefix, spacer, tripTypeOW, route, paxTypeADT, payTypeD, flightType, fareType, scenarioType);
//generates all Adult Points for OW
instance.generate(prefix, spacer, tripTypeOW, route, paxTypeADT, payTypeP, flightType, fareTypeRED, scenarioType);
//generates all Adult Dollars for RT and MC
instance.generate(prefix, spacer, tripType, route, paxTypeADT, payTypeD, flightType, flightType, fareType, scenarioType);
//generates all Adult Points for for RT and MC
instance.generate(prefix, spacer, tripType, route, paxTypeADT, payTypeP, flightType, flightType, fareTypeRED, scenarioType);
//generates all Senior Dollars for OW
instance.generate(prefix, spacer, tripTypeOW, route, paxTypeSRC, payTypeD, flightType, fareType, scenarioType);
//generates all Senior Points for OW
instance.generate(prefix, spacer, tripTypeOW, route, paxTypeSRC, payTypeP, flightType, fareTypeRED, scenarioType);
//generates all Senior Dollars for RT and MC
instance.generate(prefix, spacer, tripType, route, paxTypeSRC, payTypeD, flightType, flightType, fareType, scenarioType);
//generates all Senior Points for RT and MC
instance.generate(prefix, spacer, tripType, route, paxTypeSRC, payTypeP, flightType, flightType, fareTypeRED, scenarioType);*/
//ALL PERCENTAGE AND AMOUNT DISCOUNT SCENARIOS- NOT IN EXCEL SHEET- FOR FUTURE USE
/* //generates all Adult Dollars with Amount and Percentage Discount
instance.generate(prefix, spacer, tripType, route, paxTypeADT, payTypeD, flightType, fareType, scenarioType, discountType);
//generates all Adult Points with Percentage Discount
instance.generate(prefix, spacer, tripType, route, paxTypeADT, payTypeP, flightType, fareTypeRED, scenarioType, Arrays.asList("PercDiscount"));
//generates all Senior Dollars with Amount and Percentage Discount
instance.generate(prefix, spacer, tripType, route, paxTypeSRC, payTypeD, flightType, fareType, scenarioType, discountType);
//generates all Senior Points with Percentage Discount
instance.generate(prefix, spacer, tripType, route, paxTypeSRC, payTypeP, flightType, fareTypeRED, scenarioType, Arrays.asList("PercDiscount"));*/
//EXPERIMENTAL- FOR FUTURE TESTCASES WITH DIFFERENT FARE TYPES ON FLIGHT SEGMENTS OF RT AND MC TESTCASES
/* //generates all RT and MC trips for ADT with Dollars with separate segments
instance.generate(prefix, spacer, Arrays.asList("RT","MC"), route, paxTypeADT, payTypeD, flightType, fareType, fareType, scenarioType);*/
//generate other combo types-one time run
//instance.generate("", spacer, creditCards, otherPayTypes);
/*
ALL VALID COMBINATIONS OF DATA ARE GIVEN BELOW FOR BOOKING
*/
//SET ALL APPENDABLE LISTS HERE
instance.appendRandomVariables(creditCards, otherPayTypes, comboPayType, cash);
//generates all Adult Dollars for OW
instance.generate(prefix, spacer, tripTypeOW, route, paxTypeADT, payTypeD, flightType, fareType, scenarioType);
//generates all Adult Points for OW
instance.generate(prefix, spacer, tripTypeOW, route, paxTypeADT, payTypeP, flightType, fareTypeRED, scenarioType);
//generates all Adult Dollars for RT and MC
instance.generate(prefix, spacer, tripType, route, paxTypeADT, payTypeD, flightType, flightType, fareType, scenarioType);
//generates all Adult Points for for RT and MC
instance.generate(prefix, spacer, tripType, route, paxTypeADT, payTypeP, flightType, flightType, fareTypeRED, scenarioType);
//generates all Senior Dollars for OW
instance.generate(prefix, spacer, tripTypeOW, route, paxTypeSRC, payTypeD, flightType, fareType, scenarioType);
//generates all Senior Points for OW
instance.generate(prefix, spacer, tripTypeOW, route, paxTypeSRC, payTypeP, flightType, fareTypeRED, scenarioType);
//generates all Senior Dollars for RT and MC
instance.generate(prefix, spacer, tripType, route, paxTypeSRC, payTypeD, flightType, flightType, fareType, scenarioType);
//generates all Senior Points for RT and MC
instance.generate(prefix, spacer, tripType, route, paxTypeSRC, payTypeP, flightType, flightType, fareTypeRED, scenarioType);
System.out.println("The total number of tests is : "+counter);
Monday, November 2, 2015
Code to generate test cases and add a uniform distribution of parameters
Subscribe to:
Posts (Atom)