@Test public void listSecurityQuestionsTest() throws OktaException { SecurityQuestion expectedQuestion = new SecurityQuestion(); expectedQuestion.setQuestion("first_job"); expectedQuestion.setQuestionText("programmer"); SecurityQuestion[] expectedQuestions = { expectedQuestion }; ResponseEntity<SecurityQuestion[]> responseEntity = new ResponseEntity<>(expectedQuestions, HttpStatus.OK); expect(mockOktaRestService.doRestCall("/api/v1/users/" + expectedUser.getId() + "/factors/questions", HttpMethod.GET, SecurityQuestion[].class, "parameters")).andReturn(responseEntity).atLeastOnce(); replayAll(); List<SecurityQuestion> questions = unit.listSecurityQuestions(expectedUser); verifyAll(); assertNotNull(questions); assertEquals(1, questions.size()); SecurityQuestion question = questions.get(0); assertEquals(expectedQuestion.getQuestion(), question.getQuestion()); assertEquals(expectedQuestion.getQuestionText(), question.getQuestionText()); }
@Override public List<SecurityQuestion> listSecurityQuestions(OktaUser user) throws OktaException { if (user != null) { String apiPath = String.format(OktaAPIConstants.LIST_SECURITY_QUESTIONS, user.getId()); ResponseEntity<SecurityQuestion[]> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.GET, SecurityQuestion[].class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(exchange.toString()); } if (exchange.getBody().length > 0) { return Arrays.asList(exchange.getBody()); } } return Collections.emptyList(); }
FactorServiceImpl implements FactorService { @Override public List<SecurityQuestion> listSecurityQuestions(OktaUser user) throws OktaException { if (user != null) { String apiPath = String.format(OktaAPIConstants.LIST_SECURITY_QUESTIONS, user.getId()); ResponseEntity<SecurityQuestion[]> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.GET, SecurityQuestion[].class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(exchange.toString()); } if (exchange.getBody().length > 0) { return Arrays.asList(exchange.getBody()); } } return Collections.emptyList(); } }
FactorServiceImpl implements FactorService { @Override public List<SecurityQuestion> listSecurityQuestions(OktaUser user) throws OktaException { if (user != null) { String apiPath = String.format(OktaAPIConstants.LIST_SECURITY_QUESTIONS, user.getId()); ResponseEntity<SecurityQuestion[]> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.GET, SecurityQuestion[].class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(exchange.toString()); } if (exchange.getBody().length > 0) { return Arrays.asList(exchange.getBody()); } } return Collections.emptyList(); }  }
FactorServiceImpl implements FactorService { @Override public List<SecurityQuestion> listSecurityQuestions(OktaUser user) throws OktaException { if (user != null) { String apiPath = String.format(OktaAPIConstants.LIST_SECURITY_QUESTIONS, user.getId()); ResponseEntity<SecurityQuestion[]> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.GET, SecurityQuestion[].class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(exchange.toString()); } if (exchange.getBody().length > 0) { return Arrays.asList(exchange.getBody()); } } return Collections.emptyList(); }  @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 List<SecurityQuestion> listSecurityQuestions(OktaUser user) throws OktaException { if (user != null) { String apiPath = String.format(OktaAPIConstants.LIST_SECURITY_QUESTIONS, user.getId()); ResponseEntity<SecurityQuestion[]> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.GET, SecurityQuestion[].class, "parameters"); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(exchange.toString()); } if (exchange.getBody().length > 0) { return Arrays.asList(exchange.getBody()); } } return Collections.emptyList(); }  @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);  }