Skip to content

Commit

Permalink
[#12048] Add deep comparison for entities in verifyEquals for E2E (#…
Browse files Browse the repository at this point in the history
…12892)

* Add base for verifyEquals for all entities

* Remove branches with missing EntityData class

* Add comparison for response details JSON string

* Fix lint errors

* Fix lint errors

* Update method to compare feedbackquestion and response details by JSON string
  • Loading branch information
domlimm authored Mar 18, 2024
1 parent 2eedf1d commit ddd6f09
Showing 1 changed file with 122 additions and 9 deletions.
131 changes: 122 additions & 9 deletions src/test/java/teammates/test/BaseTestCaseWithSqlDatabaseAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@
import teammates.common.datatransfer.SqlDataBundle;
import teammates.common.datatransfer.questions.FeedbackQuestionDetails;
import teammates.common.datatransfer.questions.FeedbackResponseDetails;
import teammates.storage.sqlentity.Account;
import teammates.storage.sqlentity.BaseEntity;
import teammates.storage.sqlentity.Course;
import teammates.storage.sqlentity.DeadlineExtension;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.FeedbackResponseComment;
import teammates.storage.sqlentity.FeedbackSession;
import teammates.storage.sqlentity.Instructor;
import teammates.storage.sqlentity.Notification;
import teammates.storage.sqlentity.Student;
import teammates.storage.sqlentity.UsageStatistics;
import teammates.ui.output.AccountData;
import teammates.ui.output.ApiOutput;
import teammates.ui.output.CourseData;
import teammates.ui.output.DeadlineExtensionData;
import teammates.ui.output.FeedbackQuestionData;
import teammates.ui.output.FeedbackResponseCommentData;
import teammates.ui.output.FeedbackResponseData;
import teammates.ui.output.FeedbackSessionData;
import teammates.ui.output.InstructorData;
import teammates.ui.output.NotificationData;
import teammates.ui.output.StudentData;
import teammates.ui.output.UsageStatisticsData;

/**
* Base class for all test cases which are allowed to access the database.
Expand Down Expand Up @@ -46,21 +64,116 @@ protected void verifyEquals(BaseEntity expected, ApiOutput actual) {
FeedbackQuestion expectedQuestion = (FeedbackQuestion) expected;
FeedbackQuestionDetails expectedQuestionDetails = expectedQuestion.getQuestionDetailsCopy();
FeedbackQuestionData actualQuestion = (FeedbackQuestionData) actual;
FeedbackQuestionDetails actualQuestionDetails = actualQuestion.getQuestionDetails();
assertEquals(expectedQuestion.getQuestionNumber(), (Integer) actualQuestion.getQuestionNumber());
assertEquals(expectedQuestionDetails.getQuestionText(), actualQuestion.getQuestionBrief());
assertEquals(expectedQuestion.getDescription(), actualQuestion.getQuestionDescription());
assertEquals(expectedQuestionDetails.getQuestionType(), actualQuestion.getQuestionType());
assertEquals(expectedQuestion.getGiverType(), actualQuestion.getGiverType());
assertEquals(expectedQuestion.getRecipientType(), actualQuestion.getRecipientType());
// TODO: compare the rest of the attributes D:
assertEquals(expectedQuestion.getNumOfEntitiesToGiveFeedbackTo(),
actualQuestion.getCustomNumberOfEntitiesToGiveFeedbackTo());
assertEquals(expectedQuestionDetails.getJsonString(), actualQuestionDetails.getJsonString());
} else if (expected instanceof FeedbackResponse) {
FeedbackResponse expectedResponse = (FeedbackResponse) expected;
FeedbackResponseDetails expectedResponseDetails = expectedResponse.getFeedbackResponseDetailsCopy();
FeedbackResponse expectedFeedbackResponse = (FeedbackResponse) expected;
FeedbackResponseDetails expectedResponseDetails =
expectedFeedbackResponse.getFeedbackResponseDetailsCopy();
FeedbackResponseData actualResponse = (FeedbackResponseData) actual;
assertEquals(expectedResponse.getGiver(), actualResponse.getGiverIdentifier());
assertEquals(expectedResponse.getRecipient(), actualResponse.getRecipientIdentifier());
assertEquals(expectedResponseDetails.getAnswerString(), actualResponse.getResponseDetails().getAnswerString());
// TODO: compare the rest of the attributes D:
FeedbackResponseDetails actualResponseDetails = actualResponse.getResponseDetails();
assertEquals(expectedFeedbackResponse.getGiver(), actualResponse.getGiverIdentifier());
assertEquals(expectedFeedbackResponse.getRecipient(), actualResponse.getRecipientIdentifier());
assertEquals(expectedResponseDetails.getAnswerString(),
actualResponse.getResponseDetails().getAnswerString());
assertEquals(expectedResponseDetails.getQuestionType(),
actualResponse.getResponseDetails().getQuestionType());
assertEquals(expectedResponseDetails.getJsonString(), actualResponseDetails.getJsonString());
} else if (expected instanceof Account) {
Account expectedAccount = (Account) expected;
AccountData actualAccount = (AccountData) actual;
assertEquals(expectedAccount.getGoogleId(), actualAccount.getGoogleId());
assertEquals(expectedAccount.getName(), actualAccount.getName());
assertEquals(expectedAccount.getEmail(), actualAccount.getEmail());
} else if (expected instanceof Course) {
Course expectedCourse = (Course) expected;
CourseData actualCourse = (CourseData) actual;
assertEquals(expectedCourse.getName(), actualCourse.getCourseName());
assertEquals(expectedCourse.getTimeZone(), actualCourse.getTimeZone());
assertEquals(expectedCourse.getInstitute(), actualCourse.getInstitute());
} else if (expected instanceof DeadlineExtension) {
DeadlineExtension expectedDeadlineExtension = (DeadlineExtension) expected;
DeadlineExtensionData actualDeadlineExtension = (DeadlineExtensionData) actual;
assertEquals(expectedDeadlineExtension.getEndTime().toEpochMilli(), actualDeadlineExtension.getEndTime());
assertEquals(expectedDeadlineExtension.isClosingSoonEmailSent(),
actualDeadlineExtension.getSentClosingEmail());
} else if (expected instanceof FeedbackResponseComment) {
FeedbackResponseComment expectedFeedbackResponseComment = (FeedbackResponseComment) expected;
FeedbackResponseCommentData actualComment = (FeedbackResponseCommentData) actual;
assertEquals(expectedFeedbackResponseComment.getGiver(), actualComment.getCommentGiver());
assertEquals(expectedFeedbackResponseComment.getCommentText(), actualComment.getCommentText());
assertEquals(expectedFeedbackResponseComment.getIsVisibilityFollowingFeedbackQuestion(),
actualComment.isVisibilityFollowingFeedbackQuestion());
assertEquals(expectedFeedbackResponseComment.getLastEditorEmail(), actualComment.getLastEditorEmail());
} else if (expected instanceof FeedbackSession) {
FeedbackSession expectedFeedbackSession = (FeedbackSession) expected;
FeedbackSessionData actualFeedbackSession = (FeedbackSessionData) actual;
assertEquals(expectedFeedbackSession.getName(), actualFeedbackSession.getFeedbackSessionName());
assertEquals(expectedFeedbackSession.getInstructions(), actualFeedbackSession.getInstructions());
assertEquals(expectedFeedbackSession.getStartTime().toEpochMilli(),
actualFeedbackSession.getSubmissionStartTimestamp());
assertEquals(expectedFeedbackSession.getEndTime().toEpochMilli(),
actualFeedbackSession.getSubmissionEndTimestamp());
assertEquals(expectedFeedbackSession.getSessionVisibleFromTime().toEpochMilli(),
actualFeedbackSession.getSessionVisibleFromTimestamp().longValue());
assertEquals(expectedFeedbackSession.getResultsVisibleFromTime().toEpochMilli(),
actualFeedbackSession.getResultVisibleFromTimestamp().longValue());
assertEquals(expectedFeedbackSession.getGracePeriod().toMinutes(),
actualFeedbackSession.getGracePeriod().longValue());
assertEquals(expectedFeedbackSession.isClosingEmailEnabled(),
actualFeedbackSession.getIsClosingEmailEnabled());
assertEquals(expectedFeedbackSession.isPublishedEmailEnabled(),
actualFeedbackSession.getIsPublishedEmailEnabled());
} else if (expected instanceof Instructor) {
Instructor expectedInstructor = (Instructor) expected;
InstructorData actualInstructor = (InstructorData) actual;
assertEquals(expectedInstructor.getCourseId(), actualInstructor.getCourseId());
assertEquals(expectedInstructor.getName(), actualInstructor.getName());
assertEquals(expectedInstructor.getEmail(), actualInstructor.getEmail());
assertEquals(expectedInstructor.getRegKey(), actualInstructor.getKey());
assertEquals(expectedInstructor.isDisplayedToStudents(), actualInstructor.getIsDisplayedToStudents());
assertEquals(expectedInstructor.getDisplayName(), actualInstructor.getDisplayedToStudentsAs());
assertEquals(expectedInstructor.getRole(), actualInstructor.getRole());
} else if (expected instanceof Notification) {
Notification expectedNotification = (Notification) expected;
NotificationData actualNotification = (NotificationData) actual;
assertEquals(expectedNotification.getStartTime().toEpochMilli(), actualNotification.getStartTimestamp());
assertEquals(expectedNotification.getEndTime().toEpochMilli(), actualNotification.getEndTimestamp());
assertEquals(expectedNotification.getStyle(), actualNotification.getStyle());
assertEquals(expectedNotification.getTargetUser(), actualNotification.getTargetUser());
assertEquals(expectedNotification.getTitle(), actualNotification.getTitle());
assertEquals(expectedNotification.getMessage(), actualNotification.getMessage());
assertEquals(expectedNotification.isShown(), actualNotification.isShown());
} else if (expected instanceof Student) {
Student expectedStudent = (Student) expected;
StudentData actualStudent = (StudentData) actual;
assertEquals(expectedStudent.getCourseId(), actualStudent.getCourseId());
assertEquals(expectedStudent.getName(), actualStudent.getName());
assertEquals(expectedStudent.getEmail(), actualStudent.getEmail());
assertEquals(expectedStudent.getRegKey(), actualStudent.getKey());
assertEquals(expectedStudent.getComments(), actualStudent.getComments());
// TODO: A student might not have a team or section.
// assertEquals(expectedStudent.getTeamName(), actualStudent.getTeamName());
// assertEquals(expectedStudent.getSectionName(), actualStudent.getSectionName());
} else if (expected instanceof UsageStatistics) {
UsageStatistics expectedUsageStatistics = (UsageStatistics) expected;
UsageStatisticsData actualUsageStatistics = (UsageStatisticsData) actual;
assertEquals(expectedUsageStatistics.getStartTime().toEpochMilli(), actualUsageStatistics.getStartTime());
assertEquals(expectedUsageStatistics.getTimePeriod(), actualUsageStatistics.getTimePeriod());
assertEquals(expectedUsageStatistics.getNumResponses(), actualUsageStatistics.getNumResponses());
assertEquals(expectedUsageStatistics.getNumCourses(), actualUsageStatistics.getNumCourses());
assertEquals(expectedUsageStatistics.getNumStudents(), actualUsageStatistics.getNumStudents());
assertEquals(expectedUsageStatistics.getNumInstructors(), actualUsageStatistics.getNumInstructors());
assertEquals(expectedUsageStatistics.getNumAccountRequests(),
actualUsageStatistics.getNumAccountRequests());
assertEquals(expectedUsageStatistics.getNumEmails(), actualUsageStatistics.getNumEmails());
assertEquals(expectedUsageStatistics.getNumSubmissions(), actualUsageStatistics.getNumSubmissions());
} else {
fail("Unknown entity");
}
Expand Down

0 comments on commit ddd6f09

Please sign in to comment.