@Test
public void test_readAppRoleDetails_WithUserDetails_failure() throws Exception {

    String token = "5PDrOhsy4ig8L3EpsJZSLAMg";
    UserDetails userDetails = getMockUser("testuser2", false);
    String role_name = "approle1";
    String username = userDetails.getUsername();
    String path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + role_name;
    String roleId="generated-role-id";
    
    
    
    ArrayList<String> policiesList = new ArrayList<String>();
    policiesList.add("r_shared_safe01");
    String[] policies = policiesList.toArray(new String[policiesList.size()]);
    AppRole appRole = new AppRole(role_name, policies, true, 0, 0, 0);
    
    String appRoleResponseJson = new ObjectMapper().writeValueAsString(appRole);
    Response appRoleResponse = getMockResponse(HttpStatus.OK, true, appRoleResponseJson);
    
    Map<String, Object> appRoleResponseMap = new HashMap<>();
    Map<String, Object> dataMap = new HashMap<>();
    appRoleResponseMap.put("data", dataMap);
    dataMap.put("policies",policiesList);
    dataMap.put("bind_secret_id",new Boolean(true));
    dataMap.put("secret_id_num_uses", new Integer(0));
    dataMap.put("secret_id_ttl", new Integer(0));
    dataMap.put("token_num_uses", new Integer(0));
    dataMap.put("token_ttl", new Integer(0));
    dataMap.put("token_max_ttl", new Integer(0));
    
    when(ControllerUtil.parseJson(appRoleResponseJson)).thenReturn(appRoleResponseMap);
    when(reqProcessor.process("/auth/approle/role/read", "{\"role_name\":\""+role_name+"\"}",userDetails.getSelfSupportToken())).thenReturn(appRoleResponse);
    
    
    AppRoleMetadata approleMetadata = new AppRoleMetadata();
    approleMetadata.setPath(path);
    AppRoleMetadataDetails appRoleMetadataDetails = new AppRoleMetadataDetails();
    appRoleMetadataDetails.setCreatedBy(username);
    appRoleMetadataDetails.setName(role_name);
    approleMetadata.setAppRoleMetadataDetails(appRoleMetadataDetails);
    
    String appRoleMetadataResponseJson = new ObjectMapper().writeValueAsString(approleMetadata);
    Response appRoleMetadataResponse = getMockResponse(HttpStatus.NOT_FOUND, true, appRoleMetadataResponseJson);
    
    Map<String, Object> appRoleMetadatResponseMap = new HashMap<>();
    Map<String, Object> appRoleMetadataMap = new HashMap<>();
    appRoleMetadataMap.put("createdBy",username);
    appRoleMetadatResponseMap.put("data", appRoleMetadataMap);
    when(ControllerUtil.parseJson(appRoleMetadataResponseJson)).thenReturn(appRoleMetadatResponseMap);
    when(reqProcessor.process("/read", "{\"path\":\""+path+"\"}",userDetails.getSelfSupportToken())).thenReturn(appRoleMetadataResponse);
    
    String roleIdResponseJson = "{\"data\":{ \"role_id\": \""+roleId+"\"}}";
    Response roleIdResponse = getMockResponse(HttpStatus.OK, true, roleIdResponseJson);
    
    Map<String, Object> responseMap = new HashMap<>();
    Map<String,Object> roleIdDataMap = new HashMap<>();
    roleIdDataMap.put("role_id", roleId);
    responseMap.put("data", roleIdDataMap);
    when(ControllerUtil.parseJson("{\"data\":{ \"role_id\": \""+roleId+"\"}}")).thenReturn(responseMap);
    when(reqProcessor.process("/auth/approle/role/readRoleID", "{\"role_name\":\""+role_name+"\"}",userDetails.getSelfSupportToken())).thenReturn(roleIdResponse);
    
    String accessorIdResponseJson = "{\r\n" + 
    		"  \"keys\": [\r\n" + 
    		"    \"generated-accessor-id1\"\r\n" + 
    		"  ]\r\n" + 
    		"}";
    Response accessorIdResponse = getMockResponse(HttpStatus.OK, true, accessorIdResponseJson);
    
    Map<String, Object> accessorIdResponseMap = new HashMap<>();
    ArrayList<String> accessorIds = new ArrayList<String>();
    accessorIds.add("generated-accessor-id1");
    accessorIdResponseMap.put("keys", accessorIds);
    when(ControllerUtil.parseJson(accessorIdResponseJson)).thenReturn(responseMap);
    
    when(reqProcessor.process("/auth/approle/role/accessors/list", "{\"role_name\":\""+role_name+"\"}",userDetails.getSelfSupportToken())).thenReturn(accessorIdResponse);
    
pRoleDetails appRoleDetails = new AppRoleDetails();
pRoleDetails.setAppRole(appRole);
pRoleDetails.setRole_id(roleId);
pRoleDetails.setAppRoleMetadata(approleMetadata);
 (!CollectionUtils.isEmpty(accessorIds)) {
ppRoleDetails.setAccessorIds(accessorIds.toArray(new String[accessorIds.size()]));
    String appRoleDetailsResponseJson = "{\"errors\":[\"Access denied: You don't have enough permission to read the secret_id associated with the AppRole\"]}";
    Response appRoleDetailsResponse =getMockResponse(HttpStatus.BAD_REQUEST, true, appRoleDetailsResponseJson);
    ResponseEntity<String> responseEntityExpected = ResponseEntity.status(appRoleDetailsResponse.getHttpstatus()).body(appRoleDetailsResponse.getResponse());
    
    ResponseEntity<String> responseEntityActual = appRoleService.readAppRoleDetails(token, role_name, userDetails);
    assertEquals(HttpStatus.BAD_REQUEST, responseEntityActual.getStatusCode());
    assertEquals(responseEntityExpected, responseEntityActual);
}