use of org.exoplatform.services.cache.impl.CacheServiceImpl in project kernel by exoplatform.
the class TestCacheService method testCacheFactory.
public void testCacheFactory() throws Exception {
InitParams params = new InitParams();
ObjectParameter param = new ObjectParameter();
param.setName("NoImpl");
ExoCacheConfig config = new ExoCacheConfig();
config.setName(param.getName());
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("KnownImpl");
config = new ExoCacheConfig();
config.setName(param.getName());
config.setImplementation("org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("UnKnownImpl");
config = new ExoCacheConfig();
config.setName(param.getName());
config.setImplementation("fakeImpl");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("UnKnownImplButCorrectFQN");
config = new ExoCacheConfig();
config.setName(param.getName());
config.setImplementation("java.lang.String");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("NoImpl-MyExoCacheConfig");
config = new MyExoCacheConfig();
config.setName(param.getName());
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("KnownImpl-MyExoCacheConfig");
config = new MyExoCacheConfig();
config.setName(param.getName());
config.setImplementation("org.exoplatform.services.cache.FIFOExoCache");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("UnKnownImpl-MyExoCacheConfig");
config = new MyExoCacheConfig();
config.setName(param.getName());
config.setImplementation("fakeImpl");
param.setObject(config);
params.addParameter(param);
param = new ObjectParameter();
param.setName("UnKnownImplButCorrectFQN-MyExoCacheConfig");
config = new MyExoCacheConfig();
config.setName(param.getName());
config.setImplementation("java.lang.String");
param.setObject(config);
params.addParameter(param);
CacheService cs = new CacheServiceImpl(params, new MyExoCacheFactory());
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("NoImpl").getClass(), cs.getCacheInstance("NoImpl") instanceof MyExoCache);
assertTrue("Expected type ConcurrentFIFOExoCache found " + cs.getCacheInstance("KnownImpl").getClass(), cs.getCacheInstance("KnownImpl") instanceof ConcurrentFIFOExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImpl").getClass(), cs.getCacheInstance("UnKnownImpl") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImplButCorrectFQN").getClass(), cs.getCacheInstance("UnKnownImplButCorrectFQN") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("NoImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("NoImpl-MyExoCacheConfig") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("KnownImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("KnownImpl-MyExoCacheConfig") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("UnKnownImpl-MyExoCacheConfig") instanceof MyExoCache);
assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImplButCorrectFQN-MyExoCacheConfig").getClass(), cs.getCacheInstance("UnKnownImplButCorrectFQN-MyExoCacheConfig") instanceof MyExoCache);
}
Aggregations