TomcatInformations implements Serializable { private TomcatInformations(ObjectName threadPool) throws JMException { super(); name = threadPool.getKeyProperty("name"); maxThreads = MBeansAccessor.getAttribute(threadPool, "maxThreads"); currentThreadCount = MBeansAccessor.getAttribute(threadPool, "currentThreadCount"); currentThreadsBusy = MBeansAccessor.getAttribute(threadPool, "currentThreadsBusy"); ObjectName grp = null; for (final ObjectName globalRequestProcessor : GLOBAL_REQUEST_PROCESSORS) { if (name.equals(globalRequestProcessor.getKeyProperty("name"))) { grp = globalRequestProcessor; break; } } if (grp != null) { bytesReceived = MBeansAccessor.getAttribute(grp, "bytesReceived"); bytesSent = MBeansAccessor.getAttribute(grp, "bytesSent"); requestCount = MBeansAccessor.getAttribute(grp, "requestCount"); errorCount = MBeansAccessor.getAttribute(grp, "errorCount"); processingTime = MBeansAccessor.getAttribute(grp, "processingTime"); maxTime = MBeansAccessor.getAttribute(grp, "maxTime"); } else { bytesReceived = 0; bytesSent = 0; requestCount = 0; errorCount = 0; processingTime = 0; maxTime = 0; } } private  TomcatInformations(ObjectName threadPool); static void initMBeans(); String getName(); int getMaxThreads(); int getCurrentThreadsBusy(); long getBytesReceived(); long getBytesSent(); int getRequestCount(); int getErrorCount(); long getProcessingTime(); long getMaxTime(); @Override String toString();  }
@Test public void testTomcatInformations() throws JMException { System.setProperty("catalina.home", "unknown"); TomcatInformations.initMBeans(); assertNotNull("buildTomcatInformationsList", TomcatInformations.buildTomcatInformationsList()); final MBeanServer mBeanServer = MBeans.getPlatformMBeanServer(); final List<ObjectName> mBeans = new ArrayList<ObjectName>(); mBeans.add( mBeanServer .registerMBean(new ThreadPool(), new ObjectName("Catalina:type=ThreadPool,name=http-8080")) .getObjectName()); TomcatInformations.initMBeans(); try { assertNotNull("buildTomcatInformationsList", TomcatInformations.buildTomcatInformationsList()); mBeans.add( mBeanServer .registerMBean(new GlobalRequestProcessor(), new ObjectName( "Catalina:type=GlobalRequestProcessor,name=http-8080")) .getObjectName()); TomcatInformations.initMBeans(); assertNotNull("buildTomcatInformationsList", TomcatInformations.buildTomcatInformationsList()); for (final TomcatInformations tomcatInformations : TomcatInformations .buildTomcatInformationsList()) { tomcatInformations.toString(); } final Counter counter = new Counter("http", null); final Collector collector = new Collector("test", Arrays.asList(counter)); final ServletContext context = createNiceMock(ServletContext.class); expect(context.getServerInfo()).andReturn("Mock").anyTimes(); expect(context.getMajorVersion()).andReturn(3).anyTimes(); expect(context.getMinorVersion()).andReturn(0).anyTimes(); expect(context.getContextPath()).andReturn("/test").anyTimes(); replay(context); Parameters.initialize(context); collector.collectLocalContextWithoutErrors(); verify(context); } finally { for (final ObjectName registeredMBean : mBeans) { mBeanServer.unregisterMBean(registeredMBean); } TomcatInformations.initMBeans(); } }