package com.vst.dao;
import java.util.List;
import com.vst.dao.BaseDaoTestCase;
import com.vst.model.Question;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.orm.ObjectRetrievalFailureException;
public class QuestionDaoTest extends BaseDaoTestCase {
private Integer questionId = new Integer("1");
private QuestionDao dao = null;
public void setQuestionDao(QuestionDao dao) {
this.dao = dao;
}
public void testAddQuestion() throws Exception {
Question question = new Question();
// set required fields
dao.saveQuestion(question);
// verify a primary key was assigned
assertNotNull(question.getQuestionId());
// verify set fields are same after save
}
public void testGetQuestion() throws Exception {
Question question = dao.getQuestion(questionId);
assertNotNull(question);
}
public void testGetQuestions() throws Exception {
Question question = new Question();
List results = dao.getQuestions(question);
assertTrue(results.size() > 0);
}
public void testSaveQuestion() throws Exception {
Question question = dao.getQuestion(questionId);
// update required fields
dao.saveQuestion(question);
}
public void testRemoveQuestion() throws Exception {
Integer removeId = new Integer("3");
dao.removeQuestion(removeId);
try {
dao.getQuestion(removeId);
fail("question found in database");
} catch (ObjectRetrievalFailureException e) {
assertNotNull(e.getMessage());
} catch (InvalidDataAccessApiUsageException e) { // Spring 2.0 throws this one
assertNotNull(e.getMessage());
}
}
}