WebsphereDetector extends AbstractServerDetector { public ServerHandle detect(MBeanServerExecutor pMBeanServerExecutor) { String serverVersion = getSingleStringAttribute(pMBeanServerExecutor, "*:j2eeType=J2EEServer,type=Server,*", "serverVersion"); if (serverVersion != null && serverVersion.contains("WebSphere")) { Matcher matcher = SERVER_VERSION_PATTERN.matcher(serverVersion); if (matcher.find()) { String version = matcher.group(1); String date = matcher.group(2); JSONObject extraInfo = new JSONObject(); if (date != null) { extraInfo.put("buildDate",date); } return new WebsphereServerHandle(version, extraInfo.size() > 0 ? extraInfo : null); } return null; } else if (isWebsphere) { return new WebsphereServerHandle(isWebsphere6 ? "6" : "7 or 8", null); } return null; }  ServerHandle detect(MBeanServerExecutor pMBeanServerExecutor); @Override void addMBeanServers(Set<MBeanServerConnection> servers); static final String INTERNAL_ERROR_MSG; }
@Test public void detect() throws MalformedObjectNameException, InstanceNotFoundException, ReflectionException, AttributeNotFoundException, MBeanException { ServerDetector detector = new WebsphereDetector(); ObjectName serverMbean = new ObjectName(SERVER_MBEAN); MBeanServer mockServer = createMock(MBeanServer.class); expect(mockServer.queryNames(new ObjectName("*:j2eeType=J2EEServer,type=Server,*"),null)). andStubReturn(new HashSet<ObjectName>(Arrays.asList(serverMbean))); expect(mockServer.isRegistered(serverMbean)).andStubReturn(true); expect(mockServer.getAttribute(serverMbean,"platformName")).andReturn("IBM WebSphere Application Server"); expect(mockServer.getAttribute(serverMbean,"serverVersion")).andReturn(SERVER_VERSION_V6); replay(mockServer); ServerHandle info = detector.detect(getMBeanServerManager(mockServer)); assertEquals(info.getVendor(),"IBM"); assertEquals(info.getProduct(),"websphere"); assertNotNull(info.getExtraInfo(null)); assertEquals(info.getExtraInfo(null).get("buildDate"),"8/14/10"); }