01: /* LdapFixtureLoader.java
02: *
03: * DDSteps - Data Driven JUnit Test Steps
04: * Copyright (C) 2005 Jayway AB
05: * www.ddsteps.org
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License version 2.1 as published by the Free Software Foundation.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, visit
18: * http://www.opensource.org/licenses/lgpl-license.php
19: */
20:
21: package org.ddsteps.fixture.ldap;
22:
23: import junit.framework.TestCase;
24: import net.sf.ldaptemplate.LdapOperations;
25:
26: import org.apache.commons.lang.StringUtils;
27: import org.ddsteps.dataset.DataSetLoader;
28: import org.ddsteps.fixture.Fixture;
29: import org.ddsteps.fixture.FixtureLoader;
30:
31: /**
32: * FixtureLoader for Ldap Fixtures.
33: *
34: * @author Mattias Arthursson
35: */
36: public class LdapFixtureLoader implements FixtureLoader {
37:
38: private DataSetLoader dataSetLoader;
39:
40: private LdapOperations ldapOperations;
41:
42: private String[] tableNames;
43:
44: public Fixture loadFixture(TestCase testCase) {
45: LdapFixture ldapFixture = new LdapFixture(dataSetLoader
46: .loadDataSet(testCase.getClass()), ldapOperations);
47: ldapFixture.setTableNames(tableNames);
48: return ldapFixture;
49: }
50:
51: public void setDataSetLoader(DataSetLoader dataSetLoader) {
52: this .dataSetLoader = dataSetLoader;
53: }
54:
55: public void setLdapOperations(LdapOperations ldapOperations) {
56: this .ldapOperations = ldapOperations;
57: }
58:
59: public DataSetLoader getDataSetLoader() {
60: return dataSetLoader;
61: }
62:
63: /**
64: * Set the table names to be considered by Fixtures created from this
65: * FixtureLoader.
66: *
67: * @param tableNames
68: * names of the tables in the DataSet to be used when setting up
69: * ad tearing down the fixture.
70: */
71: public void setTableNames(String[] tableNames) {
72: this .tableNames = tableNames;
73: for (int i = 0; i < tableNames.length; i++) {
74: this.tableNames[i] = StringUtils.strip(tableNames[i]);
75: }
76: }
77: }
|