ResourceInstance createResource = createNiceMock(ResourceInstance.class);
RequestStatus status = createNiceMock(RequestStatus.class);
Resource statusResource1 = createNiceMock(Resource.class);
Resource statusResource2 = createNiceMock(Resource.class);
RequestHandler readHandler = createStrictMock(RequestHandler.class);
ResultStatus resultStatus = createNiceMock(ResultStatus.class);
String httpBody = "{" +
"\"components\" : [" +
"{\"ServiceComponentInfo\" : {" +
" \"component_name\" : \"SECONDARY_NAMENODE\"" +
" }" +
"}," +
"{\"ServiceComponentInfo\" : {" +
" \"component_name\" : \"HDFS_CLIENT\"" +
" }" +
"}" +
"] }";
Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
Set<Map<String, Object>> setRequestProps = new HashSet<Map<String, Object>>();
setRequestProps.add(Collections.<String, Object>singletonMap(
PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), "SECONDARY_NAMENODE"));
setRequestProps.add(Collections.<String, Object>singletonMap(
PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), "HDFS_CLIENT"));
Set<Map<String, Object>> setCreateProps = new HashSet<Map<String, Object>>();
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put(PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), "SECONDARY_NAMENODE");
map1.put(createKeyProperty, "id1");
setCreateProps.add(map1);
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put(PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), "SECONDARY_NAMENODE");
map2.put(createKeyProperty, "id2");
setCreateProps.add(map2);
Map<String, Object> map3 = new HashMap<String, Object>();
map3.put(PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), "HDFS_CLIENT");
map3.put(createKeyProperty, "id1");
setCreateProps.add(map3);
Map<String, Object> map4 = new HashMap<String, Object>();
map4.put(PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), "HDFS_CLIENT");
map4.put(createKeyProperty, "id2");
setCreateProps.add(map4);
Map<String, ResourceInstance> mapSubResources = new HashMap<String, ResourceInstance>();
mapSubResources.put("components", subResource);
TreeNode<Resource> resultTree = new TreeNodeImpl<Resource>(null, null, "result");
resultTree.addChild(resource1, "resource1");
resultTree.addChild(resource2, "resource2");
Set<Resource> setStatusResources = new HashSet<Resource>();
setStatusResources.add(statusResource1);
setStatusResources.add(statusResource2);
//expectations
expect(readHandler.handleRequest(request)).andReturn(result);
expect(result.getStatus()).andReturn(resultStatus).anyTimes();
expect(resultStatus.isErrorState()).andReturn(false);
expect(result.getResultTree()).andReturn(resultTree);
expect(request.getResource()).andReturn(resourceInstance).anyTimes();
expect(request.getHttpBody()).andReturn(httpBody).anyTimes();
expect(request.getHttpBodyProperties()).andReturn(setRequestProps).anyTimes();