@Test
public void tesHandleRequest_InvalidSubResSpecified() {

  Request request = createNiceMock(Request.class);
  RequestBody body = createNiceMock(RequestBody.class);
  ResourceInstance resourceInstance = createNiceMock(ResourceInstance.class);
  ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
  Query query = createNiceMock(Query.class);
  Predicate predicate = createNiceMock(Predicate.class);
  Result result = createNiceMock(Result.class);
  ResourceInstance subResource = createNiceMock(ResourceInstance.class);
  ResourceDefinition subResourceDefinition = createNiceMock(ResourceDefinition.class);
  ClusterController controller = createNiceMock(ClusterController.class);
  Schema serviceSchema = createNiceMock(Schema.class);
  Schema componentSchema = createNiceMock(Schema.class);
  String resourceKeyProperty = "resourceKeyProperty";
  Resource resource1 = createNiceMock(Resource.class);
  Resource resource2 = createNiceMock(Resource.class);
  PersistenceManager pm = createNiceMock(PersistenceManager.class);
  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 queryResultStatus = createNiceMock(ResultStatus.class);
  //  test request body
  //    {
  //      "INVALID" : [
  //        { "ServiceComponentInfo" : {
  //            "component_name" : "SECONDARY_NAMENODE"
  //          }
  //        },
  //        { "ServiceComponentInfo" : {
  //            "component_name" : "HDFS_CLIENT"
  //          }
  //        }
  //      ]
  //   }
  Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
  Set<NamedPropertySet> setRequestProps = new HashSet<NamedPropertySet>();
  Map<String, Object> mapProperties = new HashMap<String, Object>();
  Set<Map<String, Object>> arraySet  = new HashSet<Map<String, Object>>();
  mapProperties.put("INVALID", arraySet);
  Map<String, Object> map = new HashMap<String, Object>();
  map.put(PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), "SECONDARY_NAMENODE");
  arraySet.add(map);
  map = new HashMap<String, Object>();
  map.put(PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), "HDFS_CLIENT");
  arraySet.add(map);
  setRequestProps.add(new NamedPropertySet("", mapProperties));
  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");
  //expectations
  expect(readHandler.handleRequest(request)).andReturn(result);
  expect(result.getStatus()).andReturn(queryResultStatus).anyTimes();
  expect(queryResultStatus.isErrorState()).andReturn(false);
  expect(result.getResultTree()).andReturn(resultTree);
  expect(request.getResource()).andReturn(resourceInstance).anyTimes();
  expect(request.getBody()).andReturn(body).anyTimes();
  expect(body.getNamedPropertySets()).andReturn(setRequestProps).anyTimes();
  expect(resourceInstance.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
  expect(resourceInstance.getKeyValueMap()).andReturn(mapIds).anyTimes();
  expect(resourceInstance.getSubResources()).andReturn(mapSubResources).anyTimes();
  expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
  expect(controller.getSchema(Resource.Type.Service)).andReturn(serviceSchema).anyTimes();
  expect(result.getResultTree()).andReturn(resultTree).anyTimes();
  expect(resource1.getPropertyValue(resourceKeyProperty)).andReturn("id1").anyTimes();
  expect(resource2.getPropertyValue(resourceKeyProperty)).andReturn("id2").anyTimes();
  replay(request, body, resourceInstance, resourceDefinition, query, predicate, result, subResource,
      subResourceDefinition, controller, serviceSchema, componentSchema, resource1, resource2,
      pm, createResource, status, statusResource1, statusResource2,
      readHandler, queryResultStatus);
  //test
  Result testResult = new TestQueryCreateHandler(null, controller, pm, readHandler).
      handleRequest(request);
  ResultStatus resultStatus = testResult.getStatus();
  assertEquals(ResultStatus.STATUS.BAD_REQUEST, resultStatus.getStatus());
  assertEquals("Invalid Request: The specified sub-resource name is not valid: 'INVALID'.", resultStatus.getMessage());
  verify(request, body, resourceInstance, resourceDefinition, query, predicate, result, subResource,
      subResourceDefinition, controller, serviceSchema, componentSchema, resource1, resource2,
      pm, createResource, status, statusResource1, statusResource2,
      readHandler, queryResultStatus);
}