Untitled
unknown
plain_text
3 years ago
4.5 kB
6
Indexable
package pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.domain
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.boot.test.context.TestConfiguration
import pt.ulisboa.tecnico.socialsoftware.tutor.BeanConfiguration
import pt.ulisboa.tecnico.socialsoftware.tutor.SpockTest
import pt.ulisboa.tecnico.socialsoftware.tutor.question.domain.Course
import pt.ulisboa.tecnico.socialsoftware.tutor.question.domain.Question
import pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.domain.QuestionStats
import pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.domain.TeacherDashboard
import pt.ulisboa.tecnico.socialsoftware.tutor.user.domain.Teacher
@DataJpaTest
class NumAvailableTest extends SpockTest {
def teacher
def teacherDashboard
def setup() {
createExternalCourseAndExecution()
teacher = new Teacher(USER_1_NAME, false)
userRepository.save(teacher)
teacherDashboard = new TeacherDashboard(externalCourseExecution, teacher)
teacherDashboardRepository.save(teacherDashboard)
def course = new Course(COURSE_1_NAME, Course.Type.TECNICO)
courseRepository.save(course)
externalCourseExecution.setCourse(course)
}
def createQuestionStatsAndPersist() {
def questionStats = new QuestionStats(externalCourseExecution, teacherDashboard)
questionStatsRepository.save(questionStats)
return questionStats
}
def createCourseAndPersist() {
def course = new Course(COURSE_1_NAME, Course.Type.TECNICO)
courseRepository.save(course)
externalCourseExecution.setCourse(course)
return course
}
def "create an empty Question Stats"() {
when: "a new Question Stats is created"
def questionStats = createQuestionStatsAndPersist()
then: "the new question stats is correctly persisted"
questionStatsRepository.count() == 1L
def result = questionStatsRepository.findAll().get(0)
result.getId() != 0
result.getCourseExecution().getId() == externalCourseExecution.getId()
result.getTeacherDashboard().getId() == teacherDashboard.getId()
}
def "Check numAvailable with zero questions"() {
given:
def course = createCourseAndPersist()
when:
def questionStats = new QuestionStats(externalCourseExecution,teacherDashboard)
questionStats.update()
then:
questionStats.getNumAvailable() == 0
}
def "Creation of one question available"() {
given:
def course = createCourseAndPersist()
Question question = new Question()
question.setKey(1)
question.setStatus(Question.Status.AVAILABLE)
question.setCourse(externalCourse)
question.setTitle(QUESTION_1_TITLE)
course.addQuestion(question)
when:
def questionStats = new QuestionStats(externalCourseExecution,teacherDashboard)
questionStats.update()
then:
questionStats.getCourseExecution() == externalCourseExecution
questionStats.getNumAvailable() == 1
and: "disable one test and see if getNum updates"
question.setStatus(Question.Status.DISABLED)
questionStats.update()
questionStats.getNumAvailable() == 0
}
def "Creation of two questions available"() {
given:
def course = createCourseAndPersist()
Question question = new Question()
question.setKey(1)
question.setStatus(Question.Status.AVAILABLE)
question.setCourse(externalCourse)
question.setTitle(QUESTION_1_TITLE)
Question question2 = new Question()
question2.setKey(2)
question2.setStatus(Question.Status.AVAILABLE)
question2.setCourse(externalCourse)
question2.setTitle(QUESTION_2_TITLE)
course.addQuestion(question)
course.addQuestion(question2)
externalCourseExecution.setCourse(course)
when:
def questionStats = new QuestionStats(externalCourseExecution,teacherDashboard)
questionStats.update()
then:
questionStats.getCourseExecution() == externalCourseExecution
questionStats.getNumAvailable() == 2
}
@TestConfiguration
static class LocalBeanConfiguration extends BeanConfiguration {}
}Editor is loading...