Java tutorial
/* * Generated by the Mule project wizard. http://mule.mulesoft.org * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */ package nz.org.geonet.mule; import nz.org.geonet.mule.metrics.collector.MuleCollector; import org.junit.Test; import org.mule.api.client.MuleClient; import org.mule.config.spring.SpringRegistry; import org.mule.tck.junit4.FunctionalTestCase; import org.springframework.context.ApplicationContext; import java.util.HashMap; import static org.junit.Assert.assertTrue; public class MuleMetricsTestCase extends FunctionalTestCase { protected String getConfigResources() { return "src/main/app/mule-config.xml"; } /** * The Mule component (Metrics) does not return a message to the flow so we cannot test it directly. * Start Mule up and get a Spring bean from the registry to check the wiring and metrics code. * * @throws Exception */ @Test public void muleMetrics() throws Exception { MuleClient client = muleContext.getClient(); ApplicationContext applicationContext = muleContext.getRegistry() .lookupObject(SpringRegistry.SPRING_APPLICATION_CONTEXT); MuleCollector collector = (MuleCollector) applicationContext.getBean("collector"); HashMap<String, Number> results = collector.gather(); assertTrue("Map has Threading.used", results.containsKey("Threading.used")); assertTrue("Map has Threading.max", results.containsKey("Threading.max")); assertTrue("Map has HeapMemoryUsage.used", results.containsKey("HeapMemoryUsage.used")); assertTrue("Map has HeapMemoryUsage.max", results.containsKey("HeapMemoryUsage.max")); assertTrue("Map has Classes.totalLoaded", results.containsKey("Classes.totalLoaded")); } }