QuestionGroupController extends QuestionnaireController { @RequestMapping("/viewQuestionGroupDetail.ftl") public String getQuestionGroup(ModelMap model, HttpServletRequest httpServletRequest) { String questionGroupId = httpServletRequest.getParameter("questionGroupId"); try { if (isInvalidNumber(questionGroupId)) { model.addAttribute("error_message_code", QuestionnaireConstants.INVALID_QUESTION_GROUP_ID); } else { QuestionGroupDetail questionGroupDetail = questionnaireServiceFacade.getQuestionGroupDetail(Integer.valueOf(questionGroupId)); QuestionGroupForm questionGroupForm = new QuestionGroupForm(questionGroupDetail); model.addAttribute("questionGroupDetail", questionGroupForm); model.addAttribute("eventSources", getAllQgEventSources()); } } catch (SystemException e) { model.addAttribute("error_message_code", QuestionnaireConstants.QUESTION_GROUP_NOT_FOUND); } return "viewQuestionGroupDetail"; } @SuppressWarnings({"UnusedDeclaration"})  QuestionGroupController();  QuestionGroupController(QuestionnaireServiceFacade questionnaireServiceFacade); @RequestMapping("/viewQuestionGroups.ftl") String getAllQuestionGroups(ModelMap model, HttpServletRequest request); @RequestMapping("/viewQuestionGroupDetail.ftl") String getQuestionGroup(ModelMap model, HttpServletRequest httpServletRequest); @RequestMapping(value="/getHiddenVisibleQuestions.ftl", method=RequestMethod.POST) @ResponseBody Map<String, Map<Integer, Boolean>> getHiddenVisibleQuestions(
            @RequestParam Integer questionId, @RequestParam String response); @RequestMapping(value="/hideAttachedQuestions.ftl", method=RequestMethod.POST) @ResponseBody Map<String, List<String>> hideAttachedQuestions(
            @RequestParam String questionsId, @RequestParam String sectionsId); @SuppressWarnings({"ThrowableInstanceNeverThrown"}) String defineQuestionGroup(QuestionGroupForm questionGroupForm, RequestContext requestContext, boolean createMode); Map<String, String> getAllQgEventSources(); QuestionLinkDetail setQuestionLinkDetail(QuestionGroupForm questionGroupForm, String sourceQuestionId, 
            String affectedQuestionId, String value, String additionalValue, String linkType, String linkTypeDisplay); SectionLinkDetail setSectionLinkDetail(QuestionGroupForm questionGroupForm, String sourceQuestionId, 
            String affectedSectionName, String value, String additionalValue, String linkType, String linkTypeDisplay); SectionQuestionDetail findQuestionDetailById(QuestionGroupDetail questionGroupDetail, String questionId); SectionQuestionDetail findQuestionDetailByNickname(QuestionGroupDetail questionGroupDetail, String nickname); SectionDetail findSectionDetailByName(QuestionGroupDetail questionGroupDetail, String sectionName); List<QuestionLinkDetail> setFilledQuestionDetailForQuestionLinks(List<QuestionLinkDetail> questionLinkDetails, QuestionGroupDetail questionGroupDetail); List<SectionLinkDetail> setFilledSectionDetailForQuestionLinks(List<SectionLinkDetail> sectionLinkDetails, QuestionGroupDetail questionGroupDetail); String addLink(QuestionGroupForm questionGroupForm,
            String sourceQuestionId, String linkType, String appliesTo,
            String affectedQuestionId, String affectedSectionName,
            String value, String additionalValue, Map<String, String> linkTypes, RequestContext requestContext); String removeLink(QuestionGroupForm questionGroupForm,
            String sourceQuestionId, String affectedQuestionId, String affectedSectionName, String value, String additionalValue, RequestContext requestContext); String addSection(QuestionGroupForm questionGroupForm, RequestContext requestContext); String deleteSection(QuestionGroupForm questionGroupForm, String sectionName); String deleteQuestion(QuestionGroupForm questionGroupForm, String sectionName, String questionId); String moveQuestionUp(QuestionGroupForm questionGroupForm, String sectionName, String questionId); String moveQuestionDown(QuestionGroupForm questionGroupForm, String sectionName, String questionId); String moveSectionUp(QuestionGroupForm questionGroupForm, String sectionName); String moveSectionDown(QuestionGroupForm questionGroupForm, String sectionName); List<SectionQuestionDetail> getAllSectionQuestions(); List<SectionQuestionDetail> getAllSectionQuestions(QuestionGroupForm questionGroupForm); Map<String, String> getAllLinkTypes(); String saveQuestionnaire(QuestionGroupDetails questionGroupDetails, int questionGroupIndex, RequestContext requestContext); String addQuestion(QuestionGroupForm questionGroupForm, RequestContext requestContext); String addSmartChoiceTag(QuestionGroupForm questionGroupForm, RequestContext requestContext, int choiceIndex);  }
@Test public void shouldGetQuestionGroupById() throws SystemException { int questionGroupId = 1; QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(questionGroupId, TITLE, "S1", "S2", "S3"); when(questionnaireServiceFacade.getQuestionGroupDetail(questionGroupId)).thenReturn(questionGroupDetail); when(httpServletRequest.getParameter("questionGroupId")).thenReturn(Integer.toString(questionGroupId)); String view = questionGroupController.getQuestionGroup(model, httpServletRequest); assertThat(view, Is.is("viewQuestionGroupDetail")); verify(questionnaireServiceFacade).getQuestionGroupDetail(questionGroupId); verify(questionnaireServiceFacade, times(1)).getAllEventSources(); verify(httpServletRequest, times(1)).getParameter("questionGroupId"); verify(model).addAttribute(Matchers.eq("questionGroupDetail"), argThat(new QuestionGroupDetailFormMatcher(new QuestionGroupForm(questionGroupDetail)))); }
@SuppressWarnings({"ThrowableInstanceNeverThrown"}) @Test public void testGetQuestionGroupWhenNotPresentInDb() throws SystemException { int questionGroupId = 1; when(questionnaireServiceFacade.getQuestionGroupDetail(questionGroupId)).thenThrow(new SystemException(QuestionnaireConstants.QUESTION_GROUP_NOT_FOUND)); when(httpServletRequest.getParameter("questionGroupId")).thenReturn("1"); String view = questionGroupController.getQuestionGroup(model, httpServletRequest); assertThat(view, Is.is("viewQuestionGroupDetail")); verify(questionnaireServiceFacade).getQuestionGroupDetail(questionGroupId); verify(httpServletRequest, times(1)).getParameter("questionGroupId"); verify(model).addAttribute("error_message_code", QuestionnaireConstants.QUESTION_GROUP_NOT_FOUND); }
@Test public void testGetQuestionGroupWhenIdIsNull() throws SystemException { when(httpServletRequest.getParameter("questionGroupId")).thenReturn(null); String view = questionGroupController.getQuestionGroup(model, httpServletRequest); assertThat(view, Is.is("viewQuestionGroupDetail")); verify(httpServletRequest, times(1)).getParameter("questionGroupId"); verify(questionnaireServiceFacade, times(0)).getQuestionGroupDetail(Matchers.anyInt()); verify(model).addAttribute("error_message_code", QuestionnaireConstants.INVALID_QUESTION_GROUP_ID); }
@Test public void testGetQuestionGroupWhenIdIsNotInteger() throws SystemException { when(httpServletRequest.getParameter("questionGroupId")).thenReturn("1A"); String view = questionGroupController.getQuestionGroup(model, httpServletRequest); assertThat(view, Is.is("viewQuestionGroupDetail")); verify(httpServletRequest, times(1)).getParameter("questionGroupId"); verify(questionnaireServiceFacade, times(0)).getQuestionGroupDetail(Matchers.anyInt()); verify(model).addAttribute("error_message_code", QuestionnaireConstants.INVALID_QUESTION_GROUP_ID); }