+ /**
+ * Test of retrieval of all comments corresponding to a step.
+ *
+ * @throws BusinessException if there is something wrong likely unrelated to the tested method
+ */
+ @Test
+ public void testEditStepComments() throws BusinessException {
+ LOG.debug(">>>>> BEGIN testEditStepComments()");
+ startNestedTransaction();
+
+ User goodUser = TestEntitiesGenerator.getTestUser("goodUser");
+ _userDAO.create(goodUser);
+ Study goodStudy = TestEntitiesGenerator.getTestStudy(goodUser);
+ _studyDAO.create(goodStudy);
+ getHibernateTemplate().flush();
+
+ org.splat.som.Step step = new org.splat.som.Step(_projectSettings.getStep(1), goodStudy);
+
+ StepCommentAttribute comment = new StepCommentAttribute(goodStudy, "commentValue",
+ new Date(), Integer.valueOf(step.getNumber()), goodUser, "commentTitle");
+ _stepCommentAttributeDAO.saveOrUpdate(comment);
+
+ getHibernateTemplate().flush();
+
+ //non-existing id
+ StepCommentAttribute tmpComment = new StepCommentAttribute(goodStudy,"tmpCommentValue",
+ new Date(), Integer.valueOf(step.getNumber()), goodUser, "tmpCommentTitle");
+ _stepCommentAttributeDAO.create(tmpComment);
+ long nonExistingId = tmpComment.getIndex();
+ _stepCommentAttributeDAO.delete(tmpComment);
+ //getHibernateTemplate().evict(goodUser);
+
+
+ try{
+ _stepService.editStepComment(nonExistingId, "newValue", "newTitle");
+ getHibernateTemplate().flush();
+ Assert.fail("Creation with non-existing user must be failed.");
+ }
+ catch(InvalidParameterException e){
+ LOG.debug("Expected exception is thrown: "
+ + e.getClass().getSimpleName() + ": " + e.getMessage());
+ }
+
+ //different configurations with valid comment id
+ testEdit(comment, "newValue", null);
+ testEdit(comment, null, "newTitle");
+ testEdit(comment, "veryNewValue", "veryNewTitle");
+
+ rollbackNestedTransaction();
+ LOG.debug(">>>>> END testEditStepComments()");
+ }
+
+ /**
+ * Test of comment editing.
+ * @param comment the comment
+ * @param value the value
+ * @param title the title
+ * @throws InvalidParameterException if there is something wrong likely unrelated to the tested method
+ */
+ private void testEdit(StepCommentAttribute comment, String value, String title)
+ throws InvalidParameterException {
+ String oldValue = comment.getValue();
+ String oldTitle = comment.getTitle();
+
+ _stepService.editStepComment(comment.getIndex(), value, title);
+ _stepCommentAttributeDAO.flush();
+ getHibernateTemplate().evict(comment);
+ _stepCommentAttributeDAO.refresh(comment);
+ if(value == null) {
+ Assert.assertEquals(comment.getValue(), oldValue);
+ } else {
+ Assert.assertEquals(comment.getValue(), value);
+ }
+ if(title == null) {
+ Assert.assertEquals(comment.getTitle(), oldTitle);
+ } else {
+ Assert.assertEquals(comment.getTitle(), title);
+ }
+ }
+
+