Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 383   Methods: 11
NCLOC: 162   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InterceptorRegistrationTest.java - 100% 100% 100%
coverage
 1    /*
 2    * JBoss, Home of Professional Open Source.
 3    * Copyright 2006, Red Hat Middleware LLC, and individual contributors
 4    * as indicated by the @author tags. See the copyright.txt file in the
 5    * distribution for a full listing of individual contributors.
 6    *
 7    * This is free software; you can redistribute it and/or modify it
 8    * under the terms of the GNU Lesser General Public License as
 9    * published by the Free Software Foundation; either version 2.1 of
 10    * the License, or (at your option) any later version.
 11    *
 12    * This software is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15    * Lesser General Public License for more details.
 16    *
 17    * You should have received a copy of the GNU Lesser General Public
 18    * License along with this software; if not, write to the Free
 19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21    */
 22   
 23    package org.jboss.cache.jmx;
 24   
 25    import org.jboss.cache.config.Configuration;
 26   
 27    /**
 28    * Tests the interceptor registration function of CacheJmxWrapper.
 29    *
 30    * @author <a href="brian.stansberry@jboss.com">Brian Stansberry</a>
 31    * @version $Revision: 1.2 $
 32    */
 33    public class InterceptorRegistrationTest extends CacheJmxWrapperTestBase
 34    {
 35   
 36    /**
 37    * Confirms interceptor mbeans are registered if the following events
 38    * occur:
 39    *
 40    * cache.start();
 41    * wrapper creation and registration.
 42    *
 43    * @throws Exception
 44    */
 45  1 public void testInterceptorMBeans1() throws Exception
 46    {
 47    // have to start the cache to have any interceptors
 48  1 createCache(createConfiguration());
 49  1 cache.start();
 50   
 51  1 CacheJmxWrapperMBean wrapper = registerWrapper(cache);
 52  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 53   
 54  1 interceptorRegistrationTest(true);
 55   
 56    // These should be ignored because we
 57    // never did wrapper.create()/start()
 58  1 wrapper.stop();
 59  1 wrapper.destroy();
 60   
 61    // Should still be registered
 62  1 interceptorRegistrationTest(true);
 63   
 64  1 unregisterWrapper();
 65   
 66  1 interceptorRegistrationTest(false);
 67    }
 68   
 69    /**
 70    * Confirms interceptor mbeans are registered if the following events
 71    * occur:
 72    *
 73    * cache.start();
 74    * wrapper creation and and start
 75    * wrapper registration.
 76    *
 77    * @throws Exception
 78    */
 79  1 public void testInterceptorMBeans2() throws Exception
 80    {
 81    // have to start the cache to have any interceptors
 82  1 createCache(createConfiguration());
 83  1 cache.start();
 84   
 85  1 CacheJmxWrapperMBean wrapper = new CacheJmxWrapper(cache);
 86  1 wrapper.start();
 87  1 wrapper = registerWrapper(wrapper);
 88  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 89   
 90  1 interceptorRegistrationTest(true);
 91   
 92  1 wrapper.stop();
 93  1 wrapper.destroy();
 94   
 95    // Should still no longer be registered
 96  1 interceptorRegistrationTest(false);
 97   
 98  1 unregisterWrapper();
 99   
 100  1 interceptorRegistrationTest(false);
 101    }
 102   
 103    /**
 104    * Confirms interceptor mbeans are registered if the following events
 105    * occur:
 106    *
 107    * Cache not injected
 108    * wrapper registered;
 109    * wrapper created and started.
 110    *
 111    * @throws Exception
 112    */
 113  1 public void testInterceptorMBeans3() throws Exception
 114    {
 115  1 CacheJmxWrapperMBean wrapper = registerWrapper(createConfiguration());
 116  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 117   
 118    // have to start the cache to have any interceptors
 119  1 wrapper.create();
 120  1 wrapper.start();
 121   
 122  1 interceptorRegistrationTest(true);
 123   
 124  1 wrapper.stop();
 125  1 wrapper.destroy();
 126   
 127    // Destroy should unregister if we are managing
 128  1 interceptorRegistrationTest(false);
 129   
 130  1 unregisterWrapper();
 131   
 132  1 interceptorRegistrationTest(false);
 133    }
 134   
 135    /**
 136    * Confirms interceptor mbeans are registered if the following events
 137    * occur:
 138    *
 139    * Cache not injected
 140    * wrapper created and started.
 141    * wrapper registered
 142    *
 143    * @throws Exception
 144    */
 145  1 public void testInterceptorMBeans4() throws Exception
 146    {
 147  1 CacheJmxWrapper wrapper = createWrapper(createConfiguration());
 148   
 149    // have to start the cache to have any interceptors
 150  1 wrapper.create();
 151  1 wrapper.start();
 152   
 153  1 registerWrapper(wrapper);
 154   
 155  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 156   
 157  1 interceptorRegistrationTest(true);
 158   
 159  1 wrapper.stop();
 160  1 wrapper.destroy();
 161   
 162    // Destroy should unregister if we are managing
 163  1 interceptorRegistrationTest(false);
 164   
 165  1 unregisterWrapper();
 166   
 167  1 interceptorRegistrationTest(false);
 168    }
 169   
 170    /**
 171    * Confirms interceptor mbeans are registered if the following events
 172    * occur:
 173    *
 174    * cache constructed;
 175    * wrapper constructed and registered with manageCacheLifecycle=true
 176    * wrapper created and started
 177    *
 178    * @throws Exception
 179    */
 180  1 public void testInterceptorMBeans5() throws Exception
 181    {
 182  1 CacheJmxWrapperMBean wrapper = registerWrapper();
 183    // wrapper.setManageCacheLifecycle(true);
 184  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 185   
 186    // have to start the cache to have any interceptors
 187  1 wrapper.create();
 188  1 wrapper.start();
 189   
 190  1 interceptorRegistrationTest(true);
 191   
 192  1 wrapper.stop();
 193  1 wrapper.destroy();
 194   
 195    // Destroy should unregister if we are managing
 196  1 interceptorRegistrationTest(false);
 197   
 198  1 unregisterWrapper();
 199   
 200  1 interceptorRegistrationTest(false);
 201    }
 202   
 203    /**
 204    * Confirms interceptor mbeans are registered if the following events
 205    * occur:
 206    *
 207    * cache constructed;
 208    * wrapper constructed and registered
 209    * wrapper created and started
 210    *
 211    * @throws Exception
 212    */
 213  1 public void testInterceptorMBeans6() throws Exception
 214    {
 215  1 CacheJmxWrapperMBean wrapper = registerWrapper();
 216  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 217   
 218    // have to start the cache to have any interceptors
 219  1 wrapper.create();
 220  1 wrapper.start();
 221   
 222  1 interceptorRegistrationTest(true);
 223   
 224  1 wrapper.stop();
 225  1 wrapper.destroy();
 226   
 227  1 interceptorRegistrationTest(false);
 228   
 229  1 unregisterWrapper();
 230   
 231  1 interceptorRegistrationTest(false);
 232    }
 233   
 234    /**
 235    * Confirms interceptor mbeans are registered if the following events
 236    * occur:
 237    *
 238    * cache constructed;
 239    * wrapper created and started
 240    * wrapper registered
 241    *
 242    * @throws Exception
 243    */
 244  1 public void testInterceptorMBeans7() throws Exception
 245    {
 246  1 CacheJmxWrapperMBean wrapper = new CacheJmxWrapper(createCache(createConfiguration()));
 247   
 248    // have to start the cache to have any interceptors
 249  1 wrapper.create();
 250  1 wrapper.start();
 251   
 252  1 wrapper = registerWrapper(wrapper);
 253  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 254   
 255  1 interceptorRegistrationTest(true);
 256   
 257  1 wrapper.stop();
 258  1 wrapper.destroy();
 259   
 260  1 interceptorRegistrationTest(false);
 261   
 262  1 unregisterWrapper();
 263   
 264  1 interceptorRegistrationTest(false);
 265    }
 266   
 267    /**
 268    * Tests that setting registerInterceptors=false disables interceptor
 269    * registration when the wrapper is registered before create/start
 270    * are called.
 271    *
 272    * @throws Exception
 273    */
 274  1 public void testRegisterInterceptors1() throws Exception
 275    {
 276  1 CacheJmxWrapper wrapper = createWrapper(createConfiguration());
 277  1 wrapper.setRegisterInterceptors(false);
 278   
 279  1 registerWrapper(wrapper);
 280   
 281  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 282   
 283  1 wrapper.create();
 284  1 wrapper.start();
 285   
 286  1 interceptorRegistrationTest(false);
 287   
 288  1 wrapper.stop();
 289  1 wrapper.destroy();
 290   
 291  1 interceptorRegistrationTest(false);
 292   
 293  1 unregisterWrapper();
 294   
 295  1 interceptorRegistrationTest(false);
 296    }
 297   
 298    /**
 299    * Tests that setting registerInterceptors=false disables interceptor
 300    * registration when the wrapper is registered after create/start
 301    * are called.
 302    *
 303    * @throws Exception
 304    */
 305  1 public void testRegisterInterceptors2() throws Exception
 306    {
 307  1 CacheJmxWrapper wrapper = createWrapper(createConfiguration());
 308  1 wrapper.setRegisterInterceptors(false);
 309   
 310  1 wrapper.create();
 311  1 wrapper.start();
 312   
 313  1 registerWrapper(wrapper);
 314   
 315  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 316   
 317  1 interceptorRegistrationTest(false);
 318   
 319  1 wrapper.stop();
 320  1 wrapper.destroy();
 321   
 322  1 interceptorRegistrationTest(false);
 323   
 324  1 unregisterWrapper();
 325   
 326  1 interceptorRegistrationTest(false);
 327    }
 328   
 329  1 public void testExposeManagementStatistics1() throws Exception
 330    {
 331  1 Configuration cfg = createConfiguration();
 332  1 cfg.setExposeManagementStatistics(false);
 333   
 334  1 CacheJmxWrapper wrapper = createWrapper(cfg);
 335  1 registerWrapper(cfg);
 336   
 337  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 338   
 339  1 wrapper.create();
 340  1 wrapper.start();
 341   
 342  1 interceptorRegistrationTest(false);
 343   
 344  1 wrapper.stop();
 345  1 wrapper.destroy();
 346   
 347  1 interceptorRegistrationTest(false);
 348   
 349  1 unregisterWrapper();
 350   
 351  1 interceptorRegistrationTest(false);
 352    }
 353   
 354  1 public void testExposeManagementStatistics2() throws Exception
 355    {
 356  1 Configuration cfg = createConfiguration();
 357  1 cfg.setExposeManagementStatistics(false);
 358   
 359  1 CacheJmxWrapper wrapper = createWrapper(cfg);
 360   
 361  1 wrapper.create();
 362  1 wrapper.start();
 363   
 364  1 registerWrapper(wrapper);
 365   
 366  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 367   
 368  1 interceptorRegistrationTest(false);
 369   
 370  1 wrapper.stop();
 371  1 wrapper.destroy();
 372   
 373  1 interceptorRegistrationTest(false);
 374   
 375  1 unregisterWrapper();
 376   
 377  1 interceptorRegistrationTest(false);
 378   
 379    }
 380   
 381   
 382   
 383    }