1 package org.apache.commons.jcs3.engine.control;
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 java.util.Properties;
23
24 import org.apache.commons.jcs3.auxiliary.AuxiliaryCache;
25 import org.apache.commons.jcs3.engine.CompositeCacheAttributes;
26 import org.apache.commons.jcs3.engine.ElementAttributes;
27 import org.apache.commons.jcs3.engine.behavior.ICompositeCacheManager;
28 import org.apache.commons.jcs3.engine.behavior.IShutdownObserver;
29
30 /** For testing. */
31 public class MockCompositeCacheManager
32 implements ICompositeCacheManager
33 {
34 /** The cache that was returned. */
35 private CompositeCache<?, ?> cache;
36
37 /** Properties with which this manager was configured. This is exposed for other managers. */
38 private Properties configurationProperties;
39
40 /**
41 * @param cacheName
42 * @return Returns a CompositeCache
43 */
44 @Override
45 @SuppressWarnings("unchecked")
46 public <K, V> CompositeCache<K, V> getCache( final String cacheName )
47 {
48 if ( cache == null )
49 {
50 // System.out.println( "Creating mock cache" );
51 final CompositeCache<K, V> newCache =
52 new CompositeCache<>( new CompositeCacheAttributes(), new ElementAttributes() );
53 this.setCache( newCache );
54 }
55
56 return (CompositeCache<K, V>)cache;
57 }
58
59 @Override
60 public <K, V> AuxiliaryCache<K, V> getAuxiliaryCache(final String auxName, final String cacheName)
61 {
62 return null;
63 }
64
65 /**
66 * @param cache The cache to set.
67 */
68 public void setCache( final CompositeCache<?, ?> cache )
69 {
70 this.cache = cache;
71 }
72
73 /**
74 * @return Returns the cache.
75 */
76 public CompositeCache<?, ?> getCache()
77 {
78 return cache;
79 }
80
81 /**
82 * This is exposed so other manager can get access to the props.
83 * <p>
84 * @param props
85 */
86 public void setConfigurationProperties( final Properties props )
87 {
88 this.configurationProperties = props;
89 }
90
91 /**
92 * This is exposed so other manager can get access to the props.
93 * <p>
94 * @return the configurationProperties
95 */
96 @Override
97 public Properties getConfigurationProperties()
98 {
99 return configurationProperties;
100 }
101
102 /** @return Mock */
103 @Override
104 public String getStats()
105 {
106 return "Mock";
107 }
108
109 /**
110 * @see org.apache.commons.jcs3.engine.behavior.IShutdownObservable#registerShutdownObserver(org.apache.commons.jcs3.engine.behavior.IShutdownObserver)
111 */
112 @Override
113 public void registerShutdownObserver(final IShutdownObserver observer)
114 {
115 // Do nothing
116 }
117
118 /**
119 * @see org.apache.commons.jcs3.engine.behavior.IShutdownObservable#deregisterShutdownObserver(org.apache.commons.jcs3.engine.behavior.IShutdownObserver)
120 */
121 @Override
122 public void deregisterShutdownObserver(final IShutdownObserver observer)
123 {
124 // Do nothing
125 }
126 }