Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCT...
If you think the Android project andro_auto_framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.imaginea.botbot.utility;
//fromwww.java2s.comimport java.util.HashMap;
import java.util.List;
import junit.framework.Assert;
import org.imaginea.botbot.api.TestCSVReader;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.util.Log;
publicclass DataDrivenDataGenerator {
String csvFilePath;
List<String[]> row = null;
String[] keySet = null;
TestCSVReader csvReader = null;
static Context context;
publicstaticvoid setContext(Context context) {
DataDrivenDataGenerator.context = context;
}
public DataDrivenDataGenerator(String csvFilePath) {
this.csvFilePath = csvFilePath;
try {
Log.e("context", context.getPackageName());
Resources res = context.getResources();
AssetManager asset = res.getAssets();
csvReader = new TestCSVReader(asset.open(csvFilePath));
} catch (Exception e) {
Log.e("csv cannot be read", e + " CSV");
Assert.fail("Unable to read the csv file :" + e.toString());
}
keySet = csvReader.getRow(0);
}
public HashMap<String, String> getHashMapForRow(int rowNumber) {
HashMap<String, String> data = new HashMap<String, String>();
//setting test case name by taking the first parameter in the row
data.put("TestCaseName", csvReader.getData(rowNumber, 0));
//creating hashmap with identifiers as keys and data in parameters as values
for (int count = 0; count < keySet.length; count++) {
data.put(keySet[count], csvReader.getData(rowNumber, count+1));
}
return data;
}
publicint getNumberOfRows() {
// Subtracting 1 because first row is of keySet
return csvReader.getLines() - 1;
}
}