segments.add("windowid");
ContentCacheKeyGenerator generator = new JetspeedCacheKeyGenerator(segments);
JetspeedCache contentCache = new EhPortletContentCacheImpl(ehContentCache, generator);
// create the mock request context
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setUserPrincipal(new MockPrincipal("david"));
MockHttpSession session = new MockHttpSession();
request.setSession(session);
String sessionId = session.getId();
MockRequestContext context = new MockRequestContext(request, response);
// create a simple key
String window1 = "555-01";
ContentCacheKey cckey1 = contentCache.createCacheKey(context, window1);
assertEquals(cckey1.getKey(), sessionId + "/portal/555-01");
// create a another key for desktop
String window2 = "555-02";
context.getParameterMap().put("encoder", "desktop");
ContentCacheKey cckey2 = contentCache.createCacheKey(context, window2);
assertEquals(cckey2.getKey(), sessionId + "/desktop/555-02");
// create some PortletContent mock objects
PortletContent content1 = new MockPortletContent(cckey1, 100, "ContentOne", "content1content1content1content1");
PortletContent content2 = new MockPortletContent(cckey2, 200, "ContentTwo", "content2content2content2content2");
// put it in the cache
CacheElement element1 = contentCache.createElement(cckey1, content1);
contentCache.put(element1);
CacheElement element2 = contentCache.createElement(cckey2, content2);
contentCache.put(element2);
// assert the gets
Object result1 = contentCache.get(cckey1);
assertNotNull(result1);
System.out.println("result 1 = " + result1);
Object result2 = contentCache.get(cckey2);
assertNotNull(result2);
System.out.println("result 2 = " + result2);
// assert isKey Apis
assertTrue(contentCache.isKeyInCache(cckey1));
// test removes
contentCache.remove(cckey1);
assertFalse(contentCache.isKeyInCache(cckey1));
assertTrue(contentCache.isKeyInCache(cckey2));
// test user stuff
session = new MockHttpSession();
request.setSession(session);
sessionId = session.getId();
request.setUserPrincipal(new MockPrincipal("sean"));
// create a simple key
String window3 = "555-03";
ContentCacheKey cckey3 = contentCache.createCacheKey(context, window3);
assertEquals(cckey3.getKey(), sessionId + "/desktop/555-03");