List of usage examples for org.apache.wicket.markup.html.basic MultiLineLabel getDefaultModelObjectAsString
public final String getDefaultModelObjectAsString()
From source file:org.obiba.onyx.webapp.participant.panel.CommentsModalPanelTest.java
License:Open Source License
/** * Tests that all types of comments -- general and stage -- are displayed in the Previous Comments section, ordered by * date (most recent first).//from ww w .j av a2s.co m */ @SuppressWarnings("serial") @Test public void testCommentsDisplayedMostRecentFirst() { User user = createUser(); Interview interview = createInterview(1l); Stage stage = createStage("marble", "CON"); Participant participant = createParticipant(1l, "Suzan", "Tremblay"); String generalComment = "general comment"; String stageComment = "stage execute comment"; Date now = new Date(); Date oneHourAgo = new Date(now.getTime() - 1000 * 60 * 60); // // Create a list of two comments for this test, ordered by date (most recent first). // // NOTE: The order corresponds to the expected order of comments returned by // ActiveInterviewService.getInterviewComments(). // List<Action> commentActions = new ArrayList<Action>(); commentActions.add(createStageComment(user, interview, stage, ActionType.EXECUTE, now, stageComment)); commentActions.add(createGeneralComment(user, interview, oneHourAgo, generalComment)); // Expect that UserSessionService.getLocale() is called, and return locale "en". expect(userSessionServiceMock.getLocale()).andReturn(new Locale("en")); expectLastCall().anyTimes(); // We can't mock ModuleRegistry, so we'll create a mock Module instance and register that in the ModuleRegistry... // This allows us to expect that ModuleRegistry.getStage() is called, and return the proper Stage instance Module mockModule = createMock(Module.class); expect(mockModule.getStages()).andReturn(Collections.singletonList(stage)); expectLastCall().anyTimes(); expect(mockModule.getName()).andReturn("MockModule"); expectLastCall().anyTimes(); // Expect that CommentsModalPanel calls ActiveInterviewService.getInterviewComments() // to retrieve all comments related to the current interview, and return the test comments. expect(activeInterviewServiceMock.getInterviewComments()).andReturn(commentActions); // Expect that CommentsModalPanel calls ActiveInterviewService.getParticipant() to // retrieve the participant currently being interviewed, and return the test participant. expect(activeInterviewServiceMock.getParticipant()).andReturn(participant); replay(userSessionServiceMock); replay(mockModule); replay(activeInterviewServiceMock); moduleRegistry.registerModule(mockModule); tester.startPanel(new TestPanelSource() { public Panel getTestPanel(String panelId) { return commentsModalPanel = new CommentsModalPanel(panelId, new ModalWindow("bogus"), null) { @Override public void onAddComments(AjaxRequestTarget target) { // do nothing } }; } }); verify(userSessionServiceMock); verify(mockModule); verify(activeInterviewServiceMock); // // Get a reference to the FIRST comment panel and verify that it contains the most // recent comment -- i.e., the stage comment. // // NOTE: In the current user interface, the comment string is contained in the FOURTH row // of the comment panel. // KeyValueDataPanel commentPanel = (KeyValueDataPanel) commentsModalPanel .get("previousComments:comment-list:1:comment-panel"); Assert.assertNotNull(commentPanel); MultiLineLabel commentLabel = (MultiLineLabel) commentPanel .get("repeating:5:" + KeyValueDataPanel.getRowValueId()); Assert.assertNotNull(commentLabel); Assert.assertEquals(stageComment, commentLabel.getDefaultModelObjectAsString()); // // Now get a reference to the SECOND comment panel and verify that it contains the // earlier comment -- i.e., the general comment. // commentPanel = (KeyValueDataPanel) commentsModalPanel.get("previousComments:comment-list:2:comment-panel"); Assert.assertNotNull(commentPanel); commentLabel = (MultiLineLabel) commentPanel.get("repeating:5:" + KeyValueDataPanel.getRowValueId()); Assert.assertNotNull(commentLabel); Assert.assertEquals(generalComment, commentLabel.getDefaultModelObjectAsString()); }