@Test
public void test_removeGroupFromServiceAccount_metadata_failure() {

    String token = "5PDrOhsy4ig8L3EpsJZSLAMg";
    ServiceAccountGroup serviceAccountGroup = new ServiceAccountGroup("svc_vault_test7", "group1", "reset");
    UserDetails userDetails = getMockUser(false);
    ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Group configuration failed. Please try again\"]}");
    ResponseEntity<String> response = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{\"errors\":[\"Group configuration failed. Please try again\"]}");
    Response responseNoContent = getMockResponse(HttpStatus.NO_CONTENT, true, "");
    Response response404 = getMockResponse(HttpStatus.NOT_FOUND, true, "");
    String [] policies = {"o_svcacct_svc_vault_test7"};
    when(policyUtils.getCurrentPolicies(token, userDetails.getUsername(), userDetails)).thenReturn(policies);
    Response groupResp = getMockResponse(HttpStatus.OK, true, "{\"data\":{\"bound_cidrs\":[],\"max_ttl\":0,\"policies\":[\"default\",\"w_shared_mysafe01\",\"w_shared_mysafe02\"],\"ttl\":0,\"groups\":\"admin\"}}");
    when(reqProcessor.process("/auth/ldap/groups","{\"groupname\":\"group1\"}",token)).thenReturn(groupResp);
    ObjectMapper objMapper = new ObjectMapper();
    String responseJson = groupResp.getResponse();
    try {
        List<String> resList = new ArrayList<>();
        resList.add("default");
        resList.add("w_shared_mysafe01");
        resList.add("w_shared_mysafe02");
        when(ControllerUtil.getPoliciesAsListFromJson(objMapper, responseJson)).thenReturn(resList);
    } catch (IOException e) {
        e.printStackTrace();
    }
    when(ControllerUtil.configureLDAPGroup(any(),any(),any())).thenReturn(responseNoContent);
    when(ControllerUtil.updateMetadata(any(),eq(token))).thenReturn(response404);
    when(tokenUtils.getSelfServiceToken()).thenReturn(token);
    when(reqProcessor.process(eq("/sdb"),Mockito.any(),eq(token))).thenReturn(getMockResponse(HttpStatus.OK, true, "{\"data\":{\"initialPasswordReset\":true,\"managedBy\":\"smohan11\",\"name\":\"svc_vault_test5\",\"users\":{\"smohan11\":\"sudo\"}}}"));
    ResponseEntity<String> responseEntity = serviceAccountsService.removeGroupFromServiceAccount(token, serviceAccountGroup, userDetails);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
    assertEquals(responseEntityExpected, responseEntity);
}