1
2
3
4
5
6
7
8
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.tck.junit4.FunctionalTestCase;
22 import org.mule.tck.testmodels.mule.TestAgent;
23
24 import java.util.Collection;
25 import java.util.Iterator;
26
27 import org.junit.Test;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertNotNull;
32 import static org.junit.Assert.assertTrue;
33
34 public class ManagementNamespaceHandlerTestCase extends FunctionalTestCase
35 {
36
37 private static final int CHAINSAW_PORT = 8080;
38
39 public ManagementNamespaceHandlerTestCase()
40 {
41 super();
42
43 setStartContext(false);
44 }
45
46 @Override
47 protected String getConfigResources()
48 {
49 return "management-namespace-config.xml";
50 }
51
52 @Test
53 public void testSimpleJmxAgentConfig() throws Exception
54 {
55 Agent agent = muleContext.getRegistry().lookupObject(JmxAgent.class);
56 assertNotNull(agent);
57 assertEquals(JmxAgent.class, agent.getClass());
58 JmxAgent jmxAgent = (JmxAgent) agent;
59 assertFalse(jmxAgent.isCreateServer());
60 assertTrue(jmxAgent.isLocateServer());
61 assertTrue(jmxAgent.isEnableStatistics());
62 assertEquals("some://test.url", jmxAgent.getConnectorServerUrl());
63
64 agent = muleContext.getRegistry().lookupAgent("jmx-log4j");
65 assertNotNull(agent);
66 assertEquals(Log4jAgent.class, agent.getClass());
67
68 agent = muleContext.getRegistry().lookupAgent("jmx-mx4j-adaptor");
69 assertNotNull(agent);
70 assertEquals(Mx4jAgent.class, agent.getClass());
71 Mx4jAgent mx4jAgent = (Mx4jAgent) agent;
72 assertEquals(mx4jAgent.getJmxAdaptorUrl(), "http://127.0.0.1:8000");
73
74 agent = muleContext.getRegistry().lookupAgent("jmx-notifications");
75 assertNotNull(agent);
76 assertEquals(JmxServerNotificationAgent.class, agent.getClass());
77
78 agent = muleContext.getRegistry().lookupAgent("log4j-notifications");
79 assertNotNull(agent);
80 assertEquals(Log4jNotificationLoggerAgent.class, agent.getClass());
81
82 agent = muleContext.getRegistry().lookupAgent("chainsaw-notifications");
83 assertNotNull(agent);
84 assertEquals(Log4jNotificationLoggerAgent.class, agent.getClass());
85 Log4jNotificationLoggerAgent lnlAgent = (Log4jNotificationLoggerAgent) agent;
86 assertEquals(lnlAgent.getChainsawPort(), CHAINSAW_PORT);
87 assertEquals(lnlAgent.getChainsawHost(), "127.0.0.1");
88
89 agent = muleContext.getRegistry().lookupAgent("publish-notifications");
90 assertNotNull(agent);
91 assertEquals(EndpointNotificationLoggerAgent.class, agent.getClass());
92 EndpointNotificationLoggerAgent enlAgent = (EndpointNotificationLoggerAgent) agent;
93 assertEquals(enlAgent.getEndpoint().getEndpointURI().toString(), "test://test");
94
95 agent = muleContext.getRegistry().lookupAgent("test-custom-agent");
96 assertNotNull(agent);
97 assertEquals(TestAgent.class, agent.getClass());
98 assertEquals("woggle", ((TestAgent) agent).getFrobbit());
99
100
101
102
103
104 }
105
106 @Test
107 public void testAgentsOrder() throws Exception
108 {
109 Registry registry = muleContext.getRegistry();
110 assertNotNull(registry);
111 Collection<Agent> agents = registry.lookupObjects(Agent.class);
112 assertEquals(agents.size(), 8);
113
114 Iterator<Agent> iter = agents.iterator();
115 assertTrue(iter.next() instanceof JmxAgent);
116 assertTrue(iter.next() instanceof Log4jAgent);
117 assertTrue(iter.next() instanceof Mx4jAgent);
118 assertTrue(iter.next() instanceof TestAgent);
119 assertTrue(iter.next() instanceof JmxServerNotificationAgent);
120
121 Log4jNotificationLoggerAgent log4jAgent = (Log4jNotificationLoggerAgent) iter.next();
122 assertEquals(log4jAgent.getName(), "log4j-notifications");
123
124 log4jAgent = (Log4jNotificationLoggerAgent) iter.next();
125 assertEquals(log4jAgent.getName(), "chainsaw-notifications");
126 assertTrue(iter.next() instanceof EndpointNotificationLoggerAgent);
127 }
128
129 }