[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/pojo/jmx ...

Brian Stansberry brian.stansberry at jboss.com
Fri Jun 29 00:08:19 EDT 2007


  User: bstansberry
  Date: 07/06/29 00:08:19

  Added:       tests/functional/org/jboss/cache/pojo/jmx 
                        LifecycleNotificationTest.java
  Log:
  [JBCACHE-1090] Emit JMX Notifications the JBAS JSR-77 layer expects
  
  Revision  Changes    Path
  1.1      date: 2007/06/29 04:08:19;  author: bstansberry;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/jmx/LifecycleNotificationTest.java
  
  Index: LifecycleNotificationTest.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  
  package org.jboss.cache.pojo.jmx;
  
  import java.util.LinkedList;
  import java.util.List;
  
  import javax.management.AttributeChangeNotification;
  import javax.management.Notification;
  import javax.management.NotificationListener;
  
  /**
   * A LifecycleNotificationTest.
   * 
   * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
   * @version $Revision: 1.1 $
   */
  public class LifecycleNotificationTest extends PojoCacheJmxWrapperTestBase
  {
     
     public void testGetStateAndStateNotification() throws Exception
     {
        PojoCacheJmxWrapper wrapper = createWrapper(createConfiguration());
        StateNotificationListener listener = new StateNotificationListener();
        wrapper.addNotificationListener(listener, null, null);
        
        assertEquals("Correct state after instanitation", 
                     PojoCacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
        
        registerWrapper(wrapper);
        assertEquals("Correct state after registration", 
              PojoCacheJmxWrapperMBean.REGISTERED, wrapper.getState());
        
        wrapper.create();
        assertEquals("Correct state after create", 
              PojoCacheJmxWrapperMBean.CREATED, wrapper.getState());
        
        wrapper.start();
        assertEquals("Correct state after start", 
              PojoCacheJmxWrapperMBean.STARTED, wrapper.getState());
        
        wrapper.stop();
        assertEquals("Correct state after stop", 
              PojoCacheJmxWrapperMBean.STOPPED, wrapper.getState());
        
        wrapper.destroy();
        assertEquals("Correct state after destroy", 
              PojoCacheJmxWrapperMBean.DESTROYED, wrapper.getState());
        
        unregisterWrapper();
        assertEquals("Correct state after unregistration", 
              PojoCacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
        
        System.out.println(listener.notifications);
        assertEquals("Correct number of notifications received", 4, listener.notifications.size());
        assertEquals("Correct first notification", new Integer(PojoCacheJmxWrapperMBean.STARTING), listener.notifications.get(0));
        assertEquals("Correct second notification", new Integer(PojoCacheJmxWrapperMBean.STARTED), listener.notifications.get(1));
        assertEquals("Correct third notification", new Integer(PojoCacheJmxWrapperMBean.STOPPING), listener.notifications.get(2));
        assertEquals("Correct fourth notification", new Integer(PojoCacheJmxWrapperMBean.STOPPED), listener.notifications.get(3));
     }
     
     private static class StateNotificationListener
           implements NotificationListener
     {
        private List<Integer> notifications = new LinkedList<Integer>();
        
        public void handleNotification(Notification msg, Object handback)
        {
           if (msg instanceof AttributeChangeNotification)
           {
              AttributeChangeNotification change = (AttributeChangeNotification) msg;
              String attrName = change.getAttributeName();
              Object newValue = change.getNewValue();
              if ("State".equals(attrName) && newValue != null && newValue instanceof Integer)
              {
                 notifications.add((Integer) newValue);
                 return;
              }
           }
        }
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list