Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 446   Methods: 13
NCLOC: 195   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.pojo.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.3 $
 32    */
 33    public class InterceptorRegistrationTest extends PojoCacheJmxWrapperTestBase
 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 PojoCacheJmxWrapperMBean wrapper = registerWrapper(cache);
 52  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 53   
 54  1 interceptorRegistrationTest(true);
 55   
 56  1 wrapper.stop();
 57  1 wrapper.destroy();
 58   
 59    // Should still be registered
 60  1 interceptorRegistrationTest(true);
 61   
 62  1 unregisterWrapper();
 63   
 64  1 interceptorRegistrationTest(false);
 65    }
 66   
 67    /**
 68    * Confirms interceptor mbeans are registered if the following events
 69    * occur:
 70    *
 71    * cache.start();
 72    * wrapper creation and and start
 73    * wrapper registration.
 74    *
 75    * @throws Exception
 76    */
 77  1 public void testInterceptorMBeans2() throws Exception
 78    {
 79    // have to start the cache to have any interceptors
 80  1 createCache(createConfiguration());
 81  1 cache.start();
 82   
 83  1 PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(cache);
 84  1 wrapper.start();
 85  1 wrapper = registerWrapper(wrapper);
 86  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 87   
 88  1 interceptorRegistrationTest(true);
 89   
 90  1 wrapper.stop();
 91  1 wrapper.destroy();
 92   
 93    // Should still be registered
 94  1 interceptorRegistrationTest(false);
 95   
 96  1 unregisterWrapper();
 97   
 98  1 interceptorRegistrationTest(false);
 99    }
 100   
 101    /**
 102    * Confirms interceptor mbeans are registered if the following events
 103    * occur:
 104    *
 105    * Cache not injected
 106    * wrapper registered;
 107    * wrapper created and started.
 108    *
 109    * @throws Exception
 110    */
 111  1 public void testInterceptorMBeans3() throws Exception
 112    {
 113  1 PojoCacheJmxWrapperMBean wrapper = registerWrapper(createConfiguration());
 114  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 115   
 116    // have to start the cache to have any interceptors
 117  1 wrapper.create();
 118  1 wrapper.start();
 119   
 120  1 interceptorRegistrationTest(true);
 121   
 122  1 wrapper.stop();
 123  1 wrapper.destroy();
 124   
 125    // Destroy should unregister if we are managing
 126  1 interceptorRegistrationTest(false);
 127   
 128  1 unregisterWrapper();
 129   
 130  1 interceptorRegistrationTest(false);
 131    }
 132   
 133    /**
 134    * Confirms interceptor mbeans are registered if the following events
 135    * occur:
 136    *
 137    * Cache not injected
 138    * wrapper created and started.
 139    * wrapper registered
 140    *
 141    * @throws Exception
 142    */
 143  1 public void testInterceptorMBeans4() throws Exception
 144    {
 145  1 PojoCacheJmxWrapper wrapper = createWrapper(createConfiguration());
 146   
 147    // have to start the cache to have any interceptors
 148  1 wrapper.create();
 149  1 wrapper.start();
 150   
 151  1 registerWrapper(wrapper);
 152   
 153  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 154   
 155  1 interceptorRegistrationTest(true);
 156   
 157  1 wrapper.stop();
 158  1 wrapper.destroy();
 159   
 160    // Destroy should unregister if we are managing
 161  1 interceptorRegistrationTest(false);
 162   
 163  1 unregisterWrapper();
 164   
 165  1 interceptorRegistrationTest(false);
 166    }
 167   
 168    /**
 169    * Confirms interceptor mbeans are registered if the following events
 170    * occur:
 171    *
 172    * cache constructed;
 173    * wrapper constructed and registered with manageCacheLifecycle=true
 174    * wrapper created and started
 175    *
 176    * @throws Exception
 177    */
 178  1 public void testInterceptorMBeans5() throws Exception
 179    {
 180  1 PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(createCache(createConfiguration()));
 181    // wrapper.setManageCacheLifecycle(true);
 182  1 wrapper = registerWrapper(wrapper);
 183  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 184   
 185    // have to start the cache to have any interceptors
 186  1 wrapper.create();
 187  1 wrapper.start();
 188   
 189  1 interceptorRegistrationTest(true);
 190   
 191  1 wrapper.stop();
 192  1 wrapper.destroy();
 193   
 194    // Destroy should unregister if we are managing
 195  1 interceptorRegistrationTest(false);
 196   
 197  1 unregisterWrapper();
 198   
 199  1 interceptorRegistrationTest(false);
 200    }
 201   
 202    /**
 203    * Confirms interceptor mbeans are registered if the following events
 204    * occur:
 205    *
 206    * cache constructed;
 207    * wrapper constructed and registered
 208    * wrapper created and started
 209    *
 210    * @throws Exception
 211    */
 212  1 public void testInterceptorMBeans6() throws Exception
 213    {
 214  1 PojoCacheJmxWrapperMBean wrapper = registerWrapper();
 215  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 216   
 217    // have to start the cache to have any interceptors
 218  1 wrapper.create();
 219  1 wrapper.start();
 220   
 221  1 interceptorRegistrationTest(true);
 222   
 223  1 wrapper.stop();
 224  1 wrapper.destroy();
 225   
 226  1 interceptorRegistrationTest(false);
 227   
 228  1 unregisterWrapper();
 229   
 230  1 interceptorRegistrationTest(false);
 231    }
 232   
 233    /**
 234    * Confirms interceptor mbeans are registered if the following events
 235    * occur:
 236    *
 237    * cache constructed;
 238    * wrapper created and started
 239    * wrapper registered
 240    *
 241    * @throws Exception
 242    */
 243  1 public void testInterceptorMBeans7() throws Exception
 244    {
 245  1 PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(createCache(createConfiguration()));
 246   
 247    // have to start the cache to have any interceptors
 248  1 wrapper.create();
 249  1 wrapper.start();
 250   
 251  1 wrapper = registerWrapper(wrapper);
 252  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 253   
 254  1 interceptorRegistrationTest(true);
 255   
 256  1 wrapper.stop();
 257  1 wrapper.destroy();
 258   
 259  1 interceptorRegistrationTest(false);
 260   
 261  1 unregisterWrapper();
 262   
 263  1 interceptorRegistrationTest(false);
 264    }
 265   
 266    /**
 267    * Tests that setting registerInterceptors=false disables interceptor
 268    * registration when the wrapper is registered before create/start
 269    * are called.
 270    *
 271    * @throws Exception
 272    */
 273  1 public void testRegisterInterceptors1() throws Exception
 274    {
 275  1 PojoCacheJmxWrapper wrapper = createWrapper(createConfiguration());
 276  1 wrapper.setRegisterInterceptors(false);
 277   
 278  1 registerWrapper(wrapper);
 279   
 280  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 281   
 282  1 wrapper.create();
 283  1 wrapper.start();
 284   
 285  1 interceptorRegistrationTest(false);
 286   
 287  1 wrapper.stop();
 288  1 wrapper.destroy();
 289   
 290  1 interceptorRegistrationTest(false);
 291   
 292  1 unregisterWrapper();
 293   
 294  1 interceptorRegistrationTest(false);
 295    }
 296   
 297    /**
 298    * Tests that setting registerInterceptors=false disables interceptor
 299    * registration when the wrapper is registered after create/start
 300    * are called.
 301    *
 302    * @throws Exception
 303    */
 304  1 public void testRegisterInterceptors2() throws Exception
 305    {
 306  1 PojoCacheJmxWrapper wrapper = createWrapper(createConfiguration());
 307  1 wrapper.setRegisterInterceptors(false);
 308   
 309  1 wrapper.create();
 310  1 wrapper.start();
 311   
 312  1 registerWrapper(wrapper);
 313   
 314  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 315   
 316  1 interceptorRegistrationTest(false);
 317   
 318  1 wrapper.stop();
 319  1 wrapper.destroy();
 320   
 321  1 interceptorRegistrationTest(false);
 322   
 323  1 unregisterWrapper();
 324   
 325  1 interceptorRegistrationTest(false);
 326    }
 327   
 328    /**
 329    * Tests that setting registerPlainCache=false disables interceptor
 330    * registration when the wrapper is registered before create/start
 331    * are called.
 332    *
 333    * @throws Exception
 334    */
 335  1 public void testRegisterPlainCache1() throws Exception
 336    {
 337  1 PojoCacheJmxWrapper wrapper = createWrapper(createConfiguration());
 338  1 wrapper.setRegisterPlainCache(false);
 339  1 wrapper.setRegisterInterceptors(true);
 340   
 341  1 registerWrapper(wrapper);
 342   
 343  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 344   
 345  1 wrapper.create();
 346  1 wrapper.start();
 347   
 348  1 interceptorRegistrationTest(false);
 349   
 350  1 wrapper.stop();
 351  1 wrapper.destroy();
 352   
 353  1 interceptorRegistrationTest(false);
 354   
 355  1 unregisterWrapper();
 356   
 357  1 interceptorRegistrationTest(false);
 358    }
 359   
 360    /**
 361    * Tests that setting registerPlainCache=false disables interceptor
 362    * registration when the wrapper is registered after create/start
 363    * are called.
 364    *
 365    * @throws Exception
 366    */
 367  1 public void testRegisterPlainCache2() throws Exception
 368    {
 369  1 PojoCacheJmxWrapper wrapper = createWrapper(createConfiguration());
 370  1 wrapper.setRegisterPlainCache(false);
 371  1 wrapper.setRegisterInterceptors(true);
 372   
 373  1 wrapper.create();
 374  1 wrapper.start();
 375   
 376  1 registerWrapper(wrapper);
 377   
 378  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 379   
 380  1 interceptorRegistrationTest(false);
 381   
 382  1 wrapper.stop();
 383  1 wrapper.destroy();
 384   
 385  1 interceptorRegistrationTest(false);
 386   
 387  1 unregisterWrapper();
 388   
 389  1 interceptorRegistrationTest(false);
 390    }
 391   
 392  1 public void testExposeManagementStatistics1() throws Exception
 393    {
 394  1 Configuration cfg = createConfiguration();
 395  1 cfg.setExposeManagementStatistics(false);
 396   
 397  1 PojoCacheJmxWrapper wrapper = createWrapper(cfg);
 398  1 registerWrapper(cfg);
 399   
 400  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 401   
 402  1 wrapper.create();
 403  1 wrapper.start();
 404   
 405  1 interceptorRegistrationTest(false);
 406   
 407  1 wrapper.stop();
 408  1 wrapper.destroy();
 409   
 410  1 interceptorRegistrationTest(false);
 411   
 412  1 unregisterWrapper();
 413   
 414  1 interceptorRegistrationTest(false);
 415    }
 416   
 417  1 public void testExposeManagementStatistics2() throws Exception
 418    {
 419  1 Configuration cfg = createConfiguration();
 420  1 cfg.setExposeManagementStatistics(false);
 421   
 422  1 PojoCacheJmxWrapper wrapper = createWrapper(cfg);
 423   
 424  1 wrapper.create();
 425  1 wrapper.start();
 426   
 427  1 registerWrapper(wrapper);
 428   
 429  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 430   
 431  1 interceptorRegistrationTest(false);
 432   
 433  1 wrapper.stop();
 434  1 wrapper.destroy();
 435   
 436  1 interceptorRegistrationTest(false);
 437   
 438  1 unregisterWrapper();
 439   
 440  1 interceptorRegistrationTest(false);
 441   
 442    }
 443   
 444   
 445   
 446    }