@Test
public void test_onboardServiceAccount_BadRequest_for_AccountRole() {

erDetails userDetails = getMockUser(true);
	String token = userDetails.getClientToken();
	ServiceAccount serviceAccount = generateServiceAccount("testacc02","testacc01");
	serviceAccount.setAutoRotate(true);
    Response response = getMockResponse(HttpStatus.OK, true, "{\"keys\":[\"testacc03\"]}");
    when(reqProcessor.process("/ad/serviceaccount/onboardedlist","{}",token)).thenReturn(response);
    List<ADServiceAccount> allServiceAccounts = new ArrayList<>();
    allServiceAccounts.add(generateADServiceAccount("testacc02"));
    ReflectionTestUtils.setField(serviceAccountsService, "ldapTemplate", ldapTemplate);
    when(ldapTemplate.search(Mockito.anyString(), Mockito.any(), Mockito.any(AttributesMapper.class))).thenReturn(allServiceAccounts);
    // CreateRole
rviceAccountTTL serviceAccountTTL = new ServiceAccountTTL();
rviceAccountTTL.setRole_name(serviceAccount.getName());
rviceAccountTTL.setService_account_name(serviceAccount.getName() + "@aaa.bbb.ccc.com") ;
rviceAccountTTL.setTtl(serviceAccount.getTtl());
ring svc_account_payload = getJSON(serviceAccountTTL);
en(JSONUtil.getJSON(Mockito.any(ServiceAccountTTL.class))).thenReturn(svc_account_payload);
sponse onboardResponse = getMockResponse(HttpStatus.BAD_REQUEST, true, "{\"errors\":[\"Failed to create service account role.\"]}");
    when(reqProcessor.process("/ad/serviceaccount/onboard", svc_account_payload, token)).thenReturn(onboardResponse);
    // System under test
	String expectedResponse = "{\"errors\":[\"Failed to onboard AD service account into TVault for password rotation.\"]}";
    ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(expectedResponse);
    ResponseEntity<String> responseEntity = serviceAccountsService.onboardServiceAccount(token, serviceAccount, userDetails);
    assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
    assertEquals(responseEntityExpected, responseEntity);
}