@Test
public void transferSSLCertificate_External_Failure() throws Exception {

	String jsonStr = "{  \"username\": \"testusername1\",  \"password\": \"testpassword1\"}";
	String jsonStr2 = "{\"certificates\":[{\"sortedSubjectName\": \"CN=CertificateName.t-mobile.com, C=US, " +
            "ST=Washington, " +
            "L=Bellevue, O=T-Mobile USA, Inc\"," +
            "\"certificateId\":57258,\"certificateStatus\":\"Active\"," +
            "\"containerName\":\"cont_12345\",\"NotAfter\":\"2021-06-15T04:35:58-07:00\"}]}";
	SSLCertificateMetadataDetails sslCertificateRequest = getSSLCertificateMetadataDetails();
	 UserDetails userDetails = new UserDetails();
     userDetails.setSelfSupportToken("tokentTest");
     userDetails.setUsername("normaluser");
     userDetails.setAdmin(true);
     userDetails.setClientToken(token);
     userDetails.setSelfSupportToken(token);
    Map<String, Object> requestMap = new HashMap<>();
    requestMap.put("access_token", "12345");
    requestMap.put("token_type", "type");
    when(ControllerUtil.parseJson(jsonStr)).thenReturn(requestMap);
    CertManagerLogin certManagerLogin = new CertManagerLogin();
    certManagerLogin.setToken_type("token type");
    certManagerLogin.setAccess_token("1234");
    String metaDataJson = "{\"data\":{\"akmid\":\"102463\",\"applicationName\":\"tvs\",\"applicationOwnerEmailId\":\"SpectrumClearingTools@T-Mobile.com\",\"applicationTag\":\"TVS\",\"authority\":\"T-Mobile Issuing CA 01 - SHA2\",\"certCreatedBy\":\"nnazeer1\",\"certOwnerEmailId\":\"ltest@smail.com\",\"certType\":\"internal\",\"certificateId\":59880,\"certificateName\":\"certtest260630.t-mobile.com\",\"certificateStatus\":\"Revoked\",\"containerName\":\"VenafiBin_12345\",\"createDate\":\"2020-06-26T05:10:41-07:00\",\"expiryDate\":\"2021-06-26T05:10:41-07:00\",\"projectLeadEmailId\":\"Daniel.Urrutia@T-Mobile.Com\",\"users\":{\"normaluser\":\"write\",\"certuser\":\"read\",\"safeadmin\":\"deny\",\"testsafeuser\":\"write\",\"testuser1\":\"deny\",\"testuser2\":\"read\"}}}";
    Response response = new Response();
    response.setHttpstatus(HttpStatus.OK);
    response.setResponse(metaDataJson);
    response.setSuccess(true);
    when(reqProcessor.process(eq("/read"), anyObject(), anyString())).thenReturn(response);
    CertResponse certResponse = new CertResponse();
    certResponse.setHttpstatus(HttpStatus.OK);
    certResponse.setResponse(jsonStr);
    certResponse.setSuccess(true);
    when(reqProcessor.processCert(eq("/auth/certmanager/login"), anyObject(), anyString(), anyString())).thenReturn(certResponse);
    
    when(ControllerUtil.updateMetaData(anyString(), anyMap(), anyString())).thenReturn(Boolean.TRUE);
    DirectoryObjects obj =new DirectoryObjects();
    DirectoryObjectsList objList = new DirectoryObjectsList();
    DirectoryUser user = new DirectoryUser();
    user.setDisplayName("name");
    user.setUserName("213");
    Object[] values = null;
    objList.setValues(values);
    obj.setData(objList);
    
    when(directoryService.searchByUPN(anyString())).
            thenReturn(ResponseEntity.status(HttpStatus.OK).body(obj));
    ResponseEntity<?> transferCertResponse =
            sSLCertificateService.updateCertOwner(token,"external","certificatename.t-mobile.com","owneremail@test.com",userDetails);
    //Assert
    assertNotNull(transferCertResponse);   
    assertEquals(HttpStatus.BAD_REQUEST, transferCertResponse.getStatusCode());
}