-
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
3d8219a
commit d82c685
Showing
11 changed files
with
577 additions
and
30 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
src/it/java/teammates/it/sqllogic/core/UsersLogicIT.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,150 @@ | ||
package teammates.it.sqllogic.core; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.datatransfer.InstructorPermissionRole; | ||
import teammates.common.datatransfer.InstructorPrivileges; | ||
import teammates.common.exception.EntityAlreadyExistsException; | ||
import teammates.common.exception.EntityDoesNotExistException; | ||
import teammates.common.exception.InvalidParametersException; | ||
import teammates.common.util.Const; | ||
import teammates.it.test.BaseTestCaseWithSqlDatabaseAccess; | ||
import teammates.sqllogic.core.AccountsLogic; | ||
import teammates.sqllogic.core.CoursesLogic; | ||
import teammates.sqllogic.core.UsersLogic; | ||
import teammates.storage.sqlentity.Account; | ||
import teammates.storage.sqlentity.Course; | ||
import teammates.storage.sqlentity.Instructor; | ||
import teammates.storage.sqlentity.Student; | ||
|
||
/** | ||
* SUT: {@link UsersLogic}. | ||
*/ | ||
public class UsersLogicIT extends BaseTestCaseWithSqlDatabaseAccess { | ||
|
||
private final UsersLogic usersLogic = UsersLogic.inst(); | ||
|
||
private final AccountsLogic accountsLogic = AccountsLogic.inst(); | ||
|
||
private final CoursesLogic coursesLogic = CoursesLogic.inst(); | ||
|
||
private Course course; | ||
|
||
private Account account; | ||
|
||
@BeforeMethod | ||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
|
||
course = getTypicalCourse(); | ||
coursesLogic.createCourse(course); | ||
|
||
account = getTypicalAccount(); | ||
accountsLogic.createAccount(account); | ||
} | ||
|
||
@Test | ||
public void testResetInstructorGoogleId() | ||
throws InvalidParametersException, EntityAlreadyExistsException, EntityDoesNotExistException { | ||
Instructor instructor = getTypicalInstructor(); | ||
instructor.setCourse(course); | ||
instructor.setAccount(account); | ||
|
||
String email = instructor.getEmail(); | ||
String courseId = instructor.getCourseId(); | ||
String googleId = instructor.getGoogleId(); | ||
|
||
______TS("success: reset instructor that does not exist"); | ||
assertThrows(EntityDoesNotExistException.class, | ||
() -> usersLogic.resetInstructorGoogleId(email, courseId, googleId)); | ||
|
||
______TS("success: reset instructor that exists"); | ||
usersLogic.createInstructor(instructor); | ||
usersLogic.resetInstructorGoogleId(email, courseId, googleId); | ||
|
||
assertNull(instructor.getAccount()); | ||
assertEquals(0, accountsLogic.getAccountsForEmail(email).size()); | ||
|
||
______TS("found at least one other user with same googleId, should not delete account"); | ||
Account anotherAccount = getTypicalAccount(); | ||
accountsLogic.createAccount(anotherAccount); | ||
|
||
instructor.setCourse(course); | ||
instructor.setAccount(anotherAccount); | ||
|
||
Student anotherUser = getTypicalStudent(); | ||
anotherUser.setCourse(course); | ||
anotherUser.setAccount(anotherAccount); | ||
|
||
usersLogic.createStudent(anotherUser); | ||
usersLogic.resetInstructorGoogleId(email, courseId, googleId); | ||
|
||
assertNull(instructor.getAccount()); | ||
assertEquals(anotherAccount, accountsLogic.getAccountForGoogleId(googleId)); | ||
} | ||
|
||
@Test | ||
public void testResetStudentGoogleId() | ||
throws InvalidParametersException, EntityAlreadyExistsException, EntityDoesNotExistException { | ||
Student student = getTypicalStudent(); | ||
student.setCourse(course); | ||
student.setAccount(account); | ||
|
||
String email = student.getEmail(); | ||
String courseId = student.getCourseId(); | ||
String googleId = student.getGoogleId(); | ||
|
||
______TS("success: reset student that does not exist"); | ||
assertThrows(EntityDoesNotExistException.class, | ||
() -> usersLogic.resetStudentGoogleId(email, courseId, googleId)); | ||
|
||
______TS("success: reset student that exists"); | ||
usersLogic.createStudent(student); | ||
usersLogic.resetStudentGoogleId(email, courseId, googleId); | ||
|
||
assertNull(student.getAccount()); | ||
assertEquals(0, accountsLogic.getAccountsForEmail(email).size()); | ||
|
||
______TS("found at least one other user with same googleId, should not delete account"); | ||
Account anotherAccount = getTypicalAccount(); | ||
accountsLogic.createAccount(anotherAccount); | ||
|
||
student.setCourse(course); | ||
student.setAccount(anotherAccount); | ||
|
||
Instructor anotherUser = getTypicalInstructor(); | ||
anotherUser.setCourse(course); | ||
anotherUser.setAccount(anotherAccount); | ||
|
||
usersLogic.createInstructor(anotherUser); | ||
usersLogic.resetStudentGoogleId(email, courseId, googleId); | ||
|
||
assertNull(student.getAccount()); | ||
assertEquals(anotherAccount, accountsLogic.getAccountForGoogleId(googleId)); | ||
} | ||
|
||
private Course getTypicalCourse() { | ||
return new Course("course-id", "course-name", Const.DEFAULT_TIME_ZONE, "teammates"); | ||
} | ||
|
||
private Student getTypicalStudent() { | ||
return new Student(course, "student-name", "[email protected]", "comments"); | ||
} | ||
|
||
private Instructor getTypicalInstructor() { | ||
InstructorPrivileges instructorPrivileges = | ||
new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER); | ||
InstructorPermissionRole role = InstructorPermissionRole | ||
.getEnum(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER); | ||
|
||
return new Instructor(course, "instructor-name", "[email protected]", | ||
true, Const.DEFAULT_DISPLAY_NAME_FOR_INSTRUCTOR, role, instructorPrivileges); | ||
} | ||
|
||
private Account getTypicalAccount() { | ||
return new Account("google-id", "name", "[email protected]"); | ||
} | ||
|
||
} |
105 changes: 105 additions & 0 deletions
105
src/it/java/teammates/it/ui/webapi/ResetAccountActionIT.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,105 @@ | ||
package teammates.it.ui.webapi; | ||
|
||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import teammates.common.util.Const; | ||
import teammates.common.util.HibernateUtil; | ||
import teammates.storage.sqlentity.Course; | ||
import teammates.storage.sqlentity.Instructor; | ||
import teammates.storage.sqlentity.Student; | ||
import teammates.ui.output.MessageOutput; | ||
import teammates.ui.webapi.EntityNotFoundException; | ||
import teammates.ui.webapi.JsonResult; | ||
import teammates.ui.webapi.ResetAccountAction; | ||
|
||
/** | ||
* SUT: {@link ResetAccountAction}. | ||
*/ | ||
public class ResetAccountActionIT extends BaseActionIT<ResetAccountAction> { | ||
|
||
@Override | ||
@BeforeMethod | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
persistDataBundle(typicalBundle); | ||
HibernateUtil.flushSession(); | ||
} | ||
|
||
@Override | ||
protected String getActionUri() { | ||
return Const.ResourceURIs.ACCOUNT_RESET; | ||
} | ||
|
||
@Override | ||
protected String getRequestMethod() { | ||
return PUT; | ||
} | ||
|
||
@Test | ||
@Override | ||
protected void testExecute() { | ||
Instructor instructor = typicalBundle.instructors.get("instructor1OfCourse1"); | ||
Student student = typicalBundle.students.get("student1InCourse1"); | ||
|
||
loginAsAdmin(); | ||
|
||
______TS("Typical Success Case with Student Email param given and Student exists"); | ||
String[] params = new String[] { | ||
Const.ParamsNames.STUDENT_EMAIL, student.getEmail(), | ||
Const.ParamsNames.COURSE_ID, student.getCourseId(), | ||
}; | ||
|
||
ResetAccountAction resetAccountAction = getAction(params); | ||
JsonResult actionOutput = getJsonResult(resetAccountAction); | ||
MessageOutput response = (MessageOutput) actionOutput.getOutput(); | ||
|
||
assertEquals(response.getMessage(), "Account is successfully reset."); | ||
assertNotNull(student); | ||
assertNull(student.getAccount()); | ||
assertNull(student.getGoogleId()); | ||
|
||
______TS("Student Email param given but Student is non existent"); | ||
String invalidEmail = "[email protected]"; | ||
String[] invalidParams = new String[] { | ||
Const.ParamsNames.STUDENT_EMAIL, invalidEmail, | ||
Const.ParamsNames.COURSE_ID, student.getCourseId(), | ||
}; | ||
|
||
EntityNotFoundException enfe = verifyEntityNotFound(invalidParams); | ||
assertEquals("Student does not exist.", enfe.getMessage()); | ||
|
||
______TS("Typical Success Case with Instructor Email param given and Instructor exists"); | ||
params = new String[] { | ||
Const.ParamsNames.INSTRUCTOR_EMAIL, instructor.getEmail(), | ||
Const.ParamsNames.COURSE_ID, instructor.getCourseId(), | ||
}; | ||
|
||
resetAccountAction = getAction(params); | ||
actionOutput = getJsonResult(resetAccountAction); | ||
response = (MessageOutput) actionOutput.getOutput(); | ||
|
||
assertEquals(response.getMessage(), "Account is successfully reset."); | ||
assertNotNull(instructor); | ||
assertNull(instructor.getAccount()); | ||
assertNull(instructor.getGoogleId()); | ||
|
||
______TS("Instructor Email param given but Instructor is non existent"); | ||
invalidParams = new String[] { | ||
Const.ParamsNames.INSTRUCTOR_EMAIL, invalidEmail, | ||
Const.ParamsNames.COURSE_ID, instructor.getCourseId(), | ||
}; | ||
|
||
enfe = verifyEntityNotFound(invalidParams); | ||
assertEquals("Instructor does not exist.", enfe.getMessage()); | ||
} | ||
|
||
@Test | ||
@Override | ||
protected void testAccessControl() throws Exception { | ||
Course course = typicalBundle.courses.get("course1"); | ||
|
||
verifyOnlyAdminCanAccess(course); | ||
} | ||
|
||
} |
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
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
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.