View Javadoc

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