@Test
public void test_resetSvcAccPassword_success_initial_reset() {

    UserDetails userDetails = getMockUser(true);
    String token = userDetails.getClientToken();
    String svcAccName = "testacc03";
    // for createAccountRole
    ServiceAccount serviceAccount = generateServiceAccount("testacc02","testacc01");
    serviceAccount.setAutoRotate(true);
    ServiceAccountTTL serviceAccountTTL = new ServiceAccountTTL();
    serviceAccountTTL.setRole_name(serviceAccount.getName());
    serviceAccountTTL.setService_account_name(serviceAccount.getName() + "@aaa.bbb.ccc.com") ;
    serviceAccountTTL.setTtl(serviceAccount.getTtl());
    String svc_account_payload = getJSON(serviceAccountTTL);
    when(JSONUtil.getJSON(Mockito.any(ServiceAccount.class))).thenReturn(svc_account_payload);
    Response onboardResponse = getMockResponse(HttpStatus.OK, true, "{\"messages\":[\"Successfully created service account role.\"]}");
    when(reqProcessor.process(Mockito.eq("/ad/serviceaccount/onboard"), Mockito.anyString(), Mockito.eq(token))).thenReturn(onboardResponse);
    //
    // for getOnboarderdServiceAccountDetails
    Map<String,Object> rqstParams = new HashMap<>();
    rqstParams.put("service_account_name",svcAccName);
    rqstParams.put("ttl", 10);
    rqstParams.put("last_vault_rotation", "2018-05-24T17:14:38.677370855Z");
    rqstParams.put("password_last_set","2018-05-24T17:14:38.6038495Z");
    Response svcAccDetailsRes = getMockResponse(HttpStatus.OK, true, getJSON(rqstParams));
    when(reqProcessor.process("/ad/serviceaccount/details","{\"role_name\":\""+svcAccName+"\"}",token)).thenReturn(svcAccDetailsRes);
    // end getOnboarderdServiceAccountDetails
    ADServiceAccountCreds adServiceAccountCreds = new ADServiceAccountCreds();
    adServiceAccountCreds.setCurrent_password("current_password");
    adServiceAccountCreds.setLast_password("last_password");
    adServiceAccountCreds.setUsername(svcAccName);
    String expectedOutput = getJSON(adServiceAccountCreds);
    Response pwdReadResponse = getMockResponse(HttpStatus.OK, true,expectedOutput);
    Response pwdResetResponse = getMockResponse(HttpStatus.OK, true,expectedOutput);
    when(JSONUtil.getJSON(Mockito.any(ADServiceAccountCreds.class))).thenReturn(expectedOutput);
    when(reqProcessor.process(Mockito.eq("/ad/serviceaccount/resetpwd"),Mockito.anyString(),Mockito.eq(token))).thenReturn(pwdResetResponse);
    when(reqProcessor.process(Mockito.eq("/ad/serviceaccount/readpwd"),Mockito.anyString(),Mockito.eq(token))).thenReturn(pwdReadResponse);
    when(ControllerUtil.updateMetadataOnSvcaccPwdReset(Mockito.any(),eq(token))).thenReturn(getMockResponse(HttpStatus.OK, true,expectedOutput));
    ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(expectedOutput);
    when(reqProcessor.process(eq("/sdb"),Mockito.any(),eq(token))).thenReturn(getMockResponse(HttpStatus.OK, true, "{\"data\":{\"initialPasswordReset\":false,\"managedBy\":\"normaluser\",\"name\":\"svc_vault_test5\",\"users\":{\"normaluser\":\"sudo\"}}}"));
    ServiceAccountUser serviceAccountUser = new ServiceAccountUser("testacc02", "testacc01", "read");
    Response userResponse = getMockResponse(HttpStatus.OK, true, "{\"data\":{\"bound_cidrs\":[],\"max_ttl\":0,\"policies\":[\"default\"],\"ttl\":0,\"groups\":\"admin\"}}");
    Response responseNoContent = getMockResponse(HttpStatus.NO_CONTENT, true, "{\"policies\":null}");
    when(reqProcessor.process("/auth/ldap/users","{\"username\":\"testacc01\"}",token)).thenReturn(userResponse);
    try {
        List<String> resList = new ArrayList<>();
        resList.add("default");
        when(ControllerUtil.getPoliciesAsListFromJson(any(), any())).thenReturn(resList);
    } catch (IOException e) {
        e.printStackTrace();
    }
    when(ControllerUtil.configureLDAPUser(eq("testacc01"),any(),any(),eq(token))).thenReturn(responseNoContent);
    when(ControllerUtil.updateMetadata(any(),any())).thenReturn(responseNoContent);
    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\"}}}"));
    String[] latestPolicies = {"o_svcacct_testacc02"};
    when(policyUtils.getCurrentPolicies(userDetails.getSelfSupportToken(), userDetails.getUsername(), userDetails)).thenReturn(latestPolicies);
    ResponseEntity<String> responseEntity = serviceAccountsService.resetSvcAccPassword(token, svcAccName, userDetails);
    assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    assertEquals(responseEntityExpected, responseEntity);
}