Coverage Report - org.kuali.rice.core.impl.mocks.RiceCacheAdministratorMock
 
Classes in this File Line Coverage Branch Coverage Complexity
RiceCacheAdministratorMock
82%
28/34
66%
12/18
0
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.core.impl.mocks
 17  
 
 18  
 import org.kuali.rice.ksb.cache.RiceCacheAdministrator;
 19  
 
 20  
 /**
 21  
  * A simple mock for the {@link RiceCacheAdministrator} which uses a Map-based backend.
 22  
  * 
 23  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 24  
  *
 25  
  */
 26  
 class RiceCacheAdministratorMock implements RiceCacheAdministrator {
 27  
 
 28  7
         Map<String, Object> cache = new HashMap<String, Object>();
 29  7
         Map<String, Set<String>> keyToGroupMap = new HashMap<String, Set<String>>();
 30  7
         Map<String, Set<String>> groupToKeyMap = new HashMap<String, Set<String>>();
 31  
         
 32  
         @Override
 33  
         public void start() throws Exception {}
 34  
 
 35  
         @Override
 36  
         public void stop() throws Exception {}
 37  
 
 38  
         @Override
 39  
         public boolean isStarted() {
 40  0
                 return true;
 41  
         }
 42  
 
 43  
         @Override
 44  
         public synchronized Object getFromCache(String key) {
 45  0
                 return cache.get(key);
 46  
         }
 47  
 
 48  
         @Override
 49  
         public synchronized void putInCache(String key, Object content, String[] groups) {
 50  1
                 cache.put(key, content);
 51  1
                 if (groups != null && groups.length > 0) {
 52  1
                         synchronized (keyToGroupMap) {
 53  1
                                 Set<String> currentGroups = keyToGroupMap.get(key);
 54  1
                                 if (currentGroups == null) {
 55  1
                                         currentGroups = new HashSet<String>();
 56  1
                                         keyToGroupMap.put(key, currentGroups);
 57  
                                 }
 58  1
                                 for (String group : groups) {
 59  1
                                         currentGroups.add(group);
 60  1
                                         Set<String> currentGroupKeys = groupToKeyMap.get(group);
 61  1
                                         if (currentGroupKeys == null) {
 62  1
                                                 currentGroupKeys = new HashSet<String>();
 63  1
                                                 groupToKeyMap.put(group, currentGroupKeys);
 64  
                                         }
 65  1
                                         currentGroupKeys.add(key);
 66  
                                 }
 67  
                         }
 68  
                 }
 69  
         }
 70  
 
 71  
         @Override
 72  
         public synchronized void putInCache(String key, Object content, String group) {
 73  1
                 if (group != null) {
 74  1
                         putInCache(key, content, [ group ] as String[]);
 75  
                 }
 76  
         }
 77  
 
 78  
         @Override
 79  
         public synchronized void putInCache(String key, Object content) {
 80  0
                 cache.put(key, content);
 81  
         }
 82  
 
 83  
         @Override
 84  
         public synchronized void flushEntry(String key) {
 85  1
                 cache.remove(key);
 86  1
                 keyToGroupMap.remove(key);
 87  
         }
 88  
 
 89  
         @Override
 90  
         public synchronized void flushGroup(String group) {
 91  2
                 Set<String> groupKeys = groupToKeyMap.get(group);
 92  2
                 if (groupKeys != null) {
 93  1
                         for (String groupKey : groupKeys) {
 94  1
                                 flushEntry(groupKey);
 95  
                         }
 96  
                 }
 97  2
                 groupToKeyMap.remove(group);
 98  
         }
 99  
 
 100  
         @Override
 101  
         public synchronized void flushAll() {
 102  0
                 cache.clear();
 103  0
                 keyToGroupMap.clear();
 104  0
                 groupToKeyMap.clear();
 105  
         }
 106  
 
 107  
         @Override
 108  
         public void setCacheCapacity(int capacity) {}
 109  
 
 110  
         @Override
 111  
         public void setForceRegistryRefresh(boolean forceRegistryRefresh) {}
 112  
         
 113  
         public boolean isEmpty() {
 114  3
                 return cache.isEmpty();
 115  
         }
 116  
         
 117  
         public int getSize() {
 118  1
                 return cache.size();
 119  
         }
 120  
 
 121  
 }