Changes to product-build.xml to run unit tests in products

This commit is contained in:
bdc34 2010-11-11 19:11:42 +00:00
parent 252763e3b1
commit 17557c3ecb
2 changed files with 71 additions and 1 deletions

View file

@ -67,6 +67,7 @@
</path>
<path id="test.compile.classpath">
<pathelement location="${product.test.dir}"/>
<pathelement location="${war-classes.dir}" />
<path refid="compile.classpath" />
</path>
@ -166,7 +167,7 @@
- - - - - - - - - - - - - - - - - -->
<target name="productTest" depends="productCompile" if="product.tests.exist" unless="skiptests">
<javac srcdir="${product.test.dir}"
destdir="${test.classes.dir}"
destdir="${test-classes.dir}"
debug="true"
deprecation="true"
optimize="false"

View file

@ -0,0 +1,69 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.elements;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
public abstract class BaseEditElement implements EditElement {
private static final Log log = LogFactory.getLog(BaseEditElement.class);
/**
* Utility method for use in EditElements to merge a freemarker template.
*/
protected String merge(Configuration fmConfig, String templateName, Map map){
Template template = null;
try {
template = fmConfig.getTemplate(templateName);
} catch (IOException e) {
log.error("Cannot get template " + templateName);
}
StringWriter writer = new StringWriter();
try {
template.process(map, writer);
} catch (TemplateException e) {
log.error(e,e);
} catch (IOException e) {
log.error(e,e);
}
return writer.toString();
}
/**
* Utility method to check if a value from the query parameters is none or a single value.
* This returns true if the key is there and the value is null.
* This does not check if the value is the empty string.
*/
protected boolean hasNoneOrSingle(String key, Map<String, String[]> queryParameters){
if( queryParameters != null ){
if( ! queryParameters.containsKey(key) )
return true; //none
String[] vt = queryParameters.get(key);
return vt == null || vt.length == 0 || vt.length==1;
}else{
log.error("passed null queryParameters");
return false;
}
}
protected boolean hasSingleNonNullNonEmptyValueForKey(String key, Map<String, String[]> queryParameters){
if( queryParameters != null ){
if( ! queryParameters.containsKey(key) )
return true; //none
String[] vt = queryParameters.get(key);
return vt != null && vt.length == 1 && vt[0] != null && ! vt[0].isEmpty() ;
}else{
log.error("passed null queryParameters");
return false;
}
}
}