View Javadoc
1   package org.apache.commons.jcs.auxiliary.remote.http.client;
2   
3   import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
4   import org.apache.commons.jcs.auxiliary.remote.http.client.behavior.IRemoteHttpCacheClient;
5   import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
6   import org.apache.commons.jcs.engine.behavior.IElementSerializer;
7   import org.apache.commons.jcs.engine.control.MockCompositeCacheManager;
8   import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
9   
10  /*
11   * Licensed to the Apache Software Foundation (ASF) under one
12   * or more contributor license agreements.  See the NOTICE file
13   * distributed with this work for additional information
14   * regarding copyright ownership.  The ASF licenses this file
15   * to you under the Apache License, Version 2.0 (the
16   * "License"); you may not use this file except in compliance
17   * with the License.  You may obtain a copy of the License at
18   *
19   *   http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing,
22   * software distributed under the License is distributed on an
23   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24   * KIND, either express or implied.  See the License for the
25   * specific language governing permissions and limitations
26   * under the License.
27   */
28  
29  import junit.framework.TestCase;
30  
31  /** Unit tests for the manager. */
32  public class RemoteHttpCacheFactoryUnitTest
33      extends TestCase
34  {
35      /** Verify that we get the default. */
36      public void testCreateRemoteHttpCacheClient_Bad()
37      {
38          // SETUP
39          String remoteHttpClientClassName = "junk";
40          RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes();
41          cattr.setRemoteHttpClientClassName( remoteHttpClientClassName );
42  
43          RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory();
44  
45          // DO WORK
46          IRemoteHttpCacheClient<String, String> result = factory.createRemoteHttpCacheClientForAttributes( cattr );
47  
48          // VEIFY
49          assertNotNull( "Should have a cache.", result );
50          assertTrue( "Wrong default.", result instanceof RemoteHttpCacheClient );
51          assertTrue( "Should be initialized", ((RemoteHttpCacheClient<String, String>)result).isInitialized() );
52      }
53  
54      /** Verify that we get the default. */
55      public void testCreateRemoteHttpCacheClient_default()
56      {
57          // SETUP
58          RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes();
59          RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory();
60  
61          // DO WORK
62          IRemoteHttpCacheClient<String, String> result = factory.createRemoteHttpCacheClientForAttributes( cattr );
63  
64          // VEIFY
65          assertNotNull( "Should have a cache.", result );
66          assertTrue( "Wrong default.", result instanceof RemoteHttpCacheClient );
67      }
68  
69      /** Verify that we get a cache no wait. */
70      public void testGetCache_normal()
71      {
72          // SETUP
73          ICompositeCacheManager cacheMgr = new MockCompositeCacheManager();
74          ICacheEventLogger cacheEventLogger = null;
75          IElementSerializer elementSerializer = null;
76  
77          RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes();
78          RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory();
79  
80          // DO WORK
81          AuxiliaryCache<String, String> result = factory.createCache(cattr, cacheMgr, cacheEventLogger, elementSerializer);
82  
83          // VEIFY
84          assertNotNull( "Should have a cache.", result );
85      }
86  }