Untitled
unknown
plain_text
3 years ago
4.5 kB
10
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.exceptions.ErrorMessage
import pt.ulisboa.tecnico.socialsoftware.tutor.exceptions.TutorException
import pt.ulisboa.tecnico.socialsoftware.tutor.teacherdashboard.domain.StudentStats
import pt.ulisboa.tecnico.socialsoftware.tutor.user.domain.Teacher
import pt.ulisboa.tecnico.socialsoftware.tutor.user.domain.Student
import pt.ulisboa.tecnico.socialsoftware.tutor.execution.domain.CourseExecution
import pt.ulisboa.tecnico.socialsoftware.tutor.question.domain.Course
import pt.ulisboa.tecnico.socialsoftware.tutor.auth.domain.AuthUser
import spock.lang.Unroll
@DataJpaTest
class numStudentStatsTest extends SpockTest {
def teacherDashboard
def teacher
def student
def studentStats
def setup() {
createExternalCourseAndExecution()
teacher = new Teacher(USER_1_NAME, false)
userRepository.save(teacher)
}
def createTeacherDashboardAndPersist() {
teacherDashboard = new TeacherDashboard(externalCourseExecution, teacher)
teacherDashboardRepository.save(teacherDashboard)
return teacherDashboard
}
def createActiveStudent() {
student = new Student(USER_1_NAME, USER_1_USERNAME, USER_1_EMAIL, false, AuthUser.Type.TECNICO)
userRepository.save(student)
return student
}
def createInactiveStudent() {
student = new Student(USER_1_NAME, USER_1_USERNAME, USER_1_EMAIL, false, AuthUser.Type.EXTERNAL)
userRepository.save(student)
return student
}
def createStudentStats() {
studentStats = new StudentStats(externalCourseExecution, teacherDashboard)
studentStatsRepository.save(studentStats)
return studentStats
}
def "confirms if the course execution and teacher dashboard are correctly createad"() {
given: "an empty dashboard for the teacher"
teacherDashboard = createTeacherDashboardAndPersist()
when: "a StudentStats is created"
studentStats = createStudentStats()
then: "verifies if the values match"
externalCourseExecution == studentStats.getCourseExecution()
teacherDashboard == studentStats.getTeacherDashboard()
}
def "tests if course execution is empty"() {
given: "an empty dashboard for the teacher"
teacherDashboard = createTeacherDashboardAndPersist()
when: "a StudentStats is created"
studentStats = createStudentStats()
studentStats.setNumStudents()
then: "verifies if the values match"
studentStats.getNumStudents() == 0
}
def "confirms if student is added to a course execution"() {
given: "an empty dashboard for the teacher"
teacherDashboard = createTeacherDashboardAndPersist()
when: "a StudentStats is created"
studentStats = createStudentStats()
def previousNumberOfStudents = externalCourseExecution.getNumberOfActiveStudents()
and: "a student is added to the course execution"
student = createActiveStudent()
externalCourseExecution.addUser(student)
studentStats.update()
then: "verifies if the values match"
studentStats.getNumStudents() == previousNumberOfStudents + 1
}
def "confirms that an inactive student doesn't increase the number of active students of a course execution"() {
given: "an empty dashboard for the teacher"
teacherDashboard = createTeacherDashboardAndPersist()
when: "a StudentStats is created"
studentStats = createStudentStats()
def previousNumberOfStudents = externalCourseExecution.getNumberOfActiveStudents()
and: "a student is added to the course execution"
student = createInactiveStudent()
externalCourseExecution.addUser(student)
studentStats.setNumStudents()
then: "verifies if the values match"
studentStats.getNumStudents() == previousNumberOfStudents
}
@TestConfiguration
static class LocalBeanConfiguration extends BeanConfiguration {}
}
Editor is loading...