@Test public void getFactorByTypeTest() throws OktaException { Factor[] expectedFactors = { expectedFactor }; ResponseEntity<Factor[]> responseEntity = new ResponseEntity<>(expectedFactors, HttpStatus.OK); expect(mockOktaRestService.doRestCall("/api/v1/users/" + expectedUser.getId() + "/factors", HttpMethod.GET, Factor[].class, "parameters")).andReturn(responseEntity).atLeastOnce(); replayAll(); Factor factor = unit.getFactor(expectedFactor.getFactorType(), expectedUser); verifyAll(); assertNotNull(factor); assertEquals(expectedFactor.getId(), factor.getId()); assertEquals(expectedFactor.getFactorType(), factor.getFactorType()); assertEquals(expectedFactor.getProvider(), factor.getProvider()); FactorProfile profile = factor.getProfile(); assertNotNull(profile); assertEquals(expectedProfile.getEmail(), profile.getEmail()); }
@Override public Factor getFactor(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.GET, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }
FactorServiceImpl implements FactorService { @Override public Factor getFactor(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.GET, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; } }
FactorServiceImpl implements FactorService { @Override public Factor getFactor(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.GET, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }  }
FactorServiceImpl implements FactorService { @Override public Factor getFactor(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.GET, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }  @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 Factor getFactor(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.GET, Factor.class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }  @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);  }