1
|
package eu.etaxonomy.cdm.api.cache;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.util.List;
|
5
|
|
6
|
import net.sf.ehcache.Cache;
|
7
|
|
8
|
import org.apache.log4j.Level;
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.junit.Assert;
|
11
|
import org.junit.Test;
|
12
|
import org.springframework.core.io.ClassPathResource;
|
13
|
import org.springframework.core.io.Resource;
|
14
|
|
15
|
import eu.etaxonomy.taxeditor.remoting.cache.CdmClientCacheException;
|
16
|
import eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher;
|
17
|
import eu.etaxonomy.taxeditor.remoting.cache.CdmModelFieldPropertyFromClass;
|
18
|
import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
|
19
|
import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager.CdmCacheManagerType;
|
20
|
|
21
|
|
22
|
public class CdmModelGetMethodCacherTest {
|
23
|
|
24
|
private static final Logger logger = Logger.getLogger(CdmModelGetMethodCacherTest.class);
|
25
|
|
26
|
public static final Resource CDMLIB_DISK_STORE_RESOURCE =
|
27
|
new ClassPathResource("/eu/etaxonomy/cache");
|
28
|
|
29
|
|
30
|
|
31
|
@Test
|
32
|
public void cacheGettersTest() {
|
33
|
|
34
|
Logger.getRootLogger().setLevel(Level.INFO);
|
35
|
try {
|
36
|
System.setProperty("ehcache.disk.store.dir", CDMLIB_DISK_STORE_RESOURCE.getFile().getAbsolutePath());
|
37
|
} catch (IOException e) {
|
38
|
throw new CdmClientCacheException(e);
|
39
|
}
|
40
|
CdmModelCacher cmdmc = new CdmModelCacher();
|
41
|
|
42
|
//cmdmc.checkGetterMethods();
|
43
|
|
44
|
cmdmc.cacheGetterFields();
|
45
|
|
46
|
|
47
|
Cache cdmlibCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
|
48
|
List<CdmModelFieldPropertyFromClass> cmgmfcList = cmdmc.getCdmModelGetMethodFromClassList();
|
49
|
|
50
|
List<Object> keys = cdmlibCache.getKeys();
|
51
|
Assert.assertEquals(cmgmfcList.size(), keys.size());
|
52
|
|
53
|
for(CdmModelFieldPropertyFromClass cmgmfc: cmgmfcList) {
|
54
|
String className = cmgmfc.getClassName();
|
55
|
Assert.assertTrue(keys.contains(className));
|
56
|
logger.info("Class Name : " + className + " has been cached");
|
57
|
}
|
58
|
cdmlibCache.removeAll();
|
59
|
cdmlibCache.flush();
|
60
|
CdmRemoteCacheManager.getInstance().shutdown(CdmCacheManagerType.CDMLIB_MODEL);
|
61
|
}
|
62
|
|
63
|
|
64
|
|
65
|
|
66
|
}
|