Clover Coverage Report - Liquibase Core 2.0.3-SNAPSHOT
Coverage timestamp: Sat Aug 6 2011 11:33:15 EDT
../../img/srcFileCovDistChart1.png 62% of files have more coverage
23   99   14   2.56
0   82   0.61   9
9     1.56  
1    
 
  CustomPreconditionWrapper       Line # 21 23 0% 14 30 6.2% 0.0625
 
  (2)
 
1    package liquibase.precondition;
2   
3    import java.util.HashMap;
4    import java.util.Map;
5    import java.util.SortedSet;
6    import java.util.TreeSet;
7   
8    import liquibase.changelog.ChangeSet;
9    import liquibase.changelog.DatabaseChangeLog;
10    import liquibase.database.Database;
11    import liquibase.exception.CustomPreconditionErrorException;
12    import liquibase.exception.CustomPreconditionFailedException;
13    import liquibase.exception.PreconditionErrorException;
14    import liquibase.exception.PreconditionFailedException;
15    import liquibase.exception.ValidationErrors;
16    import liquibase.exception.Warnings;
17    import liquibase.precondition.core.ErrorPrecondition;
18    import liquibase.precondition.core.FailedPrecondition;
19    import liquibase.util.ObjectUtil;
20   
 
21    public class CustomPreconditionWrapper implements Precondition {
22   
23    private String className;
24    private ClassLoader classLoader;
25   
26    private SortedSet<String> params = new TreeSet<String>();
27    private Map<String, String> paramValues = new HashMap<String, String>();
28   
 
29  0 toggle public String getClassName() {
30  0 return className;
31    }
32   
 
33  0 toggle public void setClassName(String className) {
34  0 this.className = className;
35    }
36   
 
37  0 toggle public ClassLoader getClassLoader() {
38  0 return classLoader;
39    }
40   
 
41  0 toggle public void setClassLoader(ClassLoader classLoader) {
42  0 this.classLoader = classLoader;
43    }
44   
 
45  0 toggle public void setParam(String name, String value) {
46  0 this.params.add(name);
47  0 this.paramValues.put(name, value);
48    }
49   
 
50  0 toggle @Override
51    public Warnings warn(Database database) {
52  0 return new Warnings();
53    }
54   
 
55  0 toggle @Override
56    public ValidationErrors validate(Database database) {
57  0 return new ValidationErrors();
58    }
59   
 
60  0 toggle @Override
61    public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet)
62    throws PreconditionFailedException, PreconditionErrorException {
63  0 CustomPrecondition customPrecondition;
64  0 try {
65    // System.out.println(classLoader.toString());
66  0 try {
67  0 customPrecondition = (CustomPrecondition) Class.forName(className, true, classLoader).newInstance();
68    } catch (ClassCastException e) { // fails in Ant in particular
69  0 customPrecondition = (CustomPrecondition) Class.forName(className).newInstance();
70    }
71    } catch (Exception e) {
72  0 throw new PreconditionFailedException("Could not open custom precondition class " + className, changeLog,
73    this);
74    }
75   
76  0 for (String param : params) {
77  0 try {
78  0 ObjectUtil.setProperty(customPrecondition, param, paramValues.get(param));
79    } catch (Exception e) {
80  0 throw new PreconditionFailedException("Error setting parameter " + param + " on custom precondition "
81    + className, changeLog, this);
82    }
83    }
84   
85  0 try {
86  0 customPrecondition.check(database);
87    } catch (CustomPreconditionFailedException e) {
88  0 throw new PreconditionFailedException(new FailedPrecondition("Custom Precondition Failed: "
89    + e.getMessage(), changeLog, this));
90    } catch (CustomPreconditionErrorException e) {
91  0 throw new PreconditionErrorException(new ErrorPrecondition(e, changeLog, this));
92    }
93    }
94   
 
95  8 toggle @Override
96    public String getName() {
97  8 return "customPrecondition";
98    }
99    }