Project

General

Profile

« Previous | Next » 

Revision fe43cd3b

Added by Andreas Müller over 8 years ago

Implement taggedTitle for taxon base #5229

View differences:

cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/name/NameCacheStrategyTestBase.java
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.TaggedText;
18

  
19
/**
20
 * Base class for testing name cache strategies
21
 * @author a.mueller
22
 */
23
public class NameCacheStrategyTestBase {
24
	private static final Logger logger = Logger.getLogger(ZoologicalNameCacheStrategyTest.class);
25
	
26
	
27
	
28
	protected Method getMethod(Class<?> clazz, String methodName, Class<?> paramClazzes){
29
		Method method;
30
		try {
31
			method = clazz.getDeclaredMethod(methodName, paramClazzes);
32
		} catch (SecurityException e) {
33
			logger.error("SecurityException " + e.getMessage());
34
			return null;
35
		} catch (NoSuchMethodException e) {
36
			logger.error("NoSuchMethodException " + e.getMessage());
37
			return null;
38
		}
39
		return method;
40
	}
41
	
42
	
43
	protected String getStringValue(Method method, Object object,Object parameter){
44
		try {
45
			List<TaggedText> list = (List<TaggedText>)method.invoke(object, parameter);
46
			return NonViralNameDefaultCacheStrategy.createString(list);
47
		} catch (IllegalArgumentException e) {
48
			logger.error("IllegalArgumentException " + e.getMessage());
49
			return null;
50
		} catch (IllegalAccessException e) {
51
			logger.error("IllegalAccessException " + e.getMessage());
52
			return null;
53
		} catch (InvocationTargetException e) {
54
			logger.error("InvocationTargetException " + e.getMessage());
55
			return null;
56
		}
57
	}
58
}
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
}

Also available in: Unified diff