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