WebMBeanAdapter { public String invokeOperation(String operationName, Map<String, String[]> parameterMap) throws JMException, UnsupportedEncodingException { MBeanOperationInfo operationInfo = getOperationInfo(operationName); MBeanOperationInvoker invoker = createMBeanOperationInvoker(mBeanServer, objectName, operationInfo); return sanitizer.escapeValue(invoker.invokeOperation(parameterMap)); } WebMBeanAdapter(MBeanServer mBeanServer, String mBeanName, String encoding); Map<String, MBeanAttributeInfo> getAttributeMetadata(); Map<String, MBeanOperationInfo> getOperationMetadata(); MBeanOperationInfo getOperationInfo(String operationName); Map<String,Object> getAttributeValues(); String getAttributeValue(String attributeName); String invokeOperation(String operationName, Map<String, String[]> parameterMap);  }
@Test public void testInvokeOperation() throws Exception { String operationName = "operation_name"; expect(mockSanitizer.urlDecode(operationName, ENCODING)).andReturn(operationName); MBeanOperationInfo mockOperation = createMock(MBeanOperationInfo.class); MBeanOperationInfo[] operationList = new MBeanOperationInfo[1]; operationList[0] = mockOperation; expect(mockMBeanInfo.getOperations()).andReturn(operationList); expect(mockOperation.getName()).andReturn(operationName); Map<String, String[]> parameterMap = new HashMap<String, String[]>(); Object value = new Object(); expect(mockMBeanOperationInvoker.invokeOperation(parameterMap)).andReturn(value); String valueString = "some_value"; expect(mockSanitizer.escapeValue(value)).andReturn(valueString); replay(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation, mockMBeanOperationInvoker); String invokeResult = webMBeanAdapter.invokeOperation(operationName, parameterMap); assertEquals(valueString, invokeResult); verify(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation, mockMBeanOperationInvoker); }