View Javadoc

1   /*
2    * $Id: JmxDuplicateEndpointNamesTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.management;
12  
13  import org.mule.tck.FunctionalTestCase;
14  
15  import java.util.ArrayList;
16  import java.util.List;
17  import java.util.Set;
18  
19  import javax.management.MBeanServer;
20  import javax.management.MBeanServerFactory;
21  import javax.management.ObjectInstance;
22  import javax.management.ObjectName;
23  
24  public class JmxDuplicateEndpointNamesTestCase extends FunctionalTestCase
25  {
26      private List<ObjectInstance> endpointMBeans = new ArrayList<ObjectInstance>();
27      
28      @Override
29      protected String getConfigResources()
30      {
31          return "duplicate-endpoint-addesses.xml";
32      }
33  
34      public void testDuplicateNames()
35      {
36          List<?> mBeanServers = MBeanServerFactory.findMBeanServer(null);
37          assertTrue("no local MBean server found", mBeanServers.size() > 0);        
38          
39          inspectMBeanServers(mBeanServers);
40          assertEquals(2, endpointMBeans.size());
41      }
42  
43      private void inspectMBeanServers(List<?> mBeanServers)
44      {
45          for (Object o : mBeanServers)
46          {
47              MBeanServer server = (MBeanServer) o;
48              
49              Set<?> mBeans = server.queryMBeans(null, null);
50              assertTrue("no registered MBeans found", mBeans.size() > 0);
51              
52              inspectMBeans(mBeans);
53          }
54      }
55  
56      private void inspectMBeans(Set<?> mBeans)
57      {
58          for (Object o : mBeans)
59          {
60              ObjectInstance instance = (ObjectInstance) o;
61              if (objectNameMatches(instance))
62              {
63                  endpointMBeans.add(instance);
64              }
65          }
66      }
67  
68      private boolean objectNameMatches(ObjectInstance instance)
69      {
70          ObjectName name = instance.getObjectName();
71          return name.getCanonicalName().contains("vmInbound");    
72      }
73  }
74  
75