|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Validation.java | 100% | 87,5% | 100% | 91,3% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (C) 2003, Marco Jansen / Contrado Technologies (http://www.contrado.nl)
|
|
| 3 |
*
|
|
| 4 |
* This program is free software; you can redistribute it and/or
|
|
| 5 |
* modify it under the terms of the GNU General Public License as
|
|
| 6 |
* published by the Free Software Foundation; either version 2 of the
|
|
| 7 |
* License, or (at your option) any later version.
|
|
| 8 |
*
|
|
| 9 |
* This program is distributed in the hope that it will be useful, but
|
|
| 10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
| 12 |
* General Public License for more details.
|
|
| 13 |
*/
|
|
| 14 |
|
|
| 15 |
package net.sourceforge.anttestsetgen;
|
|
| 16 |
|
|
| 17 |
import org.apache.tools.ant.BuildException;
|
|
| 18 |
import org.apache.tools.ant.Project;
|
|
| 19 |
import org.apache.tools.ant.Task;
|
|
| 20 |
|
|
| 21 |
import java.sql.ResultSet;
|
|
| 22 |
import java.sql.SQLException;
|
|
| 23 |
import java.util.ArrayList;
|
|
| 24 |
import java.util.List;
|
|
| 25 |
|
|
| 26 |
/**
|
|
| 27 |
* A Validation contains the configuration of an external validator plug-in.<BR>
|
|
| 28 |
* <BR>
|
|
| 29 |
* A Validation has the following attributes:
|
|
| 30 |
* <ul>
|
|
| 31 |
* <li>classname
|
|
| 32 |
* </ul>
|
|
| 33 |
* <p/>
|
|
| 34 |
* A Validation has the following subtasks:
|
|
| 35 |
* <ul>
|
|
| 36 |
* <li>Parameters
|
|
| 37 |
* </ul>
|
|
| 38 |
*
|
|
| 39 |
* @author <a href="mailto:m.c.jansen.spam at planet.nl">Marco Jansen (Contrado Technologies)</a>
|
|
| 40 |
* @version $Id: Validation.java,v 1.4 2004/01/04 15:00:18 mcjansen Exp $
|
|
| 41 |
*/
|
|
| 42 |
public class Validation extends Task { |
|
| 43 |
|
|
| 44 |
/** The name of the validator class. */
|
|
| 45 |
private String classname;
|
|
| 46 |
|
|
| 47 |
/** The parameters that needs to be send to the validator class. */
|
|
| 48 |
private List parameters = new ArrayList(); |
|
| 49 |
|
|
| 50 |
/**
|
|
| 51 |
* Set the fully qualified name of the validation class. So this includes also the packages
|
|
| 52 |
*
|
|
| 53 |
* @param classname The name of the validation class.
|
|
| 54 |
* @see #getClassname
|
|
| 55 |
*/
|
|
| 56 | 16 |
public void setClassname(String classname) { |
| 57 | 16 |
this.classname = classname;
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/**
|
|
| 61 |
* Retrieve the fully qualified name of the validation class. So this includes also the packages.
|
|
| 62 |
*
|
|
| 63 |
* @return The name of the validation class
|
|
| 64 |
* @see #setClassname
|
|
| 65 |
*/
|
|
| 66 | 160 |
public String getClassname() {
|
| 67 | 160 |
return AntTestSetGenUtil.requiredCheck("classname", classname); |
| 68 |
} |
|
| 69 |
|
|
| 70 |
|
|
| 71 |
/**
|
|
| 72 |
* Add a fully configured validation parameter.
|
|
| 73 |
*
|
|
| 74 |
* @param parameter The validation parameter that needs to be added.
|
|
| 75 |
* @see #getParameters
|
|
| 76 |
* @see net.sourceforge.anttestsetgen.Parameter
|
|
| 77 |
*/
|
|
| 78 | 20 |
public void addConfiguredParameter(Parameter parameter) { |
| 79 | 20 |
parameters.add(parameter); |
| 80 |
} |
|
| 81 |
|
|
| 82 |
/**
|
|
| 83 |
* Retrieve the validation parameters.
|
|
| 84 |
*
|
|
| 85 |
* @return A list with validation parameters.
|
|
| 86 |
* @throws org.apache.tools.ant.BuildException
|
|
| 87 |
*
|
|
| 88 |
* @see #addConfiguredParameter
|
|
| 89 |
* @see net.sourceforge.anttestsetgen.Parameter
|
|
| 90 |
*/
|
|
| 91 | 358 |
public List getParameters() throws BuildException { |
| 92 | 358 |
return parameters;
|
| 93 |
} |
|
| 94 |
|
|
| 95 |
/**
|
|
| 96 |
* Validate parameters by the external validator by using the results from the database.
|
|
| 97 |
*
|
|
| 98 |
* @param resultSet The results of the database query
|
|
| 99 |
* @return True in case the combination of parameter values is valid, false if not.
|
|
| 100 |
* @throws org.apache.tools.ant.BuildException
|
|
| 101 |
* In case the external validator could not be instanciated.
|
|
| 102 |
* @throws java.sql.SQLException In case the column with the parameter value could not be retrieved.
|
|
| 103 |
*/
|
|
| 104 | 80 |
public boolean isValid(ResultSet resultSet) throws BuildException, SQLException { |
| 105 | 80 |
try {
|
| 106 | 80 |
log("Validate with " + getClassname(), Project.MSG_VERBOSE);
|
| 107 | 78 |
TestSetValidator testSetValidator = (TestSetValidator) Class.forName(getClassname()).newInstance(); |
| 108 | 76 |
for (int i = 0; i < getParameters().size(); i++) { |
| 109 | 144 |
Parameter parameter = (Parameter) getParameters().get(i); |
| 110 |
|
|
| 111 | 144 |
String databaseValue = parameter.getDatabaseValue(resultSet); |
| 112 |
|
|
| 113 | 140 |
log("Setting validation parameter " + parameter.getName() + " with value " + databaseValue, Project.MSG_VERBOSE); |
| 114 | 138 |
testSetValidator.setParameter(parameter.getName(), databaseValue); |
| 115 |
} |
|
| 116 | 70 |
return testSetValidator.isValid();
|
| 117 |
} catch (ClassNotFoundException e) {
|
|
| 118 | 2 |
throw new BuildException("Error loading validation class: " + getClassname() + "': " + e.getMessage()); |
| 119 |
} catch (InstantiationException e) {
|
|
| 120 | 0 |
throw new BuildException("Error loading validation class: " + getClassname() + "': " + e.getMessage()); |
| 121 |
} catch (IllegalAccessException e) {
|
|
| 122 | 0 |
throw new BuildException("Error loading validation class: " + getClassname() + "': " + e.getMessage()); |
| 123 |
} |
|
| 124 |
} |
|
| 125 |
} |
|
| 126 |
|
|
||||||||||