-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ec2274f
commit 64309bf
Showing
18 changed files
with
882 additions
and
65 deletions.
There are no files selected for viewing
196 changes: 196 additions & 0 deletions
196
src/it/java/teammates/it/sqllogic/core/DataBundleLogicIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
package teammates.it.sqllogic.core; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.InstructorPermissionRole; | ||
import teammates.common.datatransfer.InstructorPrivileges; | ||
import teammates.common.datatransfer.NotificationStyle; | ||
import teammates.common.datatransfer.NotificationTargetUser; | ||
import teammates.common.datatransfer.SqlDataBundle; | ||
import teammates.it.test.BaseTestCaseWithSqlDatabaseAccess; | ||
import teammates.sqllogic.core.DataBundleLogic; | ||
import teammates.storage.sqlentity.Account; | ||
import teammates.storage.sqlentity.AccountRequest; | ||
import teammates.storage.sqlentity.Course; | ||
import teammates.storage.sqlentity.FeedbackSession; | ||
import teammates.storage.sqlentity.Instructor; | ||
import teammates.storage.sqlentity.Notification; | ||
import teammates.storage.sqlentity.ReadNotification; | ||
import teammates.storage.sqlentity.Section; | ||
import teammates.storage.sqlentity.Student; | ||
import teammates.storage.sqlentity.Team; | ||
import teammates.test.FileHelper; | ||
|
||
/** | ||
* SUT: {@link DataBundleLogic}. | ||
*/ | ||
public class DataBundleLogicIT extends BaseTestCaseWithSqlDatabaseAccess { | ||
|
||
private final DataBundleLogic dataBundleLogic = DataBundleLogic.inst(); | ||
|
||
@BeforeMethod | ||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
@Test | ||
public void testCreateDataBundle_typicalValues_createdCorrectly() throws Exception { | ||
String pathToJsonFile = getTestDataFolder() + "/DataBundleLogicIT.json"; | ||
String jsonString = FileHelper.readFile(pathToJsonFile); | ||
SqlDataBundle dataBundle = DataBundleLogic.deserializeDataBundle(jsonString); | ||
|
||
______TS("verify account requests deserialized correctly"); | ||
|
||
AccountRequest actualAccountRequest = dataBundle.accountRequests.get("instructor1"); | ||
AccountRequest expectedAccountRequest = new AccountRequest("instr1@teammates.tmt", "Instructor 1", | ||
"TEAMMATES Test Institute 1"); | ||
expectedAccountRequest.setId(actualAccountRequest.getId()); | ||
expectedAccountRequest.setRegisteredAt(Instant.parse("1970-02-14T00:00:00Z")); | ||
expectedAccountRequest.setRegistrationKey(actualAccountRequest.getRegistrationKey()); | ||
verifyEquals(expectedAccountRequest, actualAccountRequest); | ||
|
||
______TS("verify accounts deserialized correctly"); | ||
|
||
Account actualInstructorAccount = dataBundle.accounts.get("instructor1"); | ||
Account expectedInstructorAccount = new Account("idOfInstructor1", "Instructor 1", "instr1@teammates.tmt"); | ||
expectedInstructorAccount.setId(actualInstructorAccount.getId()); | ||
verifyEquals(expectedInstructorAccount, actualInstructorAccount); | ||
assertTrue(actualInstructorAccount.getReadNotifications().size() == 1); | ||
assertTrue(List.of(dataBundle.readNotifications.get("notification1Instructor1")) | ||
.containsAll(actualInstructorAccount.getReadNotifications())); | ||
|
||
Account actualStudentAccount = dataBundle.accounts.get("student1"); | ||
Account expectedStudentAccount = new Account("idOfStudent1", "Student 1", "student1@teammates.tmt"); | ||
expectedStudentAccount.setId(actualStudentAccount.getId()); | ||
verifyEquals(expectedStudentAccount, actualStudentAccount); | ||
assertTrue(actualStudentAccount.getReadNotifications().size() == 1); | ||
assertTrue(List.of(dataBundle.readNotifications.get("notification1Student1")) | ||
.containsAll(actualStudentAccount.getReadNotifications())); | ||
|
||
______TS("verify notifications deserialized correctly"); | ||
|
||
Notification actualNotification = dataBundle.notifications.get("notification1"); | ||
Notification expectedNotification = new Notification(Instant.parse("2011-01-01T00:00:00Z"), | ||
Instant.parse("2099-01-01T00:00:00Z"), NotificationStyle.DANGER, NotificationTargetUser.GENERAL, | ||
"A deprecation note", "<p>Deprecation happens in three minutes</p>"); | ||
expectedNotification.setId(actualNotification.getId()); | ||
verifyEquals(expectedNotification, actualNotification); | ||
|
||
______TS("verify read notifications deserialized correctly"); | ||
|
||
ReadNotification actualReadNotification = dataBundle.readNotifications.get("notification1Instructor1"); | ||
ReadNotification expectedReadNotification = new ReadNotification(expectedInstructorAccount, | ||
expectedNotification); | ||
expectedNotification.setId(actualNotification.getId()); | ||
verifyEquals(expectedReadNotification, actualReadNotification); | ||
|
||
______TS("verify courses deserialized correctly"); | ||
|
||
Course actualTypicalCourse = dataBundle.courses.get("typicalCourse"); | ||
Course expectedTypicalCourse = new Course("typical-course-id", "Typical Course", "Africa/Johannesburg", | ||
"TEAMMATES Test Institute"); | ||
verifyEquals(expectedTypicalCourse, actualTypicalCourse); | ||
|
||
______TS("verify sections deserialized correctly"); | ||
|
||
Section actualSection = dataBundle.sections.get("section1InTypicalCourse"); | ||
Section expectedSection = new Section(expectedTypicalCourse, "Section 1"); | ||
expectedSection.setId(actualSection.getId()); | ||
verifyEquals(expectedSection, actualSection); | ||
|
||
______TS("verify teams deserialized correctly"); | ||
|
||
Team actualTeam = dataBundle.teams.get("team1InTypicalCourse"); | ||
Team expectedTeam = new Team(expectedSection, "Team 1"); | ||
expectedTeam.setId(actualTeam.getId()); | ||
verifyEquals(expectedTeam, actualTeam); | ||
|
||
______TS("verify instructors deserialized correctly"); | ||
|
||
Instructor actualInstructor1 = dataBundle.instructors.get("instructor1OfTypicalCourse"); | ||
InstructorPermissionRole coOwner = InstructorPermissionRole.INSTRUCTOR_PERMISSION_ROLE_COOWNER; | ||
InstructorPrivileges coOwnerPrivileges = new InstructorPrivileges(coOwner.getRoleName()); | ||
Instructor expectedInstructor1 = new Instructor(actualTypicalCourse, "Instructor 1", "instr1@teammates.tmt", | ||
true, "Instructor", coOwner, coOwnerPrivileges); | ||
expectedInstructor1.setId(actualInstructor1.getId()); | ||
expectedInstructor1.setRegKey(actualInstructor1.getRegKey()); | ||
expectedInstructor1.setAccount(expectedInstructorAccount); | ||
verifyEquals(expectedInstructor1, actualInstructor1); | ||
|
||
Instructor actualInstructor2 = dataBundle.instructors.get("instructor2OfTypicalCourse"); | ||
InstructorPermissionRole tutor = InstructorPermissionRole.INSTRUCTOR_PERMISSION_ROLE_TUTOR; | ||
InstructorPrivileges tutorPrivileges = new InstructorPrivileges(tutor.getRoleName()); | ||
Instructor expectedInstructor2 = new Instructor(actualTypicalCourse, "Instructor 2", "instr2@teammates.tmt", | ||
true, "Instructor", tutor, tutorPrivileges); | ||
expectedInstructor2.setId(actualInstructor2.getId()); | ||
expectedInstructor2.setRegKey(actualInstructor2.getRegKey()); | ||
verifyEquals(expectedInstructor2, actualInstructor2); | ||
|
||
______TS("verify students deserialized correctly"); | ||
|
||
Student actualStudent1 = dataBundle.students.get("student1InTypicalCourse"); | ||
Student expectedStudent1 = new Student(expectedTypicalCourse, "student1 In TypicalCourse", | ||
"student1@teammates.tmt", "comment for student1TypicalCourse"); | ||
expectedStudent1.setAccount(expectedStudentAccount); | ||
expectedStudent1.setTeam(expectedTeam); | ||
expectedStudent1.setRegKey(actualStudent1.getRegKey()); | ||
expectedStudent1.setId(actualStudent1.getId()); | ||
verifyEquals(expectedStudent1, actualStudent1); | ||
|
||
Student actualStudent2 = dataBundle.students.get("student2InTypicalCourse"); | ||
Student expectedStudent2 = new Student(expectedTypicalCourse, "student2 In TypicalCourse", | ||
"student2@teammates.tmt", ""); | ||
expectedStudent2.setTeam(expectedTeam); | ||
expectedStudent2.setRegKey(actualStudent2.getRegKey()); | ||
expectedStudent2.setId(actualStudent2.getId()); | ||
verifyEquals(expectedStudent2, actualStudent2); | ||
|
||
______TS("verify feedback sessions"); | ||
|
||
FeedbackSession actualSession1 = dataBundle.feedbackSessions.get("session1InTypicalCourse"); | ||
FeedbackSession expectedSession1 = new FeedbackSession("First feedback session", expectedTypicalCourse, | ||
"instr1@teammates.tmt", "Please please fill in the following questions.", | ||
Instant.parse("2012-04-01T22:00:00Z"), Instant.parse("2027-04-30T22:00:00Z"), | ||
Instant.parse("2012-03-28T22:00:00Z"), Instant.parse("2027-05-01T22:00:00Z"), Duration.ofMinutes(10), | ||
true, true, true); | ||
expectedSession1.setId(actualSession1.getId()); | ||
verifyEquals(expectedSession1, actualSession1); | ||
} | ||
|
||
@Test | ||
public void testPersistDataBundle_typicalValues_persistedToDbCorrectly() throws Exception { | ||
SqlDataBundle dataBundle = loadSqlDataBundle("/DataBundleLogicIT.json"); | ||
dataBundleLogic.persistDataBundle(dataBundle); | ||
|
||
______TS("verify notifications persisted correctly"); | ||
Notification notification1 = dataBundle.notifications.get("notification1"); | ||
|
||
verifyPresentInDatabase(notification1); | ||
|
||
______TS("verify course persisted correctly"); | ||
Course typicalCourse = dataBundle.courses.get("typicalCourse"); | ||
|
||
verifyPresentInDatabase(typicalCourse); | ||
|
||
______TS("verify feedback sessions persisted correctly"); | ||
FeedbackSession session1InTypicalCourse = dataBundle.feedbackSessions.get("session1InTypicalCourse"); | ||
|
||
verifyPresentInDatabase(session1InTypicalCourse); | ||
|
||
______TS("verify accounts persisted correctly"); | ||
Account instructor1Account = dataBundle.accounts.get("instructor1"); | ||
Account student1Account = dataBundle.accounts.get("student1"); | ||
|
||
verifyPresentInDatabase(instructor1Account); | ||
verifyPresentInDatabase(student1Account); | ||
|
||
// TODO: incomplete | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.