View Javadoc

1   /*
2    * $Id: ManagementNamespaceHandlerTestCase.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.config;
12  
13  import org.mule.agent.EndpointNotificationLoggerAgent;
14  import org.mule.agent.Log4jNotificationLoggerAgent;
15  import org.mule.api.agent.Agent;
16  import org.mule.api.registry.Registry;
17  import org.mule.module.management.agent.JmxAgent;
18  import org.mule.module.management.agent.JmxServerNotificationAgent;
19  import org.mule.module.management.agent.Log4jAgent;
20  import org.mule.module.management.agent.Mx4jAgent;
21  import org.mule.module.management.support.AutoDiscoveryJmxSupportFactory;
22  import org.mule.module.management.support.JmxSupport;
23  import org.mule.module.management.support.JmxSupportFactory;
24  import org.mule.tck.FunctionalTestCase;
25  import org.mule.tck.testmodels.mule.TestAgent;
26  
27  import java.util.Collection;
28  import java.util.Iterator;
29  
30  public class ManagementNamespaceHandlerTestCase extends FunctionalTestCase
31  {
32      private static final int CHAINSAW_PORT = 8080;
33      protected JmxSupportFactory jmxSupportFactory = AutoDiscoveryJmxSupportFactory.getInstance();
34      protected JmxSupport jmxSupport = jmxSupportFactory.getJmxSupport();
35  
36      
37      public ManagementNamespaceHandlerTestCase()
38      {
39          super();
40          // do not start the muleContext, we're only doing registry lookups in this test case
41          setStartContext(false);
42      }
43  
44      protected String getConfigResources()
45      {
46          return "management-namespace-config.xml";
47      }
48  
49      public void testSimpleJmxAgentConfig() throws Exception
50      {
51          Agent agent = muleContext.getRegistry().lookupObject(JmxAgent.class);
52          assertNotNull(agent);
53          assertEquals(JmxAgent.class, agent.getClass());
54          JmxAgent jmxAgent = (JmxAgent) agent;
55          assertFalse(jmxAgent.isCreateServer());
56          assertTrue(jmxAgent.isLocateServer());
57          assertTrue(jmxAgent.isEnableStatistics());
58          assertEquals("some://test.url", jmxAgent.getConnectorServerUrl());
59  
60          agent = muleContext.getRegistry().lookupAgent("jmx-log4j");
61          assertNotNull(agent);
62          assertEquals(Log4jAgent.class, agent.getClass());
63  
64          agent = muleContext.getRegistry().lookupAgent("jmx-mx4j-adaptor");
65          assertNotNull(agent);
66          assertEquals(Mx4jAgent.class, agent.getClass());
67          Mx4jAgent mx4jAgent = (Mx4jAgent) agent;
68          assertEquals(mx4jAgent.getJmxAdaptorUrl(), "http://127.0.0.1:8000");
69  
70          agent = muleContext.getRegistry().lookupAgent("jmx-notifications");
71          assertNotNull(agent);
72          assertEquals(JmxServerNotificationAgent.class, agent.getClass());
73  
74          agent = muleContext.getRegistry().lookupAgent("log4j-notifications");
75          assertNotNull(agent);
76          assertEquals(Log4jNotificationLoggerAgent.class, agent.getClass());
77  
78          agent = muleContext.getRegistry().lookupAgent("chainsaw-notifications");
79          assertNotNull(agent);
80          assertEquals(Log4jNotificationLoggerAgent.class, agent.getClass());
81          Log4jNotificationLoggerAgent lnlAgent = (Log4jNotificationLoggerAgent) agent;
82          assertEquals(lnlAgent.getChainsawPort(), CHAINSAW_PORT);
83          assertEquals(lnlAgent.getChainsawHost(), "127.0.0.1");
84  
85          agent = muleContext.getRegistry().lookupAgent("publish-notifications");
86          assertNotNull(agent);
87          assertEquals(EndpointNotificationLoggerAgent.class, agent.getClass());
88          EndpointNotificationLoggerAgent enlAgent = (EndpointNotificationLoggerAgent) agent;
89          assertEquals(enlAgent.getEndpoint().getEndpointURI().toString(), "test://test");
90  
91          agent = muleContext.getRegistry().lookupAgent("test-custom-agent");
92          assertNotNull(agent);
93          assertEquals(TestAgent.class, agent.getClass());
94          assertEquals("woggle", ((TestAgent) agent).getFrobbit());
95  
96          // needs profiler installed
97  //        agent = muleContext.getRegistry().lookupAgent("yourkit-profiler");
98  //        assertNotNull(agent);
99  //        assertEquals(YourKitProfilerAgent.class, agent.getClass());
100     }
101 
102     public void testAgentsOrder() throws Exception
103     {
104         Registry registry = muleContext.getRegistry();
105         assertNotNull(registry);
106         Collection agents = registry.lookupObjects(Agent.class);
107         assertEquals(agents.size(), 8);
108         
109         Iterator iter = agents.iterator();
110         assertTrue(iter.next() instanceof JmxAgent);
111         assertTrue(iter.next() instanceof Log4jAgent);
112         assertTrue(iter.next() instanceof Mx4jAgent);
113         assertTrue(iter.next() instanceof TestAgent);
114         assertTrue(iter.next() instanceof JmxServerNotificationAgent);
115         
116         Log4jNotificationLoggerAgent log4jAgent = (Log4jNotificationLoggerAgent) iter.next();
117         assertEquals(log4jAgent.getName(), "log4j-notifications");
118         
119         log4jAgent = (Log4jNotificationLoggerAgent) iter.next();
120         assertEquals(log4jAgent.getName(), "chainsaw-notifications");
121         assertTrue(iter.next() instanceof EndpointNotificationLoggerAgent);
122     }
123 
124 }