01: package org.ddsteps.data;
02:
03: import junit.framework.TestCase;
04:
05: import org.apache.commons.lang.Validate;
06: import org.ddsteps.dataset.DataRow;
07: import org.ddsteps.dataset.DataSet;
08: import org.ddsteps.dataset.DataSetLoader;
09: import org.ddsteps.dataset.DataTable;
10:
11: /**
12: * DataLoader that is backed by a DataSetLoader.
13: *
14: * DataLoaders load data for testcases. DataSets are generic, and may contain
15: * fixture data as well.
16: *
17: * @author adamskogman
18: */
19: public class DataSetDataLoader implements DataLoader {
20:
21: /**
22: * The backing data set loader.
23: */
24: protected final DataSetLoader dataSetLoader;
25:
26: /**
27: * Dependency Injection constructor.
28: *
29: * @param dataSetLoader
30: * Backing DataSetLoader.
31: */
32: public DataSetDataLoader(DataSetLoader dataSetLoader) {
33: super ();
34: Validate.notNull(dataSetLoader,
35: "Argument dataSetLoader must not be null.");
36:
37: this .dataSetLoader = dataSetLoader;
38: }
39:
40: /**
41: * @see org.ddsteps.data.DataLoader#loadTable(junit.framework.TestCase,
42: * java.lang.String)
43: */
44: public DataTable loadTable(TestCase testCase, String methodName) {
45: DataSet dataSet = dataSetLoader
46: .loadDataSet(testCase.getClass());
47:
48: if (dataSet == null) {
49: // No dataset -> no table
50: return null;
51: }
52:
53: // Get table by name
54: DataTable dataTable = dataSet.getTable(methodName);
55:
56: return dataTable;
57: }
58:
59: /**
60: * @see org.ddsteps.data.DataLoader#loadRow(junit.framework.TestCase,
61: * java.lang.String, java.lang.String)
62: */
63: public DataRow loadRow(TestCase testCase, String methodName,
64: String rowId) {
65: DataTable table = loadTable(testCase, methodName);
66:
67: if (table == null)
68: return null;
69:
70: return table.findRowById(rowId);
71: }
72:
73: /**
74: * @return Returns the backing dataSetLoader.
75: */
76: public DataSetLoader getDataSetLoader() {
77: return dataSetLoader;
78: }
79:
80: }
|