1
2
3
4
5
6
7 package org.mule.management.config;
8
9 import org.mule.agent.EndpointNotificationLoggerAgent;
10 import org.mule.agent.Log4jNotificationLoggerAgent;
11 import org.mule.api.agent.Agent;
12 import org.mule.api.registry.Registry;
13 import org.mule.module.management.agent.JmxAgent;
14 import org.mule.module.management.agent.JmxServerNotificationAgent;
15 import org.mule.module.management.agent.Log4jAgent;
16 import org.mule.module.management.agent.Mx4jAgent;
17 import org.mule.tck.junit4.FunctionalTestCase;
18 import org.mule.tck.testmodels.mule.TestAgent;
19
20 import java.util.Collection;
21 import java.util.Iterator;
22
23 import org.junit.Test;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 public class ManagementNamespaceHandlerTestCase extends FunctionalTestCase
31 {
32
33 private static final int CHAINSAW_PORT = 8080;
34
35 public ManagementNamespaceHandlerTestCase()
36 {
37 super();
38
39 setStartContext(false);
40 }
41
42 @Override
43 protected String getConfigResources()
44 {
45 return "management-namespace-config.xml";
46 }
47
48 @Test
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
97
98
99
100 }
101
102 @Test
103 public void testAgentsOrder() throws Exception
104 {
105 Registry registry = muleContext.getRegistry();
106 assertNotNull(registry);
107 Collection<Agent> agents = registry.lookupObjects(Agent.class);
108 assertEquals(agents.size(), 8);
109
110 Iterator<Agent> iter = agents.iterator();
111 assertTrue(iter.next() instanceof JmxAgent);
112 assertTrue(iter.next() instanceof Log4jAgent);
113 assertTrue(iter.next() instanceof Mx4jAgent);
114 assertTrue(iter.next() instanceof TestAgent);
115 assertTrue(iter.next() instanceof JmxServerNotificationAgent);
116
117 Log4jNotificationLoggerAgent log4jAgent = (Log4jNotificationLoggerAgent) iter.next();
118 assertEquals(log4jAgent.getName(), "log4j-notifications");
119
120 log4jAgent = (Log4jNotificationLoggerAgent) iter.next();
121 assertEquals(log4jAgent.getName(), "chainsaw-notifications");
122 assertTrue(iter.next() instanceof EndpointNotificationLoggerAgent);
123 }
124
125 }