1
2
3
4
5
6
7
8
9
10
11 package org.mule.management.config;
12
13 import org.mule.RegistryContext;
14 import org.mule.agent.EndpointNotificationLoggerAgent;
15 import org.mule.agent.Log4jNotificationLoggerAgent;
16 import org.mule.api.agent.Agent;
17 import org.mule.api.registry.Registry;
18 import org.mule.config.spring.SpringRegistry;
19 import org.mule.module.management.agent.JmxAgent;
20 import org.mule.module.management.agent.JmxServerNotificationAgent;
21 import org.mule.module.management.agent.Log4jAgent;
22 import org.mule.module.management.agent.Mx4jAgent;
23 import org.mule.module.management.support.AutoDiscoveryJmxSupportFactory;
24 import org.mule.module.management.support.JmxSupport;
25 import org.mule.module.management.support.JmxSupportFactory;
26 import org.mule.tck.FunctionalTestCase;
27 import org.mule.tck.testmodels.mule.TestAgent;
28
29 import java.util.Collection;
30 import java.util.Iterator;
31
32 public class ManagementNamespaceHandlerTestCase extends FunctionalTestCase
33 {
34 private static final int CHAINSAW_PORT = 8080;
35 protected JmxSupportFactory jmxSupportFactory = AutoDiscoveryJmxSupportFactory.getInstance();
36 protected JmxSupport jmxSupport = jmxSupportFactory.getJmxSupport();
37
38 protected String getConfigResources()
39 {
40 return "management-namespace-config.xml";
41 }
42
43 public void testSimpleJmxAgentConfig() throws Exception
44 {
45 Agent agent = muleContext.getRegistry().lookupAgent("jmx-server");
46 assertNotNull(agent);
47 assertEquals(JmxAgent.class, agent.getClass());
48 JmxAgent jmxAgent = (JmxAgent) agent;
49 assertEquals(true, jmxAgent.isCreateServer());
50 assertEquals(true, jmxAgent.isLocateServer());
51 assertEquals(true, jmxAgent.isEnableStatistics());
52
53 agent = muleContext.getRegistry().lookupAgent("jmx-log4j");
54 assertNotNull(agent);
55 assertEquals(Log4jAgent.class, agent.getClass());
56
57 agent = muleContext.getRegistry().lookupAgent("jmx-mx4j-adaptor");
58 assertNotNull(agent);
59 assertEquals(Mx4jAgent.class, agent.getClass());
60 Mx4jAgent mx4jAgent = (Mx4jAgent) agent;
61 assertEquals(mx4jAgent.getJmxAdaptorUrl(), "http://127.0.0.1:8000");
62
63 agent = muleContext.getRegistry().lookupAgent("jmx-notifications");
64 assertNotNull(agent);
65 assertEquals(JmxServerNotificationAgent.class, agent.getClass());
66
67 agent = muleContext.getRegistry().lookupAgent("log4j-notifications");
68 assertNotNull(agent);
69 assertEquals(Log4jNotificationLoggerAgent.class, agent.getClass());
70
71 agent = muleContext.getRegistry().lookupAgent("chainsaw-notifications");
72 assertNotNull(agent);
73 assertEquals(Log4jNotificationLoggerAgent.class, agent.getClass());
74 Log4jNotificationLoggerAgent lnlAgent = (Log4jNotificationLoggerAgent) agent;
75 assertEquals(lnlAgent.getChainsawPort(), CHAINSAW_PORT);
76 assertEquals(lnlAgent.getChainsawHost(), "127.0.0.1");
77
78 agent = muleContext.getRegistry().lookupAgent("publish-notifications");
79 assertNotNull(agent);
80 assertEquals(EndpointNotificationLoggerAgent.class, agent.getClass());
81 EndpointNotificationLoggerAgent enlAgent = (EndpointNotificationLoggerAgent) agent;
82 assertEquals(enlAgent.getEndpointAddress(), "test://test");
83
84 agent = muleContext.getRegistry().lookupAgent("test-custom-agent");
85 assertNotNull(agent);
86 assertEquals(TestAgent.class, agent.getClass());
87 assertEquals("woggle", ((TestAgent) agent).getFrobbit());
88
89
90
91
92
93 }
94
95 public void testAgentsOrder() throws Exception
96 {
97 Registry registry = RegistryContext.getRegistry();
98 SpringRegistry springRegistry = (SpringRegistry) registry.getParent();
99 assertNotNull(springRegistry);
100 Collection agents = springRegistry.lookupObjects(Agent.class);
101 assertEquals(agents.size(), 8);
102 Iterator iter = agents.iterator();
103 assertTrue(iter.next() instanceof JmxAgent);
104 assertTrue(iter.next() instanceof Log4jAgent);
105 assertTrue(iter.next() instanceof Mx4jAgent);
106 assertTrue(iter.next() instanceof TestAgent);
107 assertTrue(iter.next() instanceof JmxServerNotificationAgent);
108 Log4jNotificationLoggerAgent log4jAgent = (Log4jNotificationLoggerAgent) iter.next();
109 assertEquals(log4jAgent.getName(), "log4j-notifications");
110 log4jAgent = (Log4jNotificationLoggerAgent) iter.next();
111 assertEquals(log4jAgent.getName(), "chainsaw-notifications");
112 assertTrue(iter.next() instanceof EndpointNotificationLoggerAgent);
113 }
114
115 }
116
117