@Test public void deleteFactorByTypeTest() throws OktaException { Factor[] expectedFactors = { expectedFactor }; ResponseEntity<Factor[]> responseEntity = new ResponseEntity<>(expectedFactors, HttpStatus.OK); ResponseEntity<Factor> deleteResponseEntity = new ResponseEntity<>(expectedFactor, HttpStatus.OK); expect(mockOktaRestService.doRestCall("/api/v1/users/" + expectedUser.getId() + "/factors", HttpMethod.GET, Factor[].class, "parameters")).andReturn(responseEntity).atLeastOnce(); expect(mockOktaRestService.doRestCall("/api/v1/users/" + expectedUser.getId() + "/factors/" + expectedFactor.getId(), HttpMethod.DELETE, Factor.class, "parameters")).andReturn(deleteResponseEntity); replayAll(); unit.deleteFactor(expectedFactor.getFactorType(), expectedUser); verifyAll(); }
@Override public void deleteFactor(String factorId, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); if (user != null) { String apiPath = String.format(OktaAPIConstants.GET_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.DELETE, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } } }
FactorServiceImpl implements FactorService { @Override public void deleteFactor(String factorId, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); if (user != null) { String apiPath = String.format(OktaAPIConstants.GET_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.DELETE, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } } } }
FactorServiceImpl implements FactorService { @Override public void deleteFactor(String factorId, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); if (user != null) { String apiPath = String.format(OktaAPIConstants.GET_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.DELETE, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } } }  }
FactorServiceImpl implements FactorService { @Override public void deleteFactor(String factorId, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); if (user != null) { String apiPath = String.format(OktaAPIConstants.GET_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.DELETE, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } } }  @Override Factor getFactor(String factorId, OktaUser user); @Override Factor getFactor(FactorType factorType, OktaUser user); @Override List<Factor> listEnrolledFactors(OktaUser user); @Override List<Factor> listAvailableFactors(OktaUser user); @Override List<SecurityQuestion> listSecurityQuestions(OktaUser user); @Override void deleteFactor(String factorId, OktaUser user); @Override void deleteFactor(FactorType factorType, OktaUser user); OktaRestService getOktaRestService(); void setOktaRestService(OktaRestService oktaRestService); }
FactorServiceImpl implements FactorService { @Override public void deleteFactor(String factorId, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); if (user != null) { String apiPath = String.format(OktaAPIConstants.GET_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.DELETE, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } } }  @Override Factor getFactor(String factorId, OktaUser user); @Override Factor getFactor(FactorType factorType, OktaUser user); @Override List<Factor> listEnrolledFactors(OktaUser user); @Override List<Factor> listAvailableFactors(OktaUser user); @Override List<SecurityQuestion> listSecurityQuestions(OktaUser user); @Override void deleteFactor(String factorId, OktaUser user); @Override void deleteFactor(FactorType factorType, OktaUser user); OktaRestService getOktaRestService(); void setOktaRestService(OktaRestService oktaRestService);  }