1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.strategy.cache.name;
|
10
|
|
11
|
import java.lang.reflect.InvocationTargetException;
|
12
|
import java.lang.reflect.Method;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
|
18
|
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
|
19
|
|
20
|
/**
|
21
|
* Base class for testing name cache strategies
|
22
|
* @author a.mueller
|
23
|
*/
|
24
|
public class NameCacheStrategyTestBase {
|
25
|
private static final Logger logger = Logger.getLogger(ZoologicalNameCacheStrategyTest.class);
|
26
|
|
27
|
|
28
|
|
29
|
protected Method getMethod(Class<?> clazz, String methodName, Class<?> paramClazzes){
|
30
|
Method method;
|
31
|
try {
|
32
|
method = clazz.getDeclaredMethod(methodName, paramClazzes);
|
33
|
} catch (SecurityException e) {
|
34
|
logger.error("SecurityException " + e.getMessage());
|
35
|
return null;
|
36
|
} catch (NoSuchMethodException e) {
|
37
|
logger.error("NoSuchMethodException " + e.getMessage());
|
38
|
return null;
|
39
|
}
|
40
|
return method;
|
41
|
}
|
42
|
|
43
|
|
44
|
protected String getStringValue(Method method, Object object,Object parameter){
|
45
|
try {
|
46
|
List<TaggedText> list = (List<TaggedText>)method.invoke(object, parameter);
|
47
|
return TaggedCacheHelper.createString(list);
|
48
|
} catch (IllegalArgumentException e) {
|
49
|
logger.error("IllegalArgumentException " + e.getMessage());
|
50
|
return null;
|
51
|
} catch (IllegalAccessException e) {
|
52
|
logger.error("IllegalAccessException " + e.getMessage());
|
53
|
return null;
|
54
|
} catch (InvocationTargetException e) {
|
55
|
logger.error("InvocationTargetException " + e.getMessage());
|
56
|
return null;
|
57
|
}
|
58
|
}
|
59
|
}
|