1   /*    Open Source Java Caching Service
2   *    Copyright (C) 2002 Frank Karlstrøm
3   *    This library is free software; you can redistribute it and/or
4   *    modify it under the terms of the GNU Lesser General Public
5   *    License as published by the Free Software Foundation; either
6   *    version 2.1 of the License, or (at your option) any later version.
7   *
8   *    This library is distributed in the hope that it will be useful,
9   *    but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  *    Lesser General Public License for more details.
12  *
13  *    You should have received a copy of the GNU Lesser General Public
14  *    License along with this library; if not, write to the Free Software
15  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  *
17  *    The author can be contacted by email: fjankk@users.sourceforge.net
18  */
19  import java.util.Map;
20  import javax.util.jcache.Cache;
21  import javax.util.jcache.CacheAccessFactory;
22  import javax.util.jcache.CacheAttributes;
23  import junit.framework.TestCase;
24  /***
25   * Test to reproduce bug 974609. 
26   * @author Frank Karlstrøm
27   *
28   */
29  public class Bug974609_1  extends TestCase {
30  	/***
31  	 * Tests the maxObjects. Sets the maximum number of objects to 5, 
32  	 * then tries to insert six. 
33  	 * @throws Exception if any faults occurs.
34  	 */
35      final public void testSetMaxObjects() throws Exception {
36          CacheAttributes ca = CacheAttributes.getDefaultCacheAttributes();
37          ca.setMaxObjects(5);
38          ca.setLocal();
39          CacheAccessFactory factory = CacheAccessFactory.getInstance();
40          Cache cache = factory.getCache();
41          cache.close();
42          cache.init(ca);
43          Map map = factory.getMapAccess();
44          int max=5;
45          for(int i=0; i<max; i++) {
46              map.put(""+i, new Object());
47          }
48          //now it should be full.
49          try {
50              map.put("oi", new Object());
51              fail("MaxObjects was "+max+" but we managed to put "+(max+1)+".");
52          }catch(IllegalArgumentException e) {
53              //this is good.
54          }
55      }
56      
57  }