1   package org.apache.jcs;
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.Test;
23  import junit.framework.TestCase;
24  import junit.framework.TestSuite;
25  
26  import org.apache.jcs.JCS;
27  
28  import java.util.LinkedList;
29  import java.util.HashMap;
30  import java.util.Random;
31  
32  /***
33   * Simple test for the JCS class.
34   *
35   * @version $Id: JCSUniTest.java 536904 2007-05-10 16:03:42Z tv $
36   */
37  public class JCSUniTest
38      extends TestCase
39  {
40      Random random = new Random();
41  
42      /***
43       * @param testName
44       */
45      public JCSUniTest( String testName )
46      {
47          super( testName );
48      }
49  
50      /***
51       * @return Test
52       */
53      public static Test suite()
54      {
55          return new TestSuite( JCSUniTest.class );
56      }
57  
58      /***
59       * @param args
60       */
61      public static void main( String args[] )
62      {
63          String[] testCaseName = { JCSUniTest.class.getName() };
64          junit.textui.TestRunner.main( testCaseName );
65      }
66  
67      /***
68       * @throws Exception
69       */
70      public void testJCS()
71          throws Exception
72      {
73          JCS jcs = JCS.getInstance( "testCache1" );
74  
75          LinkedList list = buildList();
76  
77          jcs.put( "some:key", list );
78  
79          assertEquals( list, jcs.get( "some:key" ) );
80      }
81  
82      private LinkedList buildList()
83      {
84          LinkedList list = new LinkedList();
85  
86          for ( int i = 0; i < 100; i++ )
87          {
88              list.add( buildMap() );
89          }
90  
91          return list;
92      }
93  
94      private HashMap buildMap()
95      {
96          HashMap map = new HashMap();
97  
98          byte[] keyBytes = new byte[32];
99          byte[] valBytes = new byte[128];
100 
101         for ( int i = 0; i < 10; i++ )
102         {
103             random.nextBytes( keyBytes );
104             random.nextBytes( valBytes );
105 
106             map.put( new String( keyBytes ), new String( valBytes ) );
107         }
108 
109         return map;
110     }
111 
112 }