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;
8   
9   import org.mule.module.management.agent.FixedHostRmiClientSocketFactory;
10  import org.mule.tck.junit4.FunctionalTestCase;
11  
12  import java.net.ConnectException;
13  import java.net.Socket;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.fail;
18  
19  public class JmxAgentDefaultConfigurationWithRMITestCase extends FunctionalTestCase
20  {
21  
22      @Override
23      protected String getConfigResources()
24      {
25          return "default-with-rmi-management-config.xml";
26      }
27  
28      @Test
29      public void testDefaultJmxAgent() throws Exception
30      {
31          FixedHostRmiClientSocketFactory rmiSocketFactory = new FixedHostRmiClientSocketFactory();
32          try
33          {
34              Socket socket = rmiSocketFactory.createSocket("localhost", 1099);
35              socket.close();
36              fail("Should not connect");
37          }
38          catch (ConnectException e)
39          {
40              // expected behavior
41          }
42          
43          try
44          {
45              Socket socket = rmiSocketFactory.createSocket("localhost", 1098);
46              socket.close();
47              // expected behavior
48          }
49          catch (ConnectException e)
50          {
51              fail("Should connect");
52          }
53      }
54  
55  }