List of usage examples for org.apache.wicket.markup.html.form Radio getModelObject
@SuppressWarnings("unchecked") default T getModelObject()
From source file:gr.interamerican.wicket.markup.html.panel.picker.TestPickerPanel.java
License:Open Source License
/** * Tests creation of {@link PickerPanel}. * //from www .ja va2 s. com * Also tests that pressing the select button, selects the item. */ @Test public void testCreation() { PickerPanelDef<BeanWithOrderedFields> def = createDef(); PickerPanel<BeanWithOrderedFields> panel = new PickerPanel<BeanWithOrderedFields>(def); tester.startPage(getTestPage(panel)); new JavaSerializer(tester.getApplication().getApplicationKey()).serialize(panel); tester.assertComponent(path("tableForm:radioGroup"), RadioGroup.class); tester.assertComponent(path("tableForm:radioGroup:listTable"), DataTable.class); tester.assertComponent(path("tableForm:radioGroup:listTable:body:rows:1:cells:4:cell:radioButton"), Radio.class); String buttonId = path("tableForm:selectButton"); tester.assertComponent(buttonId, AjaxButton.class); AjaxButton button = (AjaxButton) tester.getComponentFromLastRenderedPage(path("tableForm:selectButton")); @SuppressWarnings("unchecked") RadioGroup<BeanWithOrderedFields> radioGroup = (RadioGroup<BeanWithOrderedFields>) tester .getComponentFromLastRenderedPage(path("tableForm:radioGroup")); /* * radio button of first row. Holds the first * BeanWithOrderedFields of the List supplied * to the DataTable. */ @SuppressWarnings("unchecked") Radio<BeanWithOrderedFields> radio = (Radio<BeanWithOrderedFields>) tester.getComponentFromLastRenderedPage( path("tableForm:radioGroup:listTable:body:rows:1:cells:4:cell:radioButton")); assertSame(def.getList().get(0), radio.getModelObject()); /* * Set the first object of the BeanWithOrderedFields List as the * model object of the RadioGroup. This emulates the user actually * clicking the above Radio button. */ BeanWithOrderedFields selection = def.getList().get(0); radioGroup.setModelObject(selection); BeanWithOrderedFields modelOb = radioGroup.getModelObject(); assertSame(selection, modelOb); callback.setExecuted(false); /* * We insert the values in the request parameters manually, because * the formTester.submit() will assign new ids in the path of the * radio buttons and, as a result, the AjaxEvent will fail to locate * the correct radio and retrieve the model. So, normally we would do: * * FormTester formTester = tester.newFormTester(path("tableForm")); * formTester.select("radioGroup", 0); * formTester.submit(); * * TODO: is there a way to have the ajaxevent submit the form maybe? * Having to do this in two steps is a bit counter-intuitive. * * The following line is the equivalent of having clicked the first * row radio. "radio" is the wicket:id of the radio buttons and 0 stands * for the first row. */ Map<String, String[]> map = tester.getRequest().getParameterMap(); map.put("testId:tableForm:radioGroup", new String[] { "radio0" }); tester.executeAjaxEvent(button, "onclick"); BeanWithOrderedFields modelOb2 = radioGroup.getModelObject(); assertSame(modelOb2, modelOb); assertTrue(callback.isExecuted()); assertSame(selection, def.getBeanModel().getObject()); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.DefaultQuestionPanelTest.java
License:Open Source License
@Test public void testExclusiveChoiceQuestion() { final Questionnaire questionnaire = createQuestionnaire(); CategoryAnswer previousCategoryAnswer = new CategoryAnswer(); previousCategoryAnswer.setCategoryName("1"); QuestionAnswer previousQuestionAnswer = new QuestionAnswer(); previousQuestionAnswer.setQuestionName("Q1"); previousQuestionAnswer.addCategoryAnswer(previousCategoryAnswer); final Question question = QuestionnaireFinder.getInstance(questionnaire).findQuestion("Q1"); expect(questionnaireBundleManagerMock.getBundle("HealthQuestionnaire")).andReturn(questionnaireBundleMock) .atLeastOnce();/*from w ww . java 2 s. c om*/ expect(activeQuestionnaireAdministrationServiceMock.isQuestionnaireDevelopmentMode()).andReturn(false) .atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.getComment((Question) EasyMock.anyObject())) .andReturn("").atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(0))).andReturn(previousCategoryAnswer).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(1))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(2))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(3))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(4))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(5))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(6))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(7))).andReturn(null).atLeastOnce(); activeQuestionnaireAdministrationServiceMock.deleteAnswers(question); QuestionCategory questionCategory = question.getQuestionCategories().get(1); expect(activeQuestionnaireAdministrationServiceMock.answer(question, questionCategory)) .andReturn(new CategoryAnswer()); expect(activeQuestionnaireAdministrationServiceMock.getLanguage()).andReturn(locale).anyTimes(); expect(activeQuestionnaireAdministrationServiceMock.getQuestionnaire()).andReturn(questionnaire).anyTimes(); expect(questionnaireBundleMock.getQuestionnaire()).andReturn(questionnaire).atLeastOnce(); expect(questionnaireBundleMock.getMessageSource()).andReturn(messageSource).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "label")) .andReturn(propertyKeyProvider.getPropertyKey(question, "label")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "help")) .andReturn(propertyKeyProvider.getPropertyKey(question, "help")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "specifications")) .andReturn(propertyKeyProvider.getPropertyKey(question, "specifications")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "instructions")) .andReturn(propertyKeyProvider.getPropertyKey(question, "instructions")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "caption")) .andReturn(propertyKeyProvider.getPropertyKey(question, "caption")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "categoryOrder")) .andReturn(propertyKeyProvider.getPropertyKey(question, "categoryOrder")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "media")) .andReturn(propertyKeyProvider.getPropertyKey(question, "media")).atLeastOnce(); for (QuestionCategory qCategory : question.getQuestionCategories()) { expect(questionnaireBundleMock.getPropertyKey(qCategory, "label")) .andReturn(propertyKeyProvider.getPropertyKey(qCategory, "label")).atLeastOnce(); } replay(activeInterviewServiceMock); replay(activeQuestionnaireAdministrationServiceMock); replay(questionnaireBundleManagerMock); replay(questionnaireBundleMock); tester.startPanel(new TestPanelSource() { private static final long serialVersionUID = 1L; public Panel getTestPanel(String panelId) { return new DefaultQuestionPanelMock(panelId, new Model(question)); } }); // dumpPage("testExclusiveChoiceQuestion"); // check question message resources tester.assertLabel("panel:form:content:label", "question label"); tester.assertLabel("panel:form:content:instructions", "question instructions"); tester.assertLabel("panel:form:content:caption", "question caption"); // check help toggle tester.isInvisible("panel:form:content:help"); tester.executeAjaxEvent("panel:form:content:helpToggle:link", "onclick"); tester.assertVisible("panel:form:content:help"); // check all expected radios are here tester.assertComponent("panel:form:content:content:categories", RadioGroup.class); RadioGroup radioGroup = (RadioGroup) tester .getComponentFromLastRenderedPage("panel:form:content:content:categories"); // assert radio count Assert.assertEquals(8, ComponentTesterUtils.findChildren(radioGroup, Radio.class).size()); // assert one of them is selected Assert.assertNotNull(ComponentTesterUtils.findChild(radioGroup, Radio.class, radioGroup.getModel())); // check previous answer is here (radio 1) Assert.assertEquals(radioGroup.getModel(), ComponentTesterUtils.findChildren(radioGroup, Radio.class).get(0).getDefaultModel()); // select radio 2 (the third in markup order because of the two columns) tester.executeAjaxEvent(ComponentTesterUtils.findChildren(radioGroup, Radio.class).get(2), "onchange"); radioGroup = (RadioGroup) tester.getComponentFromLastRenderedPage("panel:form:content:content:categories"); Radio radio2 = (Radio) ComponentTesterUtils.findChildren(radioGroup, Radio.class).get(2); Assert.assertEquals(radioGroup.getModelObject(), radio2.getModelObject()); verify(activeInterviewServiceMock); verify(activeQuestionnaireAdministrationServiceMock); verify(questionnaireBundleManagerMock); verify(questionnaireBundleMock); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.DefaultQuestionPanelTest.java
License:Open Source License
@Test public void testExclusiveChoiceQuestionWithOpenAnswer() { final Questionnaire questionnaire = createQuestionnaire(); CategoryAnswer previousCategoryAnswer = new CategoryAnswer(); previousCategoryAnswer.setCategoryName("DONT_KNOW"); QuestionAnswer previousQuestionAnswer = new QuestionAnswer(); previousQuestionAnswer.setQuestionName("Q2"); previousQuestionAnswer.addCategoryAnswer(previousCategoryAnswer); final Question question = QuestionnaireFinder.getInstance(questionnaire).findQuestion("Q2"); OpenAnswerDefinition open = QuestionnaireFinder.getInstance(questionnaire) .findOpenAnswerDefinition("OPEN_INT"); expect(questionnaireBundleManagerMock.getBundle("HealthQuestionnaire")).andReturn(questionnaireBundleMock) .atLeastOnce();/*w ww . j a va 2s . c om*/ expect(questionnaireBundleMock.getQuestionnaire()).andReturn(questionnaire).anyTimes(); expect(activeQuestionnaireAdministrationServiceMock.isQuestionnaireDevelopmentMode()).andReturn(false) .atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.getQuestionnaireParticipant()) .andReturn(questionnaireParticipant).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.getComment((Question) EasyMock.anyObject())) .andReturn("").atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findOpenAnswer(question, question.getCategories().get(0), open)).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findActiveAnswers(question)) .andReturn(Arrays.asList(new CategoryAnswer[] { previousCategoryAnswer })); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(0))).andReturn(null); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(1))).andReturn(previousCategoryAnswer).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(2))).andReturn(null).atLeastOnce(); activeQuestionnaireAdministrationServiceMock.deleteAnswers(previousCategoryAnswer); QuestionCategory questionCategory = question.getQuestionCategories().get(0); expect(activeQuestionnaireAdministrationServiceMock.answer(question, questionCategory, questionCategory.getCategory().getOpenAnswerDefinition(), DataBuilder.buildInteger(1l))) .andReturn(new CategoryAnswer()); expect(activeQuestionnaireAdministrationServiceMock.getLanguage()).andReturn(locale).anyTimes(); expect(activeQuestionnaireAdministrationServiceMock.getQuestionnaire()).andReturn(questionnaire).anyTimes(); expect(questionnaireBundleMock.getMessageSource()).andReturn(messageSource).anyTimes(); expect(questionnaireBundleMock.getPropertyKey(question, "label")) .andReturn(propertyKeyProvider.getPropertyKey(question, "label")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "help")) .andReturn(propertyKeyProvider.getPropertyKey(question, "help")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "instructions")) .andReturn(propertyKeyProvider.getPropertyKey(question, "instructions")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "specifications")) .andReturn(propertyKeyProvider.getPropertyKey(question, "specifications")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "caption")) .andReturn(propertyKeyProvider.getPropertyKey(question, "caption")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "categoryOrder")) .andReturn(propertyKeyProvider.getPropertyKey(question, "categoryOrder")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "media")) .andReturn(propertyKeyProvider.getPropertyKey(question, "media")).atLeastOnce(); for (QuestionCategory qCategory : question.getQuestionCategories()) { expect(questionnaireBundleMock.getPropertyKey(qCategory, "label")) .andReturn(propertyKeyProvider.getPropertyKey(qCategory, "label")).atLeastOnce(); } expect(questionnaireBundleMock.getPropertyKey(open, "label")) .andReturn(propertyKeyProvider.getPropertyKey(open, "label")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(open, "unitLabel")) .andReturn(propertyKeyProvider.getPropertyKey(open, "unitLabel")).atLeastOnce(); replay(activeInterviewServiceMock); replay(activeQuestionnaireAdministrationServiceMock); replay(questionnaireBundleManagerMock); replay(questionnaireBundleMock); tester.startPanel(new TestPanelSource() { private static final long serialVersionUID = 1L; public Panel getTestPanel(String panelId) { return new DefaultQuestionPanelMock(panelId, new Model(question)); } }); // tester.dumpPage(); RadioGroup radioGroup = (RadioGroup) tester .getComponentFromLastRenderedPage("panel:form:content:content:categories"); // assert radio count Assert.assertEquals(3, ComponentTesterUtils.findChildren(radioGroup, Radio.class).size()); // assert one of them is selected Assert.assertNotNull(ComponentTesterUtils.findChild(radioGroup, Radio.class, radioGroup.getModel())); // check previous answer is here (radio 2) Radio radio2 = (Radio) ComponentTesterUtils.findChildren(radioGroup, Radio.class).get(1); Assert.assertEquals(radioGroup.getModel(), radio2.getModel()); FormComponent field = (FormComponent) ComponentTesterUtils.findChildren(radioGroup, TextField.class).get(0); // select open field FormTester formTester = tester.newFormTester("panel:form"); formTester.setValue("content:content:categories:category:1:cols:2:input:open:open:input:field", "1"); tester.executeAjaxEvent(field, "onchange"); radioGroup = (RadioGroup) tester.getComponentFromLastRenderedPage("panel:form:content:content:categories"); Radio radio1 = (Radio) ComponentTesterUtils.findChildren(radioGroup, Radio.class).get(0); Assert.assertEquals(radioGroup.getModelObject(), radio1.getModelObject()); verify(activeInterviewServiceMock); verify(activeQuestionnaireAdministrationServiceMock); verify(questionnaireBundleManagerMock); verify(questionnaireBundleMock); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.DefaultQuestionPanelTest.java
License:Open Source License
@Test public void testExclusiveChoiceQuestionWithMultipleOpenAnswer() { final Questionnaire questionnaire = createQuestionnaire(); CategoryAnswer previousCategoryAnswer = new CategoryAnswer(); previousCategoryAnswer.setCategoryName("DONT_KNOW"); QuestionAnswer previousQuestionAnswer = new QuestionAnswer(); previousQuestionAnswer.setQuestionName("MULTIPLE_OPEN"); previousQuestionAnswer.addCategoryAnswer(previousCategoryAnswer); final Question question = QuestionnaireFinder.getInstance(questionnaire).findQuestion("MULTIPLE_OPEN"); OpenAnswerDefinition openHours = QuestionnaireFinder.getInstance(questionnaire) .findOpenAnswerDefinition("DURATION_OPEN_HOURS"); OpenAnswerDefinition openMinutes = QuestionnaireFinder.getInstance(questionnaire) .findOpenAnswerDefinition("DURATION_OPEN_MINUTES"); expect(questionnaireBundleManagerMock.getBundle("HealthQuestionnaire")).andReturn(questionnaireBundleMock) .atLeastOnce();/* w w w . ja va 2s. c o m*/ expect(questionnaireBundleMock.getQuestionnaire()).andReturn(questionnaire).anyTimes(); expect(activeQuestionnaireAdministrationServiceMock.isQuestionnaireDevelopmentMode()).andReturn(false) .atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.getQuestionnaireParticipant()) .andReturn(questionnaireParticipant).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findOpenAnswer(question, question.getCategories().get(0), openHours)).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findOpenAnswer(question, question.getCategories().get(0), openMinutes)).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findActiveAnswers(question)) .andReturn(Arrays.asList(new CategoryAnswer[] { previousCategoryAnswer })); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(0))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(1))).andReturn(previousCategoryAnswer).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question, question.getQuestionCategories().get(2))).andReturn(null).atLeastOnce(); activeQuestionnaireAdministrationServiceMock.deleteAnswers(previousCategoryAnswer); QuestionCategory questionCategory = question.getQuestionCategories().get(0); expect(activeQuestionnaireAdministrationServiceMock.getComment((Question) EasyMock.anyObject())) .andReturn("").atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.answer(question, questionCategory, questionCategory.getCategory().getOpenAnswerDefinition().getOpenAnswerDefinitions().get(0), DataBuilder.buildInteger(1l))).andReturn(new CategoryAnswer()); expect(activeQuestionnaireAdministrationServiceMock.getLanguage()).andReturn(locale).anyTimes(); expect(activeQuestionnaireAdministrationServiceMock.getQuestionnaire()).andReturn(questionnaire).anyTimes(); expect(questionnaireBundleMock.getMessageSource()).andReturn(messageSource).anyTimes(); expect(questionnaireBundleMock.getPropertyKey(question, "label")) .andReturn(propertyKeyProvider.getPropertyKey(question, "label")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "help")) .andReturn(propertyKeyProvider.getPropertyKey(question, "help")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "instructions")) .andReturn(propertyKeyProvider.getPropertyKey(question, "instructions")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "specifications")) .andReturn(propertyKeyProvider.getPropertyKey(question, "specifications")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "caption")) .andReturn(propertyKeyProvider.getPropertyKey(question, "caption")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "categoryOrder")) .andReturn(propertyKeyProvider.getPropertyKey(question, "categoryOrder")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "media")) .andReturn(propertyKeyProvider.getPropertyKey(question, "media")).atLeastOnce(); for (QuestionCategory qCategory : question.getQuestionCategories()) { expect(questionnaireBundleMock.getPropertyKey(qCategory, "label")) .andReturn(propertyKeyProvider.getPropertyKey(qCategory, "label")).atLeastOnce(); } expect(questionnaireBundleMock.getPropertyKey(openHours, "label")) .andReturn(propertyKeyProvider.getPropertyKey(openHours, "label")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(openHours, "unitLabel")) .andReturn(propertyKeyProvider.getPropertyKey(openHours, "unitLabel")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(openMinutes, "label")) .andReturn(propertyKeyProvider.getPropertyKey(openMinutes, "label")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(openMinutes, "unitLabel")) .andReturn(propertyKeyProvider.getPropertyKey(openMinutes, "unitLabel")).atLeastOnce(); replay(activeInterviewServiceMock); replay(activeQuestionnaireAdministrationServiceMock); replay(questionnaireBundleManagerMock); replay(questionnaireBundleMock); tester.startPanel(new TestPanelSource() { private static final long serialVersionUID = 1L; @SuppressWarnings("serial") public Panel getTestPanel(String panelId) { return new DefaultQuestionPanelMock(panelId, new Model(question)); } }); // dumpPage("testExclusiveChoiceQuestionWithMultipleOpenAnswer"); RadioGroup radioGroup = (RadioGroup) tester .getComponentFromLastRenderedPage("panel:form:content:content:categories"); // assert radio count Assert.assertEquals(3, ComponentTesterUtils.findChildren(radioGroup, Radio.class).size()); // assert one of them is selected Assert.assertNotNull(ComponentTesterUtils.findChild(radioGroup, Radio.class, radioGroup.getModel())); // check previous answer is here (radio 2) Radio radio2 = (Radio) ComponentTesterUtils.findChildren(radioGroup, Radio.class).get(1); Assert.assertEquals(radioGroup.getModel(), radio2.getModel()); FormComponent field1 = (FormComponent) ComponentTesterUtils.findChildren(radioGroup, TextField.class) .get(0); // select open field FormTester formTester = tester.newFormTester("panel:form"); formTester.setValue( "content:content:categories:category:1:cols:2:input:open:repeating:1:open:open:input:field", "1"); tester.executeAjaxEvent(field1, "onchange"); radioGroup = (RadioGroup) tester.getComponentFromLastRenderedPage("panel:form:content:content:categories"); Radio radio1 = (Radio) ComponentTesterUtils.findChildren(radioGroup, Radio.class).get(0); Assert.assertEquals(radioGroup.getModelObject(), radio1.getModelObject()); verify(activeInterviewServiceMock); verify(activeQuestionnaireAdministrationServiceMock); verify(questionnaireBundleManagerMock); verify(questionnaireBundleMock); }
From source file:org.obiba.onyx.quartz.core.wicket.layout.impl.standard.DefaultQuestionPanelTest.java
License:Open Source License
@Test public void testSharedCategoriesArrayQuestion() { final Questionnaire questionnaire = createQuestionnaire(); CategoryAnswer previousCategoryAnswer = new CategoryAnswer(); previousCategoryAnswer.setCategoryName("1"); QuestionAnswer previousQuestionAnswer = new QuestionAnswer(); previousQuestionAnswer.setQuestionName("Q3_1"); previousQuestionAnswer.addCategoryAnswer(previousCategoryAnswer); final Question question = QuestionnaireFinder.getInstance(questionnaire).findQuestion("Q3"); Question question1 = QuestionnaireFinder.getInstance(questionnaire).findQuestion("Q3_1"); Question question2 = QuestionnaireFinder.getInstance(questionnaire).findQuestion("Q3_2"); expect(questionnaireBundleManagerMock.getBundle("HealthQuestionnaire")).andReturn(questionnaireBundleMock) .atLeastOnce();//from w w w . j av a 2 s.co m expect(activeQuestionnaireAdministrationServiceMock.isQuestionnaireDevelopmentMode()).andReturn(false) .atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.getComment((Question) EasyMock.anyObject())) .andReturn("").atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.getQuestionnaireParticipant()) .andReturn(questionnaireParticipant).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findActiveAnswers(question1)) .andReturn(Arrays.asList(new CategoryAnswer[] { previousCategoryAnswer })); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question1, question.getQuestionCategories().get(0))).andReturn(previousCategoryAnswer).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question1, question.getQuestionCategories().get(1))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question1, question.getQuestionCategories().get(2))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findOpenAnswer(question1, question.getCategories().get(2), question.getCategories().get(2).getOpenAnswerDefinition())) .andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question2, question.getQuestionCategories().get(0))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question2, question.getQuestionCategories().get(1))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findAnswer(question2, question.getQuestionCategories().get(2))).andReturn(null).atLeastOnce(); expect(activeQuestionnaireAdministrationServiceMock.findOpenAnswer(question2, question.getCategories().get(2), question.getCategories().get(2).getOpenAnswerDefinition())) .andReturn(null).atLeastOnce(); activeQuestionnaireAdministrationServiceMock.deleteAnswers(previousCategoryAnswer); expect(activeQuestionnaireAdministrationServiceMock.answer(question1, question.getQuestionCategories().get(2), question.getCategories().get(2).getOpenAnswerDefinition(), null)).andReturn(new CategoryAnswer()); expect(activeQuestionnaireAdministrationServiceMock.getLanguage()).andReturn(locale).anyTimes(); expect(activeQuestionnaireAdministrationServiceMock.getQuestionnaire()).andReturn(questionnaire).anyTimes(); expect(questionnaireBundleMock.getQuestionnaire()).andReturn(questionnaire).anyTimes(); expect(questionnaireBundleMock.getMessageSource()).andReturn(messageSource).anyTimes(); expect(questionnaireBundleMock.getPropertyKey(question, "label")) .andReturn(propertyKeyProvider.getPropertyKey(question, "label")).anyTimes(); expect(questionnaireBundleMock.getPropertyKey(question, "help")) .andReturn(propertyKeyProvider.getPropertyKey(question, "help")).anyTimes(); expect(questionnaireBundleMock.getPropertyKey(question, "instructions")) .andReturn(propertyKeyProvider.getPropertyKey(question, "instructions")).anyTimes(); expect(questionnaireBundleMock.getPropertyKey(question, "specifications")) .andReturn(propertyKeyProvider.getPropertyKey(question, "specifications")).anyTimes(); expect(questionnaireBundleMock.getPropertyKey(question, "caption")) .andReturn(propertyKeyProvider.getPropertyKey(question, "caption")).anyTimes(); expect(questionnaireBundleMock.getPropertyKey(question, "categoryOrder")) .andReturn(propertyKeyProvider.getPropertyKey(question, "categoryOrder")).atLeastOnce(); expect(questionnaireBundleMock.getPropertyKey(question, "media")) .andReturn(propertyKeyProvider.getPropertyKey(question, "media")).atLeastOnce(); for (QuestionCategory qCategory : question.getQuestionCategories()) { expect(questionnaireBundleMock.getPropertyKey(qCategory, "label")) .andReturn(propertyKeyProvider.getPropertyKey(qCategory, "label")).anyTimes(); if (qCategory.getCategory().getOpenAnswerDefinition() != null) { expect(questionnaireBundleMock.getPropertyKey(qCategory.getCategory().getOpenAnswerDefinition(), "label")) .andReturn(propertyKeyProvider .getPropertyKey(qCategory.getCategory().getOpenAnswerDefinition(), "label")) .anyTimes(); expect(questionnaireBundleMock.getPropertyKey(qCategory.getCategory().getOpenAnswerDefinition(), "unitLabel")) .andReturn(propertyKeyProvider.getPropertyKey( qCategory.getCategory().getOpenAnswerDefinition(), "unitLabel")) .anyTimes(); } } for (Question q : question.getQuestions()) { expect(questionnaireBundleMock.getPropertyKey(q, "label")) .andReturn(propertyKeyProvider.getPropertyKey(q, "label")).anyTimes(); } replay(activeInterviewServiceMock); replay(activeQuestionnaireAdministrationServiceMock); replay(questionnaireBundleManagerMock); replay(questionnaireBundleMock); tester.startPanel(new TestPanelSource() { private static final long serialVersionUID = 1L; @SuppressWarnings("serial") public Panel getTestPanel(String panelId) { return new DefaultQuestionPanelMock(panelId, new Model(question)); } }); // dumpPage("testSharedCategoriesArrayQuestion"); // tester.getComponentFromLastRenderedPage("panel:form:content:content:array:headers:2:header:label"); tester.assertLabel("panel:form:content:content:array:headers:2:header:label", "Choice one"); tester.assertLabel("panel:form:content:content:array:headers:3:header:label", "Choice two"); tester.assertLabel("panel:form:content:content:array:headers:4:header:label", "Choice three"); // check row labels as to be child question labels tester.assertLabel("panel:form:content:content:array:rows:rows:1:group:cells:1:cell", "question3-1 label"); tester.assertLabel("panel:form:content:content:array:rows:rows:2:group:cells:1:cell", "question3-2 label"); // check all expected radios are here tester.assertComponent("panel:form:content:content:array:rows:rows:1:group", RadioGroup.class); tester.assertComponent( "panel:form:content:content:array:rows:rows:1:group:cells:2:cell:categoryLabel:radio", Radio.class); tester.assertComponent( "panel:form:content:content:array:rows:rows:1:group:cells:3:cell:categoryLabel:radio", Radio.class); tester.assertComponent( "panel:form:content:content:array:rows:rows:1:group:cells:4:cell:categoryLabel:radio", Radio.class); tester.assertComponent("panel:form:content:content:array:rows:rows:2:group", RadioGroup.class); tester.assertComponent( "panel:form:content:content:array:rows:rows:2:group:cells:2:cell:categoryLabel:radio", Radio.class); tester.assertComponent( "panel:form:content:content:array:rows:rows:2:group:cells:3:cell:categoryLabel:radio", Radio.class); tester.assertComponent( "panel:form:content:content:array:rows:rows:2:group:cells:4:cell:categoryLabel:radio", Radio.class); tester.assertLabel("panel:form:content:content:array:rows:rows:1:group:cells:4:cell:open:label", "Open three"); tester.assertComponent("panel:form:content:content:array:rows:rows:1:group:cells:4:cell:open:open", DataField.class); // check previous answer is here (radio 1.1) RadioGroup radioGroup = (RadioGroup) tester .getComponentFromLastRenderedPage("panel:form:content:content:array:rows:rows:1:group"); Radio radio11 = (Radio) tester.getComponentFromLastRenderedPage( "panel:form:content:content:array:rows:rows:1:group:cells:2:cell:categoryLabel:radio"); Assert.assertEquals(radioGroup.getModelObject(), radio11.getModelObject()); // select open field FormComponent field = (FormComponent) ComponentTesterUtils.findChildren(radioGroup, TextField.class).get(0); field.setModel(new Model("1")); tester.executeAjaxEvent(field, "onchange"); radioGroup = (RadioGroup) tester .getComponentFromLastRenderedPage("panel:form:content:content:array:rows:rows:1:group"); Radio radio13 = (Radio) tester.getComponentFromLastRenderedPage( "panel:form:content:content:array:rows:rows:1:group:cells:4:cell:categoryLabel:radio"); Assert.assertEquals(radioGroup.getModelObject(), radio13.getModelObject()); verify(activeInterviewServiceMock); verify(activeQuestionnaireAdministrationServiceMock); verify(questionnaireBundleManagerMock); verify(questionnaireBundleMock); }