diff --git a/agent/mule/pom.xml b/agent/mule/pom.xml
index 35722af38..c9b091e3e 100644
--- a/agent/mule/pom.xml
+++ b/agent/mule/pom.xml
@@ -59,6 +59,33 @@
org.mortbay.jetty
jetty
provided
+
+
+ org.mortbay.jetty
+ servlet-api
+
+
+
+
+
+ org.eclipse.jetty
+ jetty-server
+ 8.1.13.v20130916
+ provided
+
+
+
+ org.eclipse.jetty
+ jetty-servlet
+ 8.1.13.v20130916
+ provided
+
+
+
+ org.eclipse.jetty
+ jetty-security
+ 8.1.13.v20130916
+ provided
diff --git a/agent/mule/src/main/java/org/jolokia/mule/EclipseMuleAgentHttpServer.java b/agent/mule/src/main/java/org/jolokia/mule/EclipseMuleAgentHttpServer.java
new file mode 100644
index 000000000..b97e01fa7
--- /dev/null
+++ b/agent/mule/src/main/java/org/jolokia/mule/EclipseMuleAgentHttpServer.java
@@ -0,0 +1,173 @@
+package org.jolokia.mule;
+
+/*
+ * Copyright 2014 Michio Nakagawa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jetty.security.ConstraintMapping;
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.security.HashLoginService;
+import org.eclipse.jetty.security.SecurityHandler;
+import org.eclipse.jetty.security.authentication.BasicAuthenticator;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.HandlerContainer;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.util.security.Constraint;
+import org.eclipse.jetty.util.security.Credential;
+import org.jolokia.http.AgentServlet;
+import org.jolokia.util.NetworkUtil;
+import org.mule.api.agent.Agent;
+import org.mule.api.lifecycle.StartException;
+import org.mule.api.lifecycle.StopException;
+
+/**
+ * HTTP Server for the Mule agent which encapsulates a Eclipse Jetty server.
+ *
+ *
+ * @author Michio Nakagawa
+ * @since 10.10.14
+ */
+public class EclipseMuleAgentHttpServer implements MuleAgentHttpServer {
+
+ // parent agent
+ private Agent parent;
+
+ // Jetty server to use
+ private Server server;
+
+ /**
+ * Constructor
+ *
+ * @param pParent parent for creating proper exceptions
+ * @param pConfig configuration of the server
+ */
+ EclipseMuleAgentHttpServer(Agent pParent, MuleAgentConfig pConfig) {
+ parent = pParent;
+
+ // Initialize server
+ server = getServer(pConfig);
+ ServletContextHandler root = getContext(server, pConfig);
+ ServletHolder servletHolder = getServletHolder(pConfig);
+ root.addServlet(servletHolder, "/*");
+ }
+
+ /**
+ * Startup the HTTP server
+ *
+ * @throws StartException if starting fails
+ */
+ public void start() throws StartException {
+ try {
+ server.start();
+ } catch (Exception e) {
+ throw new StartException(e, parent);
+ }
+ }
+
+ /**
+ * Stop the internal HTTP server
+ *
+ * @throws StopException when stopping fails
+ */
+ public void stop() throws StopException {
+ try {
+ server.stop();
+ } catch (Exception e) {
+ throw new StopException(e, parent);
+ }
+ }
+
+ // ======================================================================================
+
+ // Create a Jetty Server with the agent servlet installed
+ private Server getServer(MuleAgentConfig pConfig) {
+ Server newServer = new Server();
+
+ Connector connector = new SelectChannelConnector();
+ if (pConfig.getHost() != null) {
+ connector.setHost(pConfig.getHost());
+ }
+ connector.setPort(pConfig.getPort());
+ newServer.setConnectors(new Connector[]{connector});
+
+ return newServer;
+ }
+
+ private ServletHolder getServletHolder(MuleAgentConfig pConfig) {
+ ServletHolder holder = new ServletHolder(new AgentServlet());
+ holder.setInitParameters(getInitParameters(pConfig));
+ holder.setInitOrder(1);
+ return holder;
+ }
+
+ private ServletContextHandler getContext(HandlerContainer pContainer, MuleAgentConfig pConfig) {
+ ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ context.setContextPath("/jolokia");
+ server.setHandler(context);
+ if (pConfig.getUser() != null && pConfig.getPassword() != null) {
+ context.setSecurityHandler(
+ getSecurityHandler(pConfig.getUser(), pConfig.getPassword(), "jolokia-role"));
+ }
+ return context;
+ }
+
+ private SecurityHandler getSecurityHandler(String pUser, String pPassword, String pRole) {
+ HashLoginService loginService = getLoginService(pUser, pPassword, pRole);
+ server.addBean(loginService);
+ ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
+ securityHandler.setConstraintMappings(getConstraintMappings(pRole));
+ securityHandler.setAuthenticator(new BasicAuthenticator());
+ securityHandler.addBean(loginService);
+ return securityHandler;
+ }
+
+ private HashLoginService getLoginService(String pUser, String pPassword, String pRole) {
+ Credential credential = Credential.getCredential(pPassword);
+ HashLoginService loginService = new HashLoginService("jolokia Realm");
+ loginService.putUser(pUser, credential, new String[] {pRole});
+ return loginService;
+ }
+
+ private ConstraintMapping[] getConstraintMappings(String ... pRoles) {
+ Constraint constraint = new Constraint();
+ constraint.setName(Constraint.__BASIC_AUTH);
+ constraint.setRoles(pRoles);
+ constraint.setAuthenticate(true);
+
+ ConstraintMapping cm = new ConstraintMapping();
+ cm.setConstraint(constraint);
+ cm.setPathSpec("/*");
+ return new ConstraintMapping[] { cm };
+ }
+
+ private Map getInitParameters(MuleAgentConfig pConfig) {
+ Map ret = new HashMap();
+ ret.put("debugMaxEntries", "" + pConfig.getDebugMaxEntries());
+ ret.put("historyMaxEntries", "" + pConfig.getHistoryMaxEntries());
+ ret.put("maxCollectionsSize", "" + pConfig.getMaxCollectionSize());
+ ret.put("maxDepth", "" + pConfig.getMaxDepth());
+ ret.put("maxObjects", "" + pConfig.getMaxObjects());
+ ret.put("debug", "" + pConfig.isDebug());
+ ret.put("agentType", "mule");
+ ret.put("agentId", NetworkUtil.getAgentId(hashCode(), "mule"));
+ return ret;
+ }
+}
diff --git a/agent/mule/src/main/java/org/jolokia/mule/JolokiaMuleAgent.java b/agent/mule/src/main/java/org/jolokia/mule/JolokiaMuleAgent.java
index 9bd49a0af..0dcc24cde 100644
--- a/agent/mule/src/main/java/org/jolokia/mule/JolokiaMuleAgent.java
+++ b/agent/mule/src/main/java/org/jolokia/mule/JolokiaMuleAgent.java
@@ -34,7 +34,7 @@
public class JolokiaMuleAgent extends AbstractAgent implements MuleAgentConfig {
// Internal HTTP-Server
- private MuleAgentHttpServer server;
+ protected MuleAgentHttpServer server;
protected JolokiaMuleAgent() {
super("jolokia-agent");
@@ -113,7 +113,7 @@ public void unregistered() {
* @throws InitialisationException
*/
public void initialise() throws InitialisationException {
- server = new MuleAgentHttpServer(this,this);
+ server = MuleAgentHttpServerFactory.create(this, this);
}
// ===============================================================================
diff --git a/agent/mule/src/main/java/org/jolokia/mule/MortbayMuleAgentHttpServer.java b/agent/mule/src/main/java/org/jolokia/mule/MortbayMuleAgentHttpServer.java
new file mode 100644
index 000000000..90ce2ea36
--- /dev/null
+++ b/agent/mule/src/main/java/org/jolokia/mule/MortbayMuleAgentHttpServer.java
@@ -0,0 +1,160 @@
+package org.jolokia.mule;
+
+/*
+ * Copyright 2009-2011 Roland Huss
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jolokia.http.AgentServlet;
+import org.jolokia.util.NetworkUtil;
+import org.mortbay.jetty.*;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.security.*;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mule.api.agent.Agent;
+import org.mule.api.lifecycle.StartException;
+import org.mule.api.lifecycle.StopException;
+
+/**
+ * HTTP Server for the Mule agent which encapsulates a Jetty server.
+ *
+ *
+ * @author roland
+ * @since 30.08.11
+ */
+public class MortbayMuleAgentHttpServer implements MuleAgentHttpServer {
+
+ // parent agent
+ private Agent parent;
+
+ // Jetty server to use
+ private Server server;
+
+ /**
+ * Constructor
+ *
+ * @param pParent parent for creating proper exceptions
+ * @param pConfig configuration of the server
+ */
+ MortbayMuleAgentHttpServer(Agent pParent, MuleAgentConfig pConfig) {
+ parent = pParent;
+
+ // Initialise server
+ server = getServer(pConfig);
+ Context root = getContext(server, pConfig);
+ ServletHolder servletHolder = getServletHolder(pConfig);
+ root.addServlet(servletHolder, "/*");
+ }
+
+ /**
+ * Startup the HTTP server
+ *
+ * @throws StartException if starting fails
+ */
+ public void start() throws StartException {
+ try {
+ server.start();
+ } catch (Exception e) {
+ throw new StartException(e, parent);
+ }
+ }
+
+ /**
+ * Stop the internal HTTP server
+ *
+ * @throws StopException when stopping fails
+ */
+ public void stop() throws StopException {
+ try {
+ server.stop();
+ } catch (Exception e) {
+ throw new StopException(e, parent);
+ }
+ }
+
+ // ======================================================================================
+
+ // Create a Jetty Server with the agent servlet installed
+ private Server getServer(MuleAgentConfig pConfig) {
+ Server newServer = new Server();
+
+ Connector connector = new SelectChannelConnector();
+ if (pConfig.getHost() != null) {
+ connector.setHost(pConfig.getHost());
+ }
+ connector.setPort(pConfig.getPort());
+ newServer.setConnectors(new Connector[]{connector});
+
+ return newServer;
+ }
+
+ private ServletHolder getServletHolder(MuleAgentConfig pConfig) {
+ ServletHolder holder = new ServletHolder(new AgentServlet());
+ holder.setInitParameters(getInitParameters(pConfig));
+ holder.setInitOrder(1);
+ return holder;
+ }
+
+ private Context getContext(HandlerContainer pContainer, MuleAgentConfig pConfig) {
+ Context root = new Context(pContainer, "/jolokia", Context.SESSIONS);
+ if (pConfig.getUser() != null && pConfig.getPassword() != null) {
+ root.setSecurityHandler(getSecurityHandler(pConfig.getUser(), pConfig.getPassword(), "jolokia-role"));
+ }
+ return root;
+ }
+
+ private SecurityHandler getSecurityHandler(String pUser, String pPassword, String pRole) {
+ SecurityHandler securityHandler = new SecurityHandler();
+ securityHandler.setConstraintMappings(getConstraintMappings(pRole));
+ securityHandler.setUserRealm(getUserRealm(pUser, pPassword, pRole));
+ return securityHandler;
+ }
+
+ private UserRealm getUserRealm(String pUser, String pPassword, String pRole) {
+ HashUserRealm realm = new HashUserRealm("jolokia Realm");
+ realm.put(pUser,pPassword);
+ realm.addUserToRole(pUser,pRole);
+ return realm;
+ }
+
+ private ConstraintMapping[] getConstraintMappings(String ... pRoles) {
+ Constraint constraint = new Constraint();
+ constraint.setName(Constraint.__BASIC_AUTH);
+ constraint.setRoles(pRoles);
+ constraint.setAuthenticate(true);
+
+ ConstraintMapping cm = new ConstraintMapping();
+ cm.setConstraint(constraint);
+ cm.setPathSpec("/*");
+ return new ConstraintMapping[] { cm };
+ }
+
+ private Map getInitParameters(MuleAgentConfig pConfig) {
+ Map ret = new HashMap();
+ ret.put("debugMaxEntries", "" + pConfig.getDebugMaxEntries());
+ ret.put("historyMaxEntries", "" + pConfig.getHistoryMaxEntries());
+ ret.put("maxCollectionsSize", "" + pConfig.getMaxCollectionSize());
+ ret.put("maxDepth", "" + pConfig.getMaxDepth());
+ ret.put("maxObjects", "" + pConfig.getMaxObjects());
+ ret.put("debug", "" + pConfig.isDebug());
+ ret.put("agentType", "mule");
+ ret.put("agentId", NetworkUtil.getAgentId(hashCode(), "mule"));
+ return ret;
+ }
+
+}
diff --git a/agent/mule/src/main/java/org/jolokia/mule/MuleAgentHttpServer.java b/agent/mule/src/main/java/org/jolokia/mule/MuleAgentHttpServer.java
index ef9b8f648..dba5fe78f 100644
--- a/agent/mule/src/main/java/org/jolokia/mule/MuleAgentHttpServer.java
+++ b/agent/mule/src/main/java/org/jolokia/mule/MuleAgentHttpServer.java
@@ -1,160 +1,31 @@
package org.jolokia.mule;
-/*
- * Copyright 2009-2011 Roland Huss
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jolokia.http.AgentServlet;
-import org.jolokia.util.NetworkUtil;
-import org.mortbay.jetty.*;
-import org.mortbay.jetty.nio.SelectChannelConnector;
-import org.mortbay.jetty.security.*;
-import org.mortbay.jetty.servlet.Context;
-import org.mortbay.jetty.servlet.ServletHolder;
-import org.mule.api.agent.Agent;
import org.mule.api.lifecycle.StartException;
import org.mule.api.lifecycle.StopException;
/**
- * HTTP Server for the Mule agent which encapsulates a Jetty server.
- *
- *
- * @author roland
- * @since 30.08.11
+ * Internal HTTP server interface For Mule Agent.
+ *
+ *
+ * @author Michio Nakagawa
+ * @since 10.10.14
*/
-public class MuleAgentHttpServer {
-
- // parent agent
- private Agent parent;
-
- // Jetty server to use
- private Server server;
-
- /**
- * Constructor
- *
- * @param pParent parent for creating proper exceptions
- * @param pConfig configuration of the server
- */
- MuleAgentHttpServer(Agent pParent, MuleAgentConfig pConfig) {
- parent = pParent;
-
- // Initialise server
- server = getServer(pConfig);
- Context root = getContext(server,pConfig);
- ServletHolder servletHolder = getServletHolder(pConfig);
- root.addServlet(servletHolder, "/*");
- }
-
- /**
- * Startup the HTTP server
- *
- * @throws StartException if starting fails
- */
- public void start() throws StartException {
- try {
- server.start();
- } catch (Exception e) {
- throw new StartException(e,parent);
- }
- }
-
- /**
- * Stop the internal HTTP server
- *
- * @throws StopException when stopping fails
- */
- public void stop() throws StopException {
- try {
- server.stop();
- } catch (Exception e) {
- throw new StopException(e,parent);
- }
- }
-
- // ======================================================================================
-
- // Create a Jetty Server with the agent servlet installed
- private Server getServer(MuleAgentConfig pConfig) {
- Server newServer = new Server();
-
- Connector connector = new SelectChannelConnector();
- if (pConfig.getHost() != null) {
- connector.setHost(pConfig.getHost());
- }
- connector.setPort(pConfig.getPort());
- newServer.setConnectors(new Connector[]{connector});
-
- return newServer;
- }
-
- private ServletHolder getServletHolder(MuleAgentConfig pConfig) {
- ServletHolder holder = new ServletHolder(new AgentServlet());
- holder.setInitParameters(getInitParameters(pConfig));
- holder.setInitOrder(1);
- return holder;
- }
-
- private Context getContext(HandlerContainer pContainer, MuleAgentConfig pConfig) {
- Context root = new Context(pContainer,"/jolokia",Context.SESSIONS);
- if (pConfig.getUser() != null && pConfig.getPassword() != null) {
- root.setSecurityHandler(getSecurityHandler(pConfig.getUser(),pConfig.getPassword(),"jolokia-role"));
- }
- return root;
- }
-
- private SecurityHandler getSecurityHandler(String pUser, String pPassword, String pRole) {
- SecurityHandler securityHandler = new SecurityHandler();
- securityHandler.setConstraintMappings(getConstraintMappings(pRole));
- securityHandler.setUserRealm(getUserRealm(pUser, pPassword, pRole));
- return securityHandler;
- }
-
- private UserRealm getUserRealm(String pUser, String pPassword, String pRole) {
- HashUserRealm realm = new HashUserRealm("jolokia Realm");
- realm.put(pUser,pPassword);
- realm.addUserToRole(pUser,pRole);
- return realm;
- }
-
- private ConstraintMapping[] getConstraintMappings(String ... pRoles) {
- Constraint constraint = new Constraint();
- constraint.setName(Constraint.__BASIC_AUTH);
- constraint.setRoles(pRoles);
- constraint.setAuthenticate(true);
-
- ConstraintMapping cm = new ConstraintMapping();
- cm.setConstraint(constraint);
- cm.setPathSpec("/*");
- return new ConstraintMapping[] { cm };
- }
-
- private Map getInitParameters(MuleAgentConfig pConfig) {
- Map ret = new HashMap();
- ret.put("debugMaxEntries", "" + pConfig.getDebugMaxEntries());
- ret.put("historyMaxEntries","" + pConfig.getHistoryMaxEntries());
- ret.put("maxCollectionsSize", "" + pConfig.getMaxCollectionSize());
- ret.put("maxDepth","" + pConfig.getMaxDepth());
- ret.put("maxObjects", "" + pConfig.getMaxObjects());
- ret.put("debug","" + pConfig.isDebug());
- ret.put("agentType","mule");
- ret.put("agentId", NetworkUtil.getAgentId(hashCode(),"mule"));
- return ret;
- }
-
-}
+public interface MuleAgentHttpServer {
+
+ /**
+ * Startup the internal HTTP server
+ *
+ *
+ * @throws StartException if starting fails
+ */
+ void start() throws StartException;
+
+ /**
+ * Stop the internal HTTP server
+ *
+ *
+ * @throws StopException when stopping fails
+ */
+ void stop() throws StopException;
+
+}
\ No newline at end of file
diff --git a/agent/mule/src/main/java/org/jolokia/mule/MuleAgentHttpServerFactory.java b/agent/mule/src/main/java/org/jolokia/mule/MuleAgentHttpServerFactory.java
new file mode 100644
index 000000000..16c68eefa
--- /dev/null
+++ b/agent/mule/src/main/java/org/jolokia/mule/MuleAgentHttpServerFactory.java
@@ -0,0 +1,54 @@
+package org.jolokia.mule;
+
+/*
+ * Copyright 2014 Michio Nakagawa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.mule.api.agent.Agent;
+
+/**
+ * HTTP Server factory for the Mule agent.
+ *
+ *
+ * @author Michio Nakagawa
+ * @since 10.10.14
+ */
+public final class MuleAgentHttpServerFactory {
+ // Server class for Jetty6
+ static String CLAZZ_NAME = "org.mortbay.jetty.Server";
+
+ protected MuleAgentHttpServerFactory() {}
+
+ /**
+ * Create the internal HTTP server.
+ * Create the Jetty Server of Mortbay packages or Eclipse Foundation packages.
+ *
+ *
+ * @param pParent parent for creating proper exceptions
+ * @param pConfig configuration of the server
+ * @return internal HTTP server
+ */
+ public static MuleAgentHttpServer create(Agent pParent, MuleAgentConfig pConfig) {
+ MuleAgentHttpServer server = null;
+
+ try {
+ Class.forName(CLAZZ_NAME);
+ server = new MortbayMuleAgentHttpServer(pParent, pConfig);
+ } catch (ClassNotFoundException e) {
+ server = new EclipseMuleAgentHttpServer(pParent, pConfig);
+ }
+ return server;
+ }
+}
diff --git a/agent/mule/src/test/java/org/jolokia/mule/EclipseJolokiaMuleAgentTest.java b/agent/mule/src/test/java/org/jolokia/mule/EclipseJolokiaMuleAgentTest.java
new file mode 100644
index 000000000..afe06619b
--- /dev/null
+++ b/agent/mule/src/test/java/org/jolokia/mule/EclipseJolokiaMuleAgentTest.java
@@ -0,0 +1,35 @@
+package org.jolokia.mule;
+
+/*
+ * Copyright 2014 Michio Nakagawa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.mule.api.lifecycle.InitialisationException;
+
+/**
+ * @author Michio Nakagawa
+ * @since 10.10.14
+ */
+public class EclipseJolokiaMuleAgentTest extends JolokiaMuleAgentTestCase {
+ @Override
+ protected JolokiaMuleAgent createJolokiaMuleAgent() {
+ return new JolokiaMuleAgent() {
+ @Override
+ public void initialise() throws InitialisationException {
+ this.server = new EclipseMuleAgentHttpServer(this, this);
+ };
+ };
+ }
+}
diff --git a/agent/mule/src/test/java/org/jolokia/mule/JolokiaMuleAgentTest.java b/agent/mule/src/test/java/org/jolokia/mule/JolokiaMuleAgentTestCase.java
similarity index 94%
rename from agent/mule/src/test/java/org/jolokia/mule/JolokiaMuleAgentTest.java
rename to agent/mule/src/test/java/org/jolokia/mule/JolokiaMuleAgentTestCase.java
index 85e75dbdf..c4b78f22f 100644
--- a/agent/mule/src/test/java/org/jolokia/mule/JolokiaMuleAgentTest.java
+++ b/agent/mule/src/test/java/org/jolokia/mule/JolokiaMuleAgentTestCase.java
@@ -31,13 +31,14 @@
* @author roland
* @since 30.08.11
*/
-public class JolokiaMuleAgentTest {
+public abstract class JolokiaMuleAgentTestCase {
- private JolokiaMuleAgent agent = new JolokiaMuleAgent();
+ private JolokiaMuleAgent agent = null;
+ protected abstract JolokiaMuleAgent createJolokiaMuleAgent();
@BeforeMethod
public void setup() {
- agent = new JolokiaMuleAgent();
+ agent = createJolokiaMuleAgent();
}
@Test
diff --git a/agent/mule/src/test/java/org/jolokia/mule/MortbayJolokiaMuleAgentTest.java b/agent/mule/src/test/java/org/jolokia/mule/MortbayJolokiaMuleAgentTest.java
new file mode 100644
index 000000000..fab9fd8d7
--- /dev/null
+++ b/agent/mule/src/test/java/org/jolokia/mule/MortbayJolokiaMuleAgentTest.java
@@ -0,0 +1,35 @@
+package org.jolokia.mule;
+
+/*
+ * Copyright 2014 Michio Nakagawa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.mule.api.lifecycle.InitialisationException;
+
+/**
+ * @author Michio Nakagawa
+ * @since 10.10.14
+ */
+public class MortbayJolokiaMuleAgentTest extends JolokiaMuleAgentTestCase {
+ @Override
+ protected JolokiaMuleAgent createJolokiaMuleAgent() {
+ return new JolokiaMuleAgent() {
+ @Override
+ public void initialise() throws InitialisationException {
+ this.server = new MortbayMuleAgentHttpServer(this, this);
+ };
+ };
+ }
+}
diff --git a/agent/mule/src/test/java/org/jolokia/mule/MuleAgentHttpServerFactoryTest.java b/agent/mule/src/test/java/org/jolokia/mule/MuleAgentHttpServerFactoryTest.java
new file mode 100644
index 000000000..662bc5ff1
--- /dev/null
+++ b/agent/mule/src/test/java/org/jolokia/mule/MuleAgentHttpServerFactoryTest.java
@@ -0,0 +1,65 @@
+package org.jolokia.mule;
+
+import static org.testng.Assert.assertEquals;
+
+import java.lang.reflect.Field;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/*
+ * Copyright 2014 Michio Nakagawa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * @author Michio Nakagawa
+ * @since 10.10.14
+ */
+public class MuleAgentHttpServerFactoryTest {
+ String originalValue = null;
+ JolokiaMuleAgent agent = new JolokiaMuleAgent();
+
+ @BeforeMethod
+ public void setup() throws Exception {
+ originalValue = MuleAgentHttpServerFactory.CLAZZ_NAME;
+ }
+
+ @AfterMethod
+ public void teardown() throws Exception {
+ setFieldValue(new MuleAgentHttpServerFactory(), "CLAZZ_NAME", originalValue);
+ }
+
+ @Test
+ public void createServerOfMortbayPackage() throws Exception {
+ MuleAgentHttpServer actual = MuleAgentHttpServerFactory.create(agent, agent);
+ assertEquals(actual.getClass(), MortbayMuleAgentHttpServer.class);
+ }
+
+ @Test
+ public void createServerOfEclipsePackage() throws Exception {
+ setFieldValue(new MuleAgentHttpServerFactory(), "CLAZZ_NAME", "xxx");
+
+ MuleAgentHttpServer actual = MuleAgentHttpServerFactory.create(agent, agent);
+ assertEquals(actual.getClass(), EclipseMuleAgentHttpServer.class);
+ }
+
+ private void setFieldValue(Object target, String name, Object value) throws Exception {
+ Field field = target.getClass().getDeclaredField(name);
+ field.setAccessible(true);
+ field.set(target, value);
+ }
+}