1 package org.cateproject.view.cache;
2
3 import java.util.UUID;
4
5 import net.sf.ehcache.Ehcache;
6 import net.sf.ehcache.Element;
7 import net.sf.ehcache.constructs.web.PageInfo;
8
9 import org.easymock.EasyMock;
10 import org.junit.Test;
11 import org.springframework.mock.web.MockFilterChain;
12 import org.springframework.mock.web.MockHttpServletRequest;
13 import org.springframework.mock.web.MockHttpServletResponse;
14
15 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
16
17
18 public class CdmObjectPageCacheImplTest {
19
20 @Test
21 public void testObjectCache() throws Exception {
22 CdmObjectPageCacheImpl<TaxonBase> pageCache = new CdmObjectPageCacheImpl<TaxonBase>();
23 pageCache.setDirectory("taxon");
24 pageCache.setType(TaxonBase.class);
25
26 MockHttpServletRequest request = new MockHttpServletRequest();
27 request.setRequestURI("/taxon/" + UUID.randomUUID().toString());
28
29 CateContentTypeResolver contentTypeResolver = EasyMock.createMock(CateContentTypeResolver.class);
30 EasyMock.expect(contentTypeResolver.resolveContentType(request)).andReturn("html").anyTimes();
31 Element element = new Element("",new PageInfo(0, null, null, null, "<html></html>".getBytes(), false, 0));
32
33 Ehcache cache = EasyMock.createMock(Ehcache.class);
34 EasyMock.expect(cache.get(EasyMock.isA(String.class))).andReturn(element);
35
36 EasyMock.replay(cache,contentTypeResolver);
37
38 pageCache.setCateContentTypeResolver(contentTypeResolver);
39 pageCache.setObjectCache(cache);
40 pageCache.setFilter(new DelegatingPageCachingFilter());
41 pageCache.init();
42
43 pageCache.filter(request, new MockHttpServletResponse(), new MockFilterChain());
44
45 EasyMock.verify(cache,contentTypeResolver);
46 }
47
48 }