WebMBeanAdapter { public MBeanOperationInfo getOperationInfo(String operationName) throws OperationNotFoundException, UnsupportedEncodingException { String decodedOperationName = sanitizer.urlDecode(operationName, encoding); Map<String, MBeanOperationInfo> operationMap = getOperationMetadata(); if (operationMap.containsKey(decodedOperationName)) { return operationMap.get(decodedOperationName); } throw new OperationNotFoundException("Could not find operation " + operationName + " on MBean " + objectName.getCanonicalName()); } 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 testGetOperationInfoWhenItExists() throws Exception { String operationName1 = "operation_name_1"; MBeanOperationInfo mockOperation1 = createMock(MBeanOperationInfo.class); String operationName2 = "operation_name_2"; MBeanOperationInfo mockOperation2 = createMock(MBeanOperationInfo.class); expect(mockSanitizer.urlDecode(operationName2, ENCODING)).andReturn(operationName2); MBeanOperationInfo[] operationList = new MBeanOperationInfo[2]; operationList[0] = mockOperation1; operationList[1] = mockOperation2; expect(mockMBeanInfo.getOperations()).andReturn(operationList); expect(mockOperation1.getName()).andReturn(operationName1); expect(mockOperation2.getName()).andReturn(operationName2); replay(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation1, mockOperation2); MBeanOperationInfo operationInfo = webMBeanAdapter.getOperationInfo(operationName2); assertEquals(mockOperation2, operationInfo); verify(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo, mockOperation1, mockOperation2); }
@Test(expected=OperationNotFoundException.class) public void testGetOperationInfoThrowsOperationNotFoundException() throws Exception { String operationName = "nonexistent"; expect(mockObjectName.getCanonicalName()).andReturn("some_name"); MBeanOperationInfo[] operationList = new MBeanOperationInfo[0]; expect(mockSanitizer.urlDecode(operationName, ENCODING)).andReturn(operationName); expect(mockMBeanInfo.getOperations()).andReturn(operationList); replay(mockMBeanServer, mockSanitizer, mockObjectName, mockMBeanInfo); webMBeanAdapter.getOperationInfo(operationName); }