@Test
public void test_readAppRoleSecretId_WithUserDetails_failure_BAD_REQUEST() throws Exception {

    String token = "5PDrOhsy4ig8L3EpsJZSLAMg";
    UserDetails userDetails = getMockUser("testuser1", false);
    String role_name = "approle1";
    String username = userDetails.getUsername();
    String path = TVaultConstants.APPROLE_METADATA_MOUNT_PATH + "/" + role_name;
    
    // START - AppRole exists
    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(reqProcessor.process("/auth/approle/role/read", "{\"role_name\":\""+role_name+"\"}",userDetails.getSelfSupportToken())).thenReturn(appRoleResponse);
    when(ControllerUtil.parseJson(appRoleResponseJson)).thenReturn(appRoleResponseMap);
    // END - AppRole exists
    // START - isAllowed
    String approleusername="nonexisting";
    Response approleMetadataResponse = getMockResponse(HttpStatus.OK, true, getAppRoleMetadataJSON(path, approleusername, role_name));
    when(reqProcessor.process("/read","{\"path\":\""+path+"\"}",userDetails.getSelfSupportToken())).thenReturn(approleMetadataResponse);
    // END - isAllowed
    
    String responseJson = "{\"errors\":[\"Access denied: You don't have enough permission to read the secret_id associated with the AppRole\"]}";
    
    Response response =getMockResponse(HttpStatus.BAD_REQUEST, true, responseJson);
    when(reqProcessor.process("/auth/approle/secretid/lookup","{\"role_name\":\""+role_name+"\"}",userDetails.getSelfSupportToken())).thenReturn(response);
    ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response.getResponse());
    Map<String, Object> responseMap = new HashMap<>();
    Map<String,Object> roleIdDataMap = new HashMap<>();
    roleIdDataMap.put("role_id", "generated-id");
    roleIdDataMap.put("createdBy", username);
    responseMap.put("data", roleIdDataMap);
    when(ControllerUtil.parseJson("{\"path\":\""+path+"\",\"data\":{\"name\":\""+role_name+"\",\"createdBy\":\""+username+"\"}}")).thenReturn(responseMap);
    ResponseEntity<String> responseEntityActual = appRoleService.readAppRoleSecretId(token, role_name, userDetails);
    assertEquals(HttpStatus.BAD_REQUEST, responseEntityActual.getStatusCode());
    assertEquals(responseEntityExpected, responseEntityActual);
}