/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.test.jmx.test;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;

import org.apache.log4j.Logger;
import org.jboss.test.JBossTestCase;

/**
 * Tests for ListenerServiceMBeanSupport and filter factories.
 * 
 * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
 * @version $Revision: 1.1.2.2 $
 */
public class ListenerServiceMBeanUnitTestCase extends JBossTestCase
{
   public ListenerServiceMBeanUnitTestCase(String name)
   {
      super(name);
   }

   /**
    * [JBAS-1959] 
    */
   public void testDeploymentInfoNotificationFilterFactory() throws Exception
   {
      Logger log = getLog();
      log.info("+++ testDeploymentInfoNotificationFilterFactory");

      String listenerService = "listener-deploymentinfo.sar";
      String testService = "listener-simpletest.sar";
      
      try
      {
         ObjectName listener = new ObjectName("jboss.test:service=NotificationListener");         
         MBeanServerConnection server = super.getServer();
         Integer notifCount;
         
         // the "listenerService" is configured to intercept the
         // start and stop notification from SARDeployer, when
         // we deploy "targetService"
         deploy(listenerService);
         notifCount = (Integer)server.getAttribute(listener, "NotificationCount");
         assertTrue("NotifCount == 0, got " + notifCount.intValue(), notifCount.intValue() == 0);
         
         deploy(testService);
         notifCount = (Integer)server.getAttribute(listener, "NotificationCount");
         assertTrue("NotifCount == 1, got " + notifCount.intValue(), notifCount.intValue() == 1);
         
         undeploy(testService);
         notifCount = (Integer)server.getAttribute(listener, "NotificationCount");
         assertTrue("NotifCount == 2, got " + notifCount.intValue(), notifCount.intValue() == 2);         
      }
      catch (Exception e)
      {
         getLog().warn("Caught exception", e);
         fail("Unexcepted Exception, see the Log file");
      }
      finally
      {
         undeploy(testService);         
         undeploy(listenerService);
      }
   }   
}