@Test @Rollback @Transactional(propagation = Propagation.REQUIRES_NEW) public void shouldCreateANewQuestionFromExistingVariable() { Question question = new Question(); question.setValue("Test Question (timestamp:" + new Date().toString() + ")"); question.setVariable(new Variable(30l)); question.getOptions().add(new Methodology(1l)); question.getOptions().add(new Methodology(2l)); question.getOptions().add(new Methodology(3l)); question = (Question) simpleDAO.save(question); assertNotNull(question.getId()); Question savedQuestion = (Question) simpleDAO .createCriteria(Question.class) .add(Restrictions.eq("value", question.getValue())) .uniqueResult(); assertEquals(question, savedQuestion); assertFalse(savedQuestion.getOptions().isEmpty()); simpleDAO.delete(savedQuestion); Question deletedQuestion = (Question) simpleDAO.load(Question.class, savedQuestion.getId()); assertNull(deletedQuestion); }
@Test @Rollback @Transactional(propagation = Propagation.REQUIRES_NEW) public void shouldFailTryingToCreateANewQuestionFromNonExistingVariable() { Question question = new Question(); question.setValue("Test Question (timestamp:" + new Date().toString() + ")"); question.setVariable(new Variable(101201l)); question = (Question) simpleDAO.save(question); }
@Test @Transactional(readOnly = true) @SuppressWarnings("unchecked") public void shouldGetQuestionsListing() { List<Question> questions = simpleDAO.createCriteria(Question.class).list(); assertNotNull(questions); assertFalse(questions.isEmpty()); for (Question question : questions) { assertNotNull(question.getValue()); assertNotNull(question.getVariable()); assertNotNull(question.getVariable().getName()); assertNotNull(question.getOptions()); assertNotNull(question.getHint()); assertFalse(question.getOptions().isEmpty()); } }