LoadInformationController { @ResponseBody @RequestMapping(value = "/loadinformation", method = RequestMethod.GET) public Map<String, Long> getLoadInformation() { Map<String, Long> loadInformation = new HashMap<>(); buildConnection(); try { Long jmsQueueSize = (Long) jmsQueueConnection.getAttribute(jmsQueue, "QueueSize"); loadInformation.put("loadInformation", jmsQueueSize); } catch (Exception e) { logger.error("Exception while monitoring queue sizes", e); } return loadInformation; }  @ResponseBody @RequestMapping(value = "/loadinformation", method = RequestMethod.GET) Map<String, Long> getLoadInformation();  }
@Test public void testGetLoadInformation() throws Exception { Long expected = new Long(91); given(mBeanServerConnection.getAttribute(jmsQueue, "QueueSize")).willReturn(expected); Map<String, Long> result = underTest.getLoadInformation(); assertEquals(expected, result.get("loadInformation")); }
@Test public final void testGetLoadInformationShouldInitConnectionWhenJMSQueueIsNull() throws Exception { Whitebox.setInternalState(underTest, "jmsQueue", null); given(jmxConnectionBuilder.buildMBeanServerConnection(LoadInformationController.JMS_SERVICE_URL)).willReturn(mBeanServerConnection); given(jmxObjectNameProvider.getObjectName(LoadInformationController.JMS_QUEUE_OBJECT_NAME)).willReturn(jmsQueue); given(mBeanServerConnection.getAttribute(jmsQueue, "QueueSize")).willReturn(new Long(91)); Map<String, Long> result = underTest.getLoadInformation(); verify(jmxConnectionBuilder).buildMBeanServerConnection(LoadInformationController.JMS_SERVICE_URL); verify(jmxObjectNameProvider).getObjectName(LoadInformationController.JMS_QUEUE_OBJECT_NAME); }
@Test public final void testGetLoadInformationShouldInitConnectionWhenMBeanServerConnectionJMSIsNull() throws Exception { Whitebox.setInternalState(underTest, "jmsQueueConnection", null); given(jmxConnectionBuilder.buildMBeanServerConnection(LoadInformationController.JMS_SERVICE_URL)).willReturn(mBeanServerConnection); given(jmxObjectNameProvider.getObjectName(LoadInformationController.JMS_QUEUE_OBJECT_NAME)).willReturn(jmsQueue); given(mBeanServerConnection.getAttribute(jmsQueue, "QueueSize")).willReturn(new Long(91)); Map<String, Long> result = underTest.getLoadInformation(); verify(jmxConnectionBuilder).buildMBeanServerConnection(LoadInformationController.JMS_SERVICE_URL); verify(jmxObjectNameProvider).getObjectName(LoadInformationController.JMS_QUEUE_OBJECT_NAME); }
@Test public void testGetLoadInformationShouldSendBackEmptyJSONWhenExceptionRaised() throws Exception { given(jmxConnectionBuilder.buildMBeanServerConnection(LoadInformationController.JMS_SERVICE_URL)).willReturn(mBeanServerConnection); given(jmxObjectNameProvider.getObjectName(LoadInformationController.JMS_QUEUE_OBJECT_NAME)).willReturn(jmsQueue); given(mBeanServerConnection.getAttribute(jmsQueue, "QueueSize")).willThrow(AttributeNotFoundException.class); Map<String, Long> result = underTest.getLoadInformation(); assertEquals(0, result.size()); }