Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 103   Methods: 2
NCLOC: 60   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
LifecycleNotificationTest.java 75% 100% 100% 97.1%
coverage 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 java.util.LinkedList;
 26    import java.util.List;
 27   
 28    import javax.management.AttributeChangeNotification;
 29    import javax.management.Notification;
 30    import javax.management.NotificationListener;
 31   
 32    /**
 33    * A LifecycleNotificationTest.
 34    *
 35    * @author <a href="brian.stansberry@jboss.com">Brian Stansberry</a>
 36    * @version $Revision: 1.1 $
 37    */
 38    public class LifecycleNotificationTest extends CacheJmxWrapperTestBase
 39    {
 40   
 41  1 public void testGetStateAndStateNotification() throws Exception
 42    {
 43  1 CacheJmxWrapper wrapper = createWrapper(createConfiguration());
 44  1 StateNotificationListener listener = new StateNotificationListener();
 45  1 wrapper.addNotificationListener(listener, null, null);
 46   
 47  1 assertEquals("Correct state after instanitation",
 48    CacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
 49   
 50  1 registerWrapper(wrapper);
 51  1 assertEquals("Correct state after registration",
 52    CacheJmxWrapperMBean.REGISTERED, wrapper.getState());
 53   
 54  1 wrapper.create();
 55  1 assertEquals("Correct state after create",
 56    CacheJmxWrapperMBean.CREATED, wrapper.getState());
 57   
 58  1 wrapper.start();
 59  1 assertEquals("Correct state after start",
 60    CacheJmxWrapperMBean.STARTED, wrapper.getState());
 61   
 62  1 wrapper.stop();
 63  1 assertEquals("Correct state after stop",
 64    CacheJmxWrapperMBean.STOPPED, wrapper.getState());
 65   
 66  1 wrapper.destroy();
 67  1 assertEquals("Correct state after destroy",
 68    CacheJmxWrapperMBean.DESTROYED, wrapper.getState());
 69   
 70  1 unregisterWrapper();
 71  1 assertEquals("Correct state after unregistration",
 72    CacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
 73   
 74  1 System.out.println(listener.notifications);
 75  1 assertEquals("Correct number of notifications received", 4, listener.notifications.size());
 76  1 assertEquals("Correct first notification", new Integer(CacheJmxWrapperMBean.STARTING), listener.notifications.get(0));
 77  1 assertEquals("Correct second notification", new Integer(CacheJmxWrapperMBean.STARTED), listener.notifications.get(1));
 78  1 assertEquals("Correct third notification", new Integer(CacheJmxWrapperMBean.STOPPING), listener.notifications.get(2));
 79  1 assertEquals("Correct fourth notification", new Integer(CacheJmxWrapperMBean.STOPPED), listener.notifications.get(3));
 80    }
 81   
 82    private static class StateNotificationListener
 83    implements NotificationListener
 84    {
 85    private List<Integer> notifications = new LinkedList<Integer>();
 86   
 87  6 public void handleNotification(Notification msg, Object handback)
 88    {
 89  6 if (msg instanceof AttributeChangeNotification)
 90    {
 91  4 AttributeChangeNotification change = (AttributeChangeNotification) msg;
 92  4 String attrName = change.getAttributeName();
 93  4 Object newValue = change.getNewValue();
 94  4 if ("State".equals(attrName) && newValue != null && newValue instanceof Integer)
 95    {
 96  4 notifications.add((Integer) newValue);
 97  4 return;
 98    }
 99    }
 100    }
 101    }
 102   
 103    }