1   package org.jmage.cache;
2   
3   import org.jmage.ImageRequest;
4   import org.jmage.JmageException;
5   import org.jmage.dispatcher.RequestDispatcher;
6   import org.jmock.Mock;
7   import org.jmock.MockObjectTestCase;
8   
9   import java.util.Properties;
10  
11  /***
12   * CachingProxyTests
13   */
14  public class CachingProxyTests extends MockObjectTestCase {
15  
16      public void testCachingProxy() throws JmageException {
17          ImageRequest imageRequest = new ImageRequest();
18          byte[] rval = new byte[]{0x00, 0x01, 0x02};
19  
20          Mock mockRequestDispatcher = new Mock(RequestDispatcher.class);
21          mockRequestDispatcher.expects(atLeastOnce()).method("createFrom").with(same(imageRequest)).will(returnValue(rval));
22  
23          Properties cacheProperties = new Properties();
24          cacheProperties.setProperty("cachesize", "5");
25          cacheProperties.setProperty("cachetype", CacheManagerImpl.MEMORY);
26  
27          RequestDispatcher requestDispatcher2 = null;
28          requestDispatcher2 = (RequestDispatcher) CachingFactoryProxy.newInstance((RequestDispatcher) mockRequestDispatcher.proxy(), cacheProperties);
29  
30          assertTrue(rval.equals(requestDispatcher2.createFrom(imageRequest)));
31          //test cache
32          assertTrue(rval.equals(requestDispatcher2.createFrom(imageRequest)));
33  
34          mockRequestDispatcher.verify();
35      }
36  }