View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.management.agents;
8   
9   import org.mule.module.management.agent.DefaultJmxSupportAgent;
10  import org.mule.module.management.agent.FixedHostRmiClientSocketFactory;
11  import org.mule.module.management.agent.JmxAgent;
12  import org.mule.tck.junit4.AbstractMuleContextTestCase;
13  
14  import java.util.Map;
15  
16  import javax.management.remote.rmi.RMIConnectorServer;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class DefaultJmxSupportAgentTestCase extends AbstractMuleContextTestCase
25  {
26      @Test
27      public void testHostPropertyEnablesClientSocketFactory () throws Exception
28      {
29          DefaultJmxSupportAgent agent = new DefaultJmxSupportAgent();
30          agent.setMuleContext(muleContext);
31          agent.setHost("127.0.0.1");
32          JmxAgent jmxAgent = agent.createJmxAgent();
33          Map props = jmxAgent.getConnectorServerProperties();
34          assertNotNull(props);
35          assertEquals("JMX ConnectorServer properties should've been merged",
36                       2, props.size());
37          assertTrue("Property shouldn't have been removed",
38                     props.containsKey(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE));
39          assertTrue("Property should've been added",
40                     props.containsKey(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE));
41          Object ref = props.get(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
42          assertNotNull(ref);
43          assertTrue(ref instanceof FixedHostRmiClientSocketFactory);
44      }
45  }