JmxRequestFactory { public static <R extends JmxRequest> R createPostRequest(Map<String, ?> pRequestMap, ProcessingParameters pProcessingParams) { try { ProcessingParameters paramsMerged = pProcessingParams.mergedParams((Map<String,String>) pRequestMap.get("config")); RequestType type = RequestType.getTypeByName((String) pRequestMap.get("type")); return (R) getCreator(type).create(pRequestMap, paramsMerged); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Invalid object name. " + e.getMessage(),e); } } private  JmxRequestFactory(); static R createGetRequest(String pPathInfo, ProcessingParameters pProcessingParameters); static R createPostRequest(Map<String, ?> pRequestMap, ProcessingParameters pProcessingParams); static List<JmxRequest> createPostRequests(List pJsonRequests, ProcessingParameters pProcessingParams);  }
@Test public void simplePost() { Map<String,Object> reqMap = createMap( "type","read", "mbean","java.lang:type=Memory", "attribute","HeapMemoryUsage"); JmxReadRequest req = JmxRequestFactory.createPostRequest(reqMap, procParams); assert req.getType() == RequestType.READ : "Type is read"; assert req.getObjectName().getCanonicalName().equals("java.lang:type=Memory") : "Name properly parsed"; assertEquals(req.getAttributeName(),"HeapMemoryUsage","Attribute parsed properly"); assert req.getPathParts() == null : "PathParts are null"; assert req.getPath() == null : "Path is null"; }
@Test public void simplePostWithPath() { Map<String,Object> reqMap = createMap( "type","read", "mbean","java.lang:type=Memory", "attribute","HeapMemoryUsage", "path","blub!/bla/hello"); JmxReadRequest req = JmxRequestFactory.createPostRequest(reqMap, procParams); List<String> path = req.getPathParts(); assertEquals(path.size(),2); assertEquals(path.get(0),"blub/bla"); assertEquals(path.get(1),"hello"); assertEquals(req.getPath(),"blub!/bla/hello"); }
@Test(expectedExceptions = { IllegalArgumentException.class }) public void simplePostWithMalformedObjectName() { JmxRequestFactory.createPostRequest(createMap("type", "read", "mbean", "bal::blub", "attribute", "HeapMemoryUsage"), procParams); }
@Test public void simplePostWithMergedMaps() { Map config = new HashMap(); config.put("maxDepth","10"); Map<String,Object> reqMap = createMap( "type","read", "mbean","java.lang:type=Memory", "attribute","HeapMemoryUsage", "config",config); Map param = new HashMap();; param.put("maxObjects","100"); JmxReadRequest req = (JmxReadRequest) JmxRequestFactory.createPostRequest(reqMap,new Configuration().getProcessingParameters(param)); assertEquals(req.getAttributeName(),"HeapMemoryUsage"); assertEquals(req.getParameter(ConfigKey.MAX_DEPTH),"10"); assertEquals(req.getParameterAsInt(ConfigKey.MAX_OBJECTS), 100); }