@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); }