View Javadoc
1   package org.apache.commons.jcs.auxiliary.disk;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  import org.apache.commons.jcs.engine.CacheElement;
24  import org.apache.commons.jcs.engine.ElementAttributes;
25  import org.apache.commons.jcs.engine.behavior.ICacheElement;
26  import org.apache.commons.jcs.engine.behavior.IElementAttributes;
27  
28  /** Simple unit tests for the Purgatory Element. */
29  public class PurgatoryElementUnitTest
30      extends TestCase
31  {
32      /** Verify basic data */
33      public void testSpoolable_normal()
34      {
35          // SETUP
36          String cacheName = "myCacheName";
37          String key = "myKey";
38          String value = "myValue";
39          IElementAttributes elementAttributes = new ElementAttributes();
40          ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes );
41          PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement );
42          purgatoryElement.setSpoolable( false );
43  
44          // DO WORK
45          boolean result = purgatoryElement.isSpoolable();
46  
47          // VERIFY
48          assertFalse( "Should not be spoolable.", result );
49      }
50  
51      /** Verify basic data */
52      public void testElementAttributes_normal()
53      {
54          // SETUP
55          String cacheName = "myCacheName";
56          String key = "myKey";
57          String value = "myValue";
58          IElementAttributes elementAttributes = new ElementAttributes();
59  
60          ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value );
61          PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement );
62          purgatoryElement.setElementAttributes( elementAttributes );
63  
64          // DO WORK
65          IElementAttributes result = cacheElement.getElementAttributes();
66  
67          // VERIFY
68          assertEquals( "Should have set the attributes on the element", elementAttributes, result );
69      }
70  
71      /** Verify basic data */
72      public void testToString_normal()
73      {
74          // SETUP
75          String cacheName = "myCacheName";
76          String key = "myKey";
77          String value = "myValue";
78          IElementAttributes elementAttributes = new ElementAttributes();
79          ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes );
80          PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement );
81  
82          // DO WORK
83          String result = purgatoryElement.toString();
84  
85          // VERIFY
86          assertTrue( "Should have the cacheName.", result.indexOf( cacheName ) != -1 );
87          assertTrue( "Should have the key.", result.indexOf( key ) != -1 );
88          assertTrue( "Should have the value.", result.indexOf( value ) != -1 );
89      }
90  }