diff --git a/src/main/java/Main.java b/src/main/java/Main.java index e506a76..a222b32 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -11,6 +11,10 @@ import use_cases.collaborative_task_scheduling.scheduling_ct_use_case.*; import use_cases.calendar_scheduler.schedule_conflict_use_case.ScheduleConflictPresenter; import use_cases.calendar_scheduler.scheduler_use_case.SchedulerPresenter; +import use_cases.login_registration.login_usecase.LoginGateway; +import use_cases.login_registration.login_usecase.LoginInputBoundary; +import use_cases.login_registration.login_usecase.LoginInteractor; +import use_cases.login_registration.login_usecase.LoginPresenter; import use_cases.login_registration.user_register_usecase.*; import use_cases.task_management.event_creation_use_case.*; @@ -21,7 +25,7 @@ public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws IOException, ClassNotFoundException { // Build the main program window JFrame application = new JFrame("32 Things To Do"); @@ -35,12 +39,29 @@ public static void main(String[] args) { HashMap allCourses = new HashMap<>(); // Create the components for injection into the use cases - UserRegGateway regUser = new InMemoryUser(); + UserRegGateway regUser = new FileUser("src/main/java/data/users.ser"); + UserFactory fac = new GeneralUserFactory(); UserRegPresenter userPresenter = new UserRegResponseFormatter(); - UserRegInputBoundary userInteractor = new UserRegInteractor(regUser, userPresenter); + UserRegInputBoundary userInteractor = new UserRegInteractor(regUser, userPresenter, fac); UserRegController userRegisterController = new UserRegController(userInteractor); - User user = ((UserRegInteractor) userInteractor).getUser(); + // Adding in login use case + LoginGateway loginUser = new FileUser("src/main/java/data/users.ser"); + LoginPresenter loginPresenter = new LoginResponseFormatter(); + LoginInputBoundary loginInteractor = new LoginInteractor(loginUser, loginPresenter); + LoginController loginController = new LoginController(loginInteractor); + // + + // initialize User based on whether they log in or register + // if you don't register, then you are logging in: + User user; + if ((((UserRegInteractor) userInteractor).getUser() instanceof StudentUser) | + (((UserRegInteractor) userInteractor).getUser() instanceof InstructorUser)) { + user = ((UserRegInteractor) userInteractor).getUser(); + } else { + user = ((LoginInteractor) loginInteractor).getUser(); + } + SchedulerPresenter schedulerPresenter = new SchedulerResponseFormatter(); ScheduleConflictPresenter scheduleConflictPresenter = new ScheduleConflictResponseFormatter(); @@ -86,14 +107,17 @@ public static void main(String[] args) { CourseCreationScreen courseCreationScreen = new CourseCreationScreen(courseCreationController, screens, cardLayout); screens.add("course", courseCreationScreen); - MainScreen mainScreen = new MainScreen(screens, cardLayout); - screens.add("main", mainScreen); + StudentMainScreen studentMainScreen = new StudentMainScreen(screens, cardLayout); + screens.add("main", studentMainScreen); RegisterScreen registerScreen = new RegisterScreen(userRegisterController, cardLayout, screens); screens.add("register", registerScreen); -// LoginScreen loginScreen = new LoginScreen(loginController); -// screens.add("login", loginScreen); + LoginScreen loginScreen = new LoginScreen(loginController, cardLayout, screens); + screens.add("login", loginScreen); + + InstructorMain instructorMainScreen = new InstructorMain(screens, cardLayout); + screens.add("InstructorMain", instructorMainScreen); WelcomeScreen welcomeScreen = new WelcomeScreen(cardLayout, screens); screens.add("welcome", welcomeScreen); diff --git a/src/main/java/data/users.ser b/src/main/java/data/users.ser new file mode 100644 index 0000000..8f6702e Binary files /dev/null and b/src/main/java/data/users.ser differ diff --git a/src/main/java/entities/GeneralUserFactory.java b/src/main/java/entities/GeneralUserFactory.java new file mode 100644 index 0000000..0b19100 --- /dev/null +++ b/src/main/java/entities/GeneralUserFactory.java @@ -0,0 +1,23 @@ +package entities; + +// Entity Layer + +public class GeneralUserFactory implements UserFactory { + + /** + * @param name the name of this StudentUser + * @param password the password of this StudentUser + * @return a new StudentUser + */ + + @Override + public StudentUser createStudent(String name, String password) { + return new StudentUser(name, password); + } + + @Override + public InstructorUser createInstructor(String name, String password) { + return new InstructorUser(name, password); + } + +} diff --git a/src/main/java/entities/InstructorUserFactory.java b/src/main/java/entities/InstructorUserFactory.java deleted file mode 100644 index a5f01d5..0000000 --- a/src/main/java/entities/InstructorUserFactory.java +++ /dev/null @@ -1,18 +0,0 @@ -package entities; - -// Entity layer - -public class InstructorUserFactory implements UserFactory { - - /** - * @param name the name of this InstructorUser - * @param password the password of this InstructorUser's account - * @return a new InstructorUser - */ - - @Override - public User create(String name, String password) { - return new InstructorUser(name, password); - } - -} diff --git a/src/main/java/entities/StudentUser.java b/src/main/java/entities/StudentUser.java index 1f65111..0ef70b5 100644 --- a/src/main/java/entities/StudentUser.java +++ b/src/main/java/entities/StudentUser.java @@ -87,7 +87,7 @@ public ArrayList getCourses() { } public void addCourse(String course) { - this.toDoList.add(course); + this.courses.add(course); } public void setCourses(ArrayList c) { this.courses = c; } diff --git a/src/main/java/entities/StudentUserFactory.java b/src/main/java/entities/StudentUserFactory.java deleted file mode 100644 index f99d65a..0000000 --- a/src/main/java/entities/StudentUserFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -package entities; - -// Entity Layer - -public class StudentUserFactory implements UserFactory { - - /** - * @param name the name of this StudentUser - * @param password the password of this StudentUser - * @return a new StudentUser - */ - @Override - public User create(String name, String password) { - return new StudentUser(name, password); - } - -} diff --git a/src/main/java/entities/UserFactory.java b/src/main/java/entities/UserFactory.java index df97992..7b5b326 100644 --- a/src/main/java/entities/UserFactory.java +++ b/src/main/java/entities/UserFactory.java @@ -1,11 +1,15 @@ package entities; - -// Entity Layer - public interface UserFactory { /** - * Creates Users with the specified name and password + * + * @param name the name of this user + * @param password the password of this user + * @return a User object */ - User create(String name, String password); + + StudentUser createStudent(String name, String password); + + InstructorUser createInstructor(String name, String password); + } diff --git a/src/main/java/screens/InstructorMain.java b/src/main/java/screens/InstructorMain.java new file mode 100644 index 0000000..ca37401 --- /dev/null +++ b/src/main/java/screens/InstructorMain.java @@ -0,0 +1,88 @@ +package screens; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class InstructorMain extends JPanel implements ActionListener { + + + /** + * The selectable buttons on the main screen + */ + JButton taskCreate; + JButton calendar; + JButton courses; + JButton scheduleCT; + + JButton logout; + + /** + * Objects for connecting to the other screens + */ + CardLayout cardLayout; + JPanel screens; + + /** + * The window of the main screen with buttons connecting to each use case + */ + public InstructorMain(JPanel screens, CardLayout cardLayout) { + + this.cardLayout = cardLayout; + this.screens = screens; + + // Create label for title of screen + JLabel title = new JLabel("32 Things To Do"); + title.setAlignmentX(Component.CENTER_ALIGNMENT); + + // Create buttons + taskCreate = new JButton("New Task"); + calendar = new JButton("Calendar"); + courses = new JButton("Courses"); +// scheduleCT = new JButton("Schedule Collaborative Task"); + logout = new JButton("Logout"); + + taskCreate.addActionListener(this); + calendar.addActionListener(this); + courses.addActionListener(this); +// scheduleCT.addActionListener(this); + logout.addActionListener(this); + + // Create panel for buttons + JPanel buttons = new JPanel(); + buttons.add(taskCreate); + buttons.add(calendar); + buttons.add(courses); +// buttons.add(scheduleCT); + buttons.add(logout); + + // Add all components to the panel + this.add(title); + this.add(buttons); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + } + + /** + * Trigger the corresponding use case upon button click + */ + public void actionPerformed(ActionEvent evt) { + if (evt.getSource() == taskCreate) { + cardLayout.show(screens, "toDoList"); + } + if (evt.getSource() == calendar) { + cardLayout.show(screens, "calendar"); + } + + if (evt.getSource() == courses) { + cardLayout.show(screens, "course"); + } +// if (evt.getSource() == scheduleCT) { +// cardLayout.show(screens, "scheduleCT"); +// } + if (evt.getSource() == logout) { + cardLayout.show(screens, "welcome"); + } + + } +} diff --git a/src/main/java/screens/MainScreen.java b/src/main/java/screens/StudentMainScreen.java similarity index 86% rename from src/main/java/screens/MainScreen.java rename to src/main/java/screens/StudentMainScreen.java index 3ef9199..b63d03c 100644 --- a/src/main/java/screens/MainScreen.java +++ b/src/main/java/screens/StudentMainScreen.java @@ -5,7 +5,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -public class MainScreen extends JPanel implements ActionListener { +public class StudentMainScreen extends JPanel implements ActionListener { /** * The selectable buttons on the main screen @@ -16,6 +16,8 @@ public class MainScreen extends JPanel implements ActionListener { JButton courses; JButton scheduleCT; + JButton logout; + /** * Objects for connecting to the other screens */ @@ -25,7 +27,7 @@ public class MainScreen extends JPanel implements ActionListener { /** * The window of the main screen with buttons connecting to each use case */ - public MainScreen(JPanel screens, CardLayout cardLayout) { + public StudentMainScreen(JPanel screens, CardLayout cardLayout) { this.cardLayout = cardLayout; this.screens = screens; @@ -40,12 +42,14 @@ public MainScreen(JPanel screens, CardLayout cardLayout) { progressTracker = new JButton("Progress Tracker"); courses = new JButton("Courses"); scheduleCT = new JButton("Schedule Collaborative Task"); + logout = new JButton("Logout"); toDoList.addActionListener(this); calendar.addActionListener(this); progressTracker.addActionListener(this); courses.addActionListener(this); scheduleCT.addActionListener(this); + logout.addActionListener(this); // Create panel for buttons JPanel buttons = new JPanel(); @@ -54,6 +58,7 @@ public MainScreen(JPanel screens, CardLayout cardLayout) { buttons.add(progressTracker); buttons.add(courses); buttons.add(scheduleCT); + buttons.add(logout); // Add all components to the panel this.add(title); @@ -80,6 +85,9 @@ public void actionPerformed(ActionEvent evt) { if (evt.getSource() == scheduleCT) { cardLayout.show(screens, "scheduleCT"); } + if (evt.getSource() == logout) { + cardLayout.show(screens, "welcome"); + } } diff --git a/src/main/java/screens/login_registration/FileUser.java b/src/main/java/screens/login_registration/FileUser.java index 724b14f..caab839 100644 --- a/src/main/java/screens/login_registration/FileUser.java +++ b/src/main/java/screens/login_registration/FileUser.java @@ -1,17 +1,19 @@ package screens.login_registration; - import use_cases.login_registration.login_usecase.LoginGateway; import use_cases.login_registration.logout_usecase.LogoutGateway; import use_cases.login_registration.user_register_usecase.UserRegGateway; import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashMap; import java.util.Map; public class FileUser implements UserRegGateway, LoginGateway, LogoutGateway { - private final HashMap accounts; +// private final HashMap accounts; + private static HashMap accounts; private final String filePath; @@ -22,7 +24,21 @@ public FileUser(String path) throws IOException, ClassNotFoundException { */ this.filePath = path; - this.accounts = readFile(); + + // method that checks if a path or file exists or not and then + // writes an empty map to a new file if it doesn't exist + // and reads the existing file if it does exist + + if (Files.exists(Path.of(path))) { +// this.accounts = readFile(); + accounts = readFile(); + } else { +// this.accounts = new HashMap(); + accounts = new HashMap(); + save(); + } + + } private HashMap readFile() throws IOException, ClassNotFoundException { @@ -46,10 +62,16 @@ public void save(UserRegSaveRequest requestModel) throws IOException { private void save() throws IOException { /* - * Write the new map of usernames to UserRegSaveRequest objects into the User database file. + * Write the map of usernames to UserRegSaveRequest objects into the User database file. */ - FileOutputStream fileWriter = new FileOutputStream(filePath); + FileOutputStream fileWriter; +// if (Files.exists(Path.of(filePath))) { +// fileWriter = new FileOutputStream(filePath); +// } else { +// fileWriter = new FileOutputStream("src/main/java/data/users.ser"); +// } + fileWriter = new FileOutputStream(filePath); ObjectOutputStream out = new ObjectOutputStream(fileWriter); out.writeObject(accounts); out.close(); @@ -72,16 +94,8 @@ public String passOf(String name) { } public Map getAccounts() { - return this.accounts; +// return this.accounts; + return accounts; } -// /** -// * @param name The username of the user -// * @return the UserRegSaveRequest object associated with this username. -// * Preconditions: name is a key in accounts -// */ -// public UserRegSaveRequest getUserSaveReq(String name) throws KeyException, IOException { -//// accounts.get(name); -// return accounts.get(name); -// } } diff --git a/src/main/java/screens/login_registration/InMemoryUser.java b/src/main/java/screens/login_registration/InMemoryUser.java index 3dbdf06..77d11b2 100644 --- a/src/main/java/screens/login_registration/InMemoryUser.java +++ b/src/main/java/screens/login_registration/InMemoryUser.java @@ -1,13 +1,14 @@ package screens.login_registration; import use_cases.login_registration.login_usecase.LoginGateway; +import use_cases.login_registration.logout_usecase.LogoutGateway; import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; import use_cases.login_registration.user_register_usecase.UserRegGateway; import java.util.HashMap; import java.util.Map; -public class InMemoryUser implements UserRegGateway, LoginGateway { +public class InMemoryUser implements UserRegGateway, LoginGateway, LogoutGateway { final private Map users = new HashMap<>(); diff --git a/src/main/java/screens/login_registration/LoginScreen.java b/src/main/java/screens/login_registration/LoginScreen.java index 555232c..b5d49f8 100644 --- a/src/main/java/screens/login_registration/LoginScreen.java +++ b/src/main/java/screens/login_registration/LoginScreen.java @@ -1,6 +1,7 @@ package screens.login_registration; import screens.LabelTextPanel; +import use_cases.login_registration.login_usecase.LoginResponseModel; import javax.swing.*; import java.awt.*; @@ -9,7 +10,7 @@ import static javax.swing.JOptionPane.showMessageDialog; -public class LoginScreen extends JFrame implements ActionListener { +public class LoginScreen extends JPanel implements ActionListener { /** * The username chosen by the user */ @@ -21,8 +22,14 @@ public class LoginScreen extends JFrame implements ActionListener { LoginController loginController; - public LoginScreen(LoginController controller) { + CardLayout cardLayout; + + JPanel screens; + + public LoginScreen(LoginController controller, CardLayout cardLayout, JPanel screens) { this.loginController = controller; + this.cardLayout = cardLayout; + this.screens = screens; JLabel title = new JLabel("Login Screen"); title.setAlignmentX(Component.CENTER_ALIGNMENT); @@ -42,16 +49,17 @@ public LoginScreen(LoginController controller) { logIn.addActionListener(this); cancel.addActionListener(this); - JPanel main = new JPanel(); - main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); - - main.add(title); - main.add(usernameInfo); - main.add(passwordInfo); - main.add(buttons); - this.setContentPane(main); - - this.pack(); +// JPanel main = new JPanel(); +// main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + +// this.add(title); + this.add(usernameInfo); + this.add(passwordInfo); + this.add(buttons); +// this.setContentPane(main); +// +// this.pack(); } /** @@ -59,15 +67,23 @@ public LoginScreen(LoginController controller) { */ public void actionPerformed(ActionEvent evt) { System.out.println("Click " + evt.getActionCommand()); - - try { - loginController.create(username.getText(), - String.valueOf(password.getPassword())); - showMessageDialog(this, "% logged in.".format(username.getText())); - } catch (Exception e) { - showMessageDialog(this, e.getMessage()); - } catch (LoginFailed e) { - throw new RuntimeException(e); + if (evt.getActionCommand().equals("Cancel")) { + cardLayout.show(screens, "welcome"); + } else { + try { + LoginResponseModel l = loginController.create(username.getText(), + String.valueOf(password.getPassword())); + showMessageDialog(this, "% logged in.".format(username.getText())); + if (l.getTypeOfUser().equals("Instructor")) { + cardLayout.show(screens, "InstructorMain"); + } else { + cardLayout.show(screens, "main"); + } + } catch (Exception e) { + showMessageDialog(this, e.getMessage()); + } catch (LoginFailed e) { + throw new RuntimeException(e); + } } } diff --git a/src/main/java/screens/login_registration/LogoutResponseFormatter.java b/src/main/java/screens/login_registration/LogoutResponseFormatter.java new file mode 100644 index 0000000..c625e26 --- /dev/null +++ b/src/main/java/screens/login_registration/LogoutResponseFormatter.java @@ -0,0 +1,17 @@ +package screens.login_registration; + +import use_cases.login_registration.logout_usecase.LogoutPresenter; +import use_cases.login_registration.logout_usecase.LogoutResponseModel; + +public class LogoutResponseFormatter implements LogoutPresenter { + + /** + * @param logout the logout response + * @return the successful logout view + */ + @Override + public LogoutResponseModel prepareSuccessView(LogoutResponseModel logout) { + return logout; + } + +} diff --git a/src/main/java/screens/login_registration/RegisterScreen.java b/src/main/java/screens/login_registration/RegisterScreen.java index 3679d6d..69f9906 100644 --- a/src/main/java/screens/login_registration/RegisterScreen.java +++ b/src/main/java/screens/login_registration/RegisterScreen.java @@ -102,15 +102,24 @@ public RegisterScreen(UserRegController controller, CardLayout cardLayout, JPane public void actionPerformed(ActionEvent evt) { System.out.println("Click " + evt.getActionCommand()); - try { - userRegController.create(username.getText(), - String.valueOf(password.getPassword()), - String.valueOf(repeatPassword.getPassword()), - String.valueOf(typeOfUser.getText())); - showMessageDialog(this, "%s created.".format(username.getText())); - cardLayout.show(screens, "main"); - } catch (Exception e) { - showMessageDialog(this, e.getMessage()); + if (evt.getActionCommand().equals("Cancel")) { + cardLayout.show(screens, "welcome"); + } else { + try { + userRegController.create(username.getText(), + String.valueOf(password.getPassword()), + String.valueOf(repeatPassword.getPassword()), + String.valueOf(typeOfUser.getText())); + showMessageDialog(this, "%s created.".format(username.getText())); + if (String.valueOf(typeOfUser.getText()).equals("Student")) { + cardLayout.show(screens, "main"); + } else if (String.valueOf(typeOfUser.getText()).equals("Instructor")) { + cardLayout.show(screens, "InstructorMain"); + } + + } catch (Exception e) { + showMessageDialog(this, e.getMessage()); + } } } } \ No newline at end of file diff --git a/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java b/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java index ccbe8b1..2085d6f 100644 --- a/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java +++ b/src/main/java/use_cases/login_registration/login_usecase/LoginInteractor.java @@ -1,13 +1,11 @@ package use_cases.login_registration.login_usecase; import entities.InstructorUser; -import entities.StudentUser; import entities.User; import screens.login_registration.LoginFailed; -import use_cases.login_registration.user_register_usecase.InstructorSaveRequest; -import use_cases.login_registration.user_register_usecase.StudentSaveRequest; import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; + import java.time.LocalDateTime; public class LoginInteractor implements LoginInputBoundary { @@ -34,7 +32,7 @@ public LoginInteractor(LoginGateway loginGate, LoginPresenter loginPres) { * * @param requestModel the Login request (containing the user's input) * @return the response to this login request (whether it worked or not) - * @throws LoginFailed + * @throws LoginFailed if the username doesn't exist or the password is incorrect */ @Override public LoginResponseModel create(LoginRequestModel requestModel) throws LoginFailed { @@ -45,9 +43,16 @@ public LoginResponseModel create(LoginRequestModel requestModel) throws LoginFai } LocalDateTime now = LocalDateTime.now(); - LoginResponseModel loginRes = new LoginResponseModel(requestModel.getName(), now.toString()); this.user = createUser(requestModel); + + LoginResponseModel loginRes; + + if (this.user instanceof InstructorUser) { + loginRes = new LoginResponseModel(requestModel.getName(), now.toString(), "Instructor"); + } else { + loginRes = new LoginResponseModel(requestModel.getName(), now.toString(), "Student"); + } return loginPresenter.prepareSuccessView(loginRes); } @@ -56,20 +61,6 @@ private User createUser(LoginRequestModel requestModel) { // creating a new User object using the information in the UserRegSaveRequest UserRegSaveRequest userSave = loginGateway.getAccounts().get(requestModel.getName()); - User user; - if (userSave instanceof InstructorSaveRequest) { - user = new InstructorUser(userSave.getName(), userSave.getPass()); - ((InstructorUser) user).setCourses(((InstructorSaveRequest) userSave).getCourses()); - } else { - user = new StudentUser(userSave.getName(), userSave.getPass()); - ((StudentUser) user).setCourses(((StudentSaveRequest) userSave).getCourses()); - ((StudentUser) user).setToDoList(((StudentSaveRequest) userSave).getCourses()); - ((StudentUser) user).setTaskArchive(((StudentSaveRequest) userSave).getTaskArchive()); - ((StudentUser) user).setInbox(((StudentSaveRequest) userSave).getInbox()); - ((StudentUser) user).setNotifications(((StudentSaveRequest) userSave).getNotifications()); - ((StudentUser) user).setDesiredGrades(((StudentSaveRequest) userSave).getDesiredGrades()); - ((StudentUser) user).setWorkingHours(((StudentSaveRequest) userSave).getWorkingHours()); - } - return user; + return userSave.initializeUser(); } } diff --git a/src/main/java/use_cases/login_registration/login_usecase/LoginRequestModel.java b/src/main/java/use_cases/login_registration/login_usecase/LoginRequestModel.java index 4f1068a..8a3542a 100644 --- a/src/main/java/use_cases/login_registration/login_usecase/LoginRequestModel.java +++ b/src/main/java/use_cases/login_registration/login_usecase/LoginRequestModel.java @@ -18,11 +18,11 @@ public LoginRequestModel(String name, String password) { this.password = password; } - String getName() { return name; } + public String getName() { return name; } void setName(String name) { this.name = name; } - String getPass() { return password; } + public String getPass() { return password; } void setPass(String pass) { this.password = pass; diff --git a/src/main/java/use_cases/login_registration/login_usecase/LoginResponseModel.java b/src/main/java/use_cases/login_registration/login_usecase/LoginResponseModel.java index 3db6b5e..c592d69 100644 --- a/src/main/java/use_cases/login_registration/login_usecase/LoginResponseModel.java +++ b/src/main/java/use_cases/login_registration/login_usecase/LoginResponseModel.java @@ -9,19 +9,30 @@ public class LoginResponseModel { String loginTime; + String typeOfUser; + /** * @param username the name of the User that just logged in * @param timeOfLogin the time at which this User logged in */ - public LoginResponseModel(String username, String timeOfLogin) { + public LoginResponseModel(String username, String timeOfLogin, String typeOfUser) { this.name = username; this.loginTime = timeOfLogin; + this.typeOfUser = typeOfUser; } public String getName() { return name; } public void setName(String username) { this.name = username; } + public String getTypeOfUser() { return typeOfUser; } + + public void setTypeOfUser(String s) { + if (s.equals("Instructor") | s.equals("Student")) { + this.typeOfUser = s; + } + } + public String getLoginTime() { return loginTime; } diff --git a/src/main/java/use_cases/login_registration/logout_usecase/LogoutInteractor.java b/src/main/java/use_cases/login_registration/logout_usecase/LogoutInteractor.java index cab36bb..4470846 100644 --- a/src/main/java/use_cases/login_registration/logout_usecase/LogoutInteractor.java +++ b/src/main/java/use_cases/login_registration/logout_usecase/LogoutInteractor.java @@ -38,7 +38,7 @@ public LogoutInteractor(LogoutGateway gateway, LogoutPresenter logoutPresenter, * log out into the User database. * @param request the request to logout * @return the logout response - * @throws IOException + * @throws IOException if logout fails */ @Override public LogoutResponseModel create(LogoutRequestModel request) throws IOException { @@ -46,6 +46,7 @@ public LogoutResponseModel create(LogoutRequestModel request) throws IOException LocalDateTime now = LocalDateTime.now(); UserRegSaveRequest userModel; + if (user instanceof StudentUser) { userModel = new StudentSaveRequest(user.getName(), user.getPass(), (StudentUser) user, now); diff --git a/src/main/java/use_cases/login_registration/logout_usecase/LogoutPresenter.java b/src/main/java/use_cases/login_registration/logout_usecase/LogoutPresenter.java index 8ed055e..dfbcd97 100644 --- a/src/main/java/use_cases/login_registration/logout_usecase/LogoutPresenter.java +++ b/src/main/java/use_cases/login_registration/logout_usecase/LogoutPresenter.java @@ -8,4 +8,5 @@ public interface LogoutPresenter { */ LogoutResponseModel prepareSuccessView(LogoutResponseModel logout); + } diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/InstructorSaveRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/InstructorSaveRequest.java index a5b1732..e23528f 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/InstructorSaveRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/InstructorSaveRequest.java @@ -26,6 +26,9 @@ public class InstructorSaveRequest extends UserRegSaveRequest { */ public InstructorSaveRequest(String name, String password, InstructorUser instructor, LocalDateTime creationTime) { super(name, password, instructor, creationTime); + this.name = name; + this.password = password; + this.creationTime = creationTime; this.courses = instructor.getCourses(); } @@ -33,4 +36,11 @@ public ArrayList getCourses() { return this.courses; } + @Override + public InstructorUser initializeUser() { + InstructorUser i = new InstructorUser(this.name, this.password); + i.setCourses(this.courses); + return i; + } + } diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/StudentSaveRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/StudentSaveRequest.java index ed1da82..30d9163 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/StudentSaveRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/StudentSaveRequest.java @@ -1,5 +1,6 @@ package use_cases.login_registration.user_register_usecase; +import entities.InstructorUser; import entities.StudentUser; import java.time.LocalDateTime; @@ -40,6 +41,9 @@ public class StudentSaveRequest extends UserRegSaveRequest { */ public StudentSaveRequest(String name, String password, StudentUser student, LocalDateTime creationTime) { super(name, password, student, creationTime); + this.name = name; + this.password = password; + this.creationTime = creationTime; this.toDoList = student.getToDoList(); this.taskArchive = student.getTaskArchive(); this.courses = student.getCourses(); @@ -83,4 +87,17 @@ public ArrayList getWorkingHours() { return this.workingHours; } + @Override + public StudentUser initializeUser() { + StudentUser s = new StudentUser(this.name, this.password); + s.setCourses(this.courses); + s.setToDoList(this.toDoList); + s.setTaskArchive(this.getTaskArchive()); + s.setInbox(this.getInbox()); + s.setNotifications(this.getNotifications()); + s.setDesiredGrades(this.getDesiredGrades()); + s.setWorkingHours(this.getWorkingHours()); + return s; + } + } diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java index 04be09a..3561a7b 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegInteractor.java @@ -17,24 +17,25 @@ public class UserRegInteractor implements UserRegInputBoundary { final UserRegPresenter userPresenter; -// private UserFactory userFactory; + final UserFactory userFactory; private User user; /** * @param gateway the gateway that interacts with the User database * @param userRegPresenter the presenter that shows the success or failure of this attempt to register + * @param factory the factory that creates Users */ - public UserRegInteractor(UserRegGateway gateway, UserRegPresenter userRegPresenter) { + public UserRegInteractor(UserRegGateway gateway, UserRegPresenter userRegPresenter, UserFactory factory) { this.userGateway = gateway; this.userPresenter = userRegPresenter; -// this.userFactory = null; + this.userFactory = factory; } /** * @param request the request to register this user * @return the response to whether this request to register was successful - * @throws IOException + * @throws IOException if anything goes wrong */ @Override public UserRegResponse create(UserRegRequest request) throws IOException { @@ -46,22 +47,34 @@ public UserRegResponse create(UserRegRequest request) throws IOException { return userPresenter.prepareFailView("Enter either 'Instructor' or 'Student'."); } - UserFactory userFactory; + // can make userFactory have a createUser() method that takes in the Name, Pass, and typeOfUser + // and creates that type of user (with an if statement) + if (request.getTypeOfUser().equals("Instructor")) { - userFactory = new InstructorUserFactory(); - } else { - userFactory = new StudentUserFactory(); + this.user = userFactory.createInstructor(request.getName(), request.getPassword()); + } else //if (request.getTypeOfUser().equals("Student")) + { + this.user = userFactory.createStudent(request.getName(), request.getPassword()); } +// else { +// this.user = null; +// } - User user = userFactory.create(request.getName(), request.getPassword()); if (!user.checkPassword()) { return userPresenter.prepareFailView("Password must be at least 9 characters long"); } - this.user = user; - LocalDateTime now = LocalDateTime.now(); + UserRegSaveRequest userModel = getUserRegSaveRequest(now); + + userGateway.save(userModel); + + UserRegResponse accResponseModel = new UserRegResponse(user.getName(), now.toString()); + return userPresenter.prepareSuccessView(accResponseModel); + } + + private UserRegSaveRequest getUserRegSaveRequest(LocalDateTime now) { UserRegSaveRequest userModel; if (user instanceof StudentUser) { userModel = new StudentSaveRequest(user.getName(), user.getPass(), @@ -72,14 +85,32 @@ public UserRegResponse create(UserRegRequest request) throws IOException { } else { userModel = new UserRegSaveRequest(user.getName(), user.getPass(), user, now); } + return userModel; + } - userGateway.save(userModel); - - UserRegResponse accResponseModel = new UserRegResponse(user.getName(), now.toString()); - return userPresenter.prepareSuccessView(accResponseModel); + /** + * For testing purposes only!! Do not actually use. + * @param now time of creation + */ + public UserRegSaveRequest getUserSaveRequest(LocalDateTime now) { + UserRegSaveRequest userModel; + if (user instanceof StudentUser) { + userModel = new StudentSaveRequest(user.getName(), user.getPass(), + (StudentUser) user, now); + } else if (user instanceof InstructorUser) { + userModel = new InstructorSaveRequest(user.getName(), user.getPass(), + (InstructorUser) user, now); + } else { + userModel = new UserRegSaveRequest(user.getName(), user.getPass(), user, now); + } + return userModel; } public User getUser() { - return this.user; + if ((this.user instanceof StudentUser) | (this.user instanceof InstructorUser)) { + return this.user; + } else { + return null; + } } } diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegRequest.java index 967b30f..44d617c 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegRequest.java @@ -45,7 +45,7 @@ public void setReenterPassword(String reenterPassword) { String getTypeOfUser() { return typeOfUser; } - String setTypeOfUser(String userType) { + public String setTypeOfUser(String userType) { if (userType.equals("Instructor") | userType.equals("Student")) { this.typeOfUser = userType; return "Success"; diff --git a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java index 851b146..ea0005d 100644 --- a/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java +++ b/src/main/java/use_cases/login_registration/user_register_usecase/UserRegSaveRequest.java @@ -48,4 +48,12 @@ public LocalDateTime getCreationTime() { return creationTime; } + /** + * @return a User based on the information stored in this UserRegSaveRequest object + * Default is StudentUser + */ + public User initializeUser() { + return new StudentUser(this.name, this.password); + } + } diff --git a/src/main/java/users b/src/main/java/users deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/java/FileUserTest.java b/src/test/java/FileUserTest.java index 9f76778..f25e628 100644 --- a/src/test/java/FileUserTest.java +++ b/src/test/java/FileUserTest.java @@ -1,17 +1,65 @@ +import entities.InstructorUser; +import entities.StudentUser; import org.junit.jupiter.api.Test; -//import screens.FileUser2; +import screens.login_registration.FileUser; +import use_cases.login_registration.user_register_usecase.InstructorSaveRequest; +import use_cases.login_registration.user_register_usecase.StudentSaveRequest; + +import java.io.IOException; +import java.time.LocalDateTime; +import java.util.*; public class FileUserTest { + // Can it save a StudentUser and an InstructorUser? + // Can it read the file? Is the data preserved? + // Does it save updates to users? + + StudentUser student = new StudentUser("dhakaad", "badassb4real"); + InstructorUser instructor = new InstructorUser("zinda", "bollywood"); + StudentSaveRequest ssri = new StudentSaveRequest("dhakaad", "badassb4real", student, + LocalDateTime.now()); + InstructorSaveRequest bruh = new InstructorSaveRequest("zinda", "bollywood", instructor, + LocalDateTime.now()); + + public FileUserTest() throws IOException, ClassNotFoundException { + } + @Test - void saveStudentUser() { -// StudentUser student = new StudentUser("gma", "veryverysad"); -// StudentSaveRequest ssri = new StudentSaveRequest("gma", "veryverysad", student, -// LocalDateTime.now()); -// FileUser2 f_u = new FileUser2("./userstest.ser"); -// f_u.save(ssri); -// System.out.println(f_u.getAccounts()); + void saveUsers() throws IOException, ClassNotFoundException { + FileUser f_u = new FileUser("src/test/java/data/userstest.ser"); + f_u.save(ssri); + assert f_u.existsByName("dhakaad"); + f_u.save(bruh); + assert f_u.existsByName("zinda"); + } + + StudentSaveRequest ssri2 = new StudentSaveRequest("plant", "vanillawhey", student, + LocalDateTime.now()); + InstructorSaveRequest bruh2 = new InstructorSaveRequest("cacti", "waterbottle", + instructor, LocalDateTime.now()); + + @Test + void readUsers() throws IOException, ClassNotFoundException { + FileUser f_u2 = new FileUser("src/test/java/data/userstest.ser"); + f_u2.save(ssri2); + f_u2.save(bruh2); + Set s = f_u2.getAccounts().keySet(); + String[] names = {"zinda", "dhakaad", "plant", "cacti"}; + assert s.containsAll(List.of(names)); + } + + StudentSaveRequest ssri3 = new StudentSaveRequest("plant", "changedPass", student, + LocalDateTime.now()); + @Test + void updateUsers() throws IOException, ClassNotFoundException { + FileUser f_u3 = new FileUser("src/test/java/data/userstest.ser"); + f_u3.save(ssri3); + Map accounts = f_u3.getAccounts(); + StudentSaveRequest s = (StudentSaveRequest) accounts.get("plant"); + assert s.getPass().equals("changedPass"); + } diff --git a/src/test/java/data/userstest.ser b/src/test/java/data/userstest.ser new file mode 100644 index 0000000..4adea51 Binary files /dev/null and b/src/test/java/data/userstest.ser differ diff --git a/src/test/java/entities/UserFactoryTest.java b/src/test/java/entities/UserFactoryTest.java new file mode 100644 index 0000000..358318a --- /dev/null +++ b/src/test/java/entities/UserFactoryTest.java @@ -0,0 +1,36 @@ +package entities; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class UserFactoryTest { + + @Test + void testCreateStudentGoodPass() { + GeneralUserFactory g = new GeneralUserFactory(); + StudentUser s = g.createStudent("Fives", "123456789"); + // doing this because if it wasn't a StudentUser, it wouldn't compile + Assertions.assertTrue(s.checkPassword()); + } + + @Test + void testCreateInstructorGoodPass() { + GeneralUserFactory g = new GeneralUserFactory(); + InstructorUser s = g.createInstructor("Hardcase", "123456789"); + Assertions.assertTrue(s.checkPassword()); + } + + @Test + void testCreateStudentBadPass() { + GeneralUserFactory g = new GeneralUserFactory(); + StudentUser s = g.createStudent("Vaughn", "2468"); + Assertions.assertFalse(s.checkPassword()); + } + + @Test + void testCreateInstructorBadPass() { + GeneralUserFactory g = new GeneralUserFactory(); + InstructorUser s = g.createInstructor("Hardcase", "2468"); + Assertions.assertFalse(s.checkPassword()); + } +} diff --git a/src/test/java/entities/UserUnitTest.java b/src/test/java/entities/UserUnitTest.java new file mode 100644 index 0000000..ba0bb16 --- /dev/null +++ b/src/test/java/entities/UserUnitTest.java @@ -0,0 +1,51 @@ +package entities; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class UserUnitTest { + + @Test + void testShortPassStudent() { + User user = new StudentUser("Rex", "7567"); + + assertFalse(user.checkPassword()); + } + + @Test + void testShortPassInstructor() { + User user = new InstructorUser("Cody", "2224"); + + assertFalse(user.checkPassword()); + } + + @Test + void testGoodPassStudent() { + User user = new StudentUser("Ahsoka", "123456789"); + + assertTrue(user.checkPassword()); + } + + @Test + void testGoodPassInstructor() { + User user = new InstructorUser("Anakin", "123456789"); + + assertTrue(user.checkPassword()); + } + + @Test + void testNoPassInstructor() { + User user = new InstructorUser("Jesse", ""); + + assertFalse(user.checkPassword()); + } + + @Test + void testNoPassStudent() { + User user = new StudentUser("Cody", ""); + + assertFalse(user.checkPassword()); + } +} diff --git a/src/test/java/login_usecase/LoginInteractorTest.java b/src/test/java/login_usecase/LoginInteractorTest.java new file mode 100644 index 0000000..aad281d --- /dev/null +++ b/src/test/java/login_usecase/LoginInteractorTest.java @@ -0,0 +1,64 @@ +package login_usecase; + +import entities.GeneralUserFactory; +import entities.InstructorUser; +import entities.User; +import entities.UserFactory; +import org.junit.jupiter.api.Test; +import screens.login_registration.InMemoryUser; +import screens.login_registration.LoginFailed; +import screens.login_registration.LoginResponseFormatter; +import screens.login_registration.UserRegResponseFormatter; +import use_cases.login_registration.login_usecase.*; +import use_cases.login_registration.user_register_usecase.*; + +import java.io.IOException; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.fail; + +public class LoginInteractorTest { + + + @Test + void create() throws IOException, LoginFailed { + + InstructorUser u = new InstructorUser("paul", "pwd1234567"); + InstructorSaveRequest i = new InstructorSaveRequest("paul", "pwd1234567", + u, LocalDateTime.now()); + LoginGateway userRepository = new InMemoryUser(); + ((InMemoryUser) userRepository).save(i); + + // This creates an anonymous implementing class for the Output Boundary. + LoginPresenter presenter = new LoginResponseFormatter() { + + @Override + public LoginResponseModel prepareSuccessView(LoginResponseModel login) { + // 4) Check that the Output Data and associated changes + // are correct + assertEquals("paul", login.getName()); + assertNotNull(login.getLoginTime()); // any creation time is fine. + assertTrue(userRepository.existsByName("paul")); + return null; + } + + @Override + public LoginResponseModel prepareFailView(String error) { + fail("Use case failure is unexpected."); + return null; + } + }; + + LoginInteractor interactor = new LoginInteractor(userRepository, presenter); + + // 2) Input data — we can make this up for the test. Normally it would + // be created by the Controller. + LoginRequestModel inputData = new LoginRequestModel("paul", "pwd1234567"); + + // 3) Run the use case + interactor.create(inputData); + + } + +} diff --git a/src/test/java/logout_usecase/LogoutInteractorTest.java b/src/test/java/logout_usecase/LogoutInteractorTest.java new file mode 100644 index 0000000..be88ba4 --- /dev/null +++ b/src/test/java/logout_usecase/LogoutInteractorTest.java @@ -0,0 +1,58 @@ +package logout_usecase; + +import entities.GeneralUserFactory; +import entities.InstructorUser; +import entities.User; +import entities.UserFactory; +import org.junit.jupiter.api.Test; +import screens.login_registration.InMemoryUser; +import screens.login_registration.LogoutResponseFormatter; +import screens.login_registration.UserRegResponseFormatter; +import use_cases.login_registration.logout_usecase.*; +import use_cases.login_registration.user_register_usecase.*; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.fail; + +public class LogoutInteractorTest { + + @Test + void create() throws IOException { + + LogoutGateway userRepository = new InMemoryUser(); + + // This creates an anonymous implementing class for the Output Boundary. + LogoutPresenter presenter = new LogoutResponseFormatter() { + + @Override + public LogoutResponseModel prepareSuccessView(LogoutResponseModel logout) { + // 4) Check that the Output Data and associated changes + // are correct + assertEquals("paul", logout.getName()); + assertNotNull(logout.getLogoutTime()); // any creation time is fine. + return null; + } + + public LogoutResponseModel prepareFailView(String error) { + fail("Use case failure is unexpected."); + return null; + } + + }; + + User u = new InstructorUser("paul", "123456789"); + LogoutInputBoundary interactor = new LogoutInteractor(userRepository, presenter, u); + + // 2) Input data — we can make this up for the test. Normally it would + // be created by the Controller. + LogoutRequestModel request = new LogoutRequestModel(); + + // 3) Run the use case + interactor.create(request); + + // was the user saved after logout? + assert ((InMemoryUser) userRepository).existsByName("paul"); + } +} diff --git a/src/test/java/user_register_usecase/UserRegInteractorTest.java b/src/test/java/user_register_usecase/UserRegInteractorTest.java new file mode 100644 index 0000000..eaa43e6 --- /dev/null +++ b/src/test/java/user_register_usecase/UserRegInteractorTest.java @@ -0,0 +1,93 @@ +package user_register_usecase; + +import entities.GeneralUserFactory; +import entities.StudentUser; +import entities.UserFactory; +import org.junit.jupiter.api.Test; +import screens.login_registration.InMemoryUser; +import screens.login_registration.UserRegResponseFormatter; +import use_cases.login_registration.user_register_usecase.*; + +import java.io.IOException; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.fail; + +public class UserRegInteractorTest { + + @Test + void create() throws IOException { + // To test the use case: + // 1) Create a UserRegisterInteractor and prerequisite objects + // (arguments for the UserRegisterInteractor constructor parameters) + // 2) create the Input Data + // 3) Call the use case User Input Boundary method to run the use case + // 4) Check that the Output Data passed to the Presenter is correct + // 5) Check that the expected changes to the data layer are there. + + // 1) UserRegisterInteractor and prerequisite objects + // We're going to need a place to save and look up information. We could + // use FileUser, but because unit tests are supposed to be independent + // that would make us also reset the file when we are done. + // Instead, we're going to "mock" that info using a short-lived solution + // that just keeps the info in a dictionary, and it won't be persistent. + // (Separately, elsewhere, we will need to test the FileUser works + // properly.) + UserRegGateway userRepository = new InMemoryUser(); + + // This creates an anonymous implementing class for the Output Boundary. + UserRegPresenter presenter = new UserRegResponseFormatter() { + + @Override + public UserRegResponse prepareSuccessView(UserRegResponse user) { + // 4) Check that the Output Data and associated changes + // are correct + assertEquals("paul", user.getLogin()); + assertNotNull(user.getCreationTime()); // any creation time is fine. + assertTrue(userRepository.existsByName("paul")); + return null; + } + + @Override + public UserRegResponse prepareFailView(String error) { + fail("Use case failure is unexpected."); + return null; + } + }; + + UserFactory userFactory = new GeneralUserFactory(); + UserRegInputBoundary interactor = new UserRegInteractor( + userRepository, presenter, userFactory); + + // 2) Input data — we can make this up for the test. Normally it would + // be created by the Controller. + UserRegRequest inputData = new UserRegRequest( + "paul", "pwd1234567", "pwd1234567", "Student"); + + // 3) Run the use case + interactor.create(inputData); + } + + LocalDateTime now = LocalDateTime.now(); + StudentUser s = new StudentUser("Saje", "diffusers"); + UserRegGateway userRepository = new InMemoryUser(); + UserRegPresenter presenter = new UserRegResponseFormatter(); + UserFactory userFactory = new GeneralUserFactory(); + UserRegInputBoundary interactor2 = new UserRegInteractor(userRepository, presenter, userFactory); + UserRegRequest inputData = new UserRegRequest( + "Saje", "diffusers", "diffusers", "Student"); + + + @Test + void testGetUserRegSaveRequest() throws IOException { + + StudentSaveRequest ussr = new StudentSaveRequest("Saje", "diffusers", s, now); + ((UserRegInteractor) interactor2).create(inputData); + UserRegSaveRequest ussr2 = ((UserRegInteractor) interactor2).getUserSaveRequest(now); + assertTrue(ussr.getName().equals(ussr2.getName())); + assertTrue(ussr.getPass().equals(ussr2.getPass())); + assertTrue(ussr instanceof StudentSaveRequest); + + } +} diff --git a/src/test/java/user_register_usecase/UserRegRequestTest.java b/src/test/java/user_register_usecase/UserRegRequestTest.java new file mode 100644 index 0000000..eefd215 --- /dev/null +++ b/src/test/java/user_register_usecase/UserRegRequestTest.java @@ -0,0 +1,24 @@ +package user_register_usecase; + +import org.junit.jupiter.api.Test; +import use_cases.login_registration.user_register_usecase.UserRegRequest; + +public class UserRegRequestTest { + + @Test + void testSetTypeOfUserDoesntWork() { + // doesn't matter if password is valid or not, because UserRegRequest does not worry about that + UserRegRequest r = new UserRegRequest("Poha", "small", "small", + "Student"); + String s = r.setTypeOfUser("Stu"); + assert s.equals("User type can only be Instructor or Student"); + } + + @Test + void testSetTypeOfUserWorks() { + UserRegRequest r = new UserRegRequest("Poha", "small", "small", + "Student"); + String s = r.setTypeOfUser("Instructor"); + assert s.equals("Success"); + } +} diff --git a/src/test/java/user_register_usecase/UserRegSaveRequestTest.java b/src/test/java/user_register_usecase/UserRegSaveRequestTest.java new file mode 100644 index 0000000..3d8471b --- /dev/null +++ b/src/test/java/user_register_usecase/UserRegSaveRequestTest.java @@ -0,0 +1,37 @@ +package user_register_usecase; + +import entities.InstructorUser; +import entities.StudentUser; +import entities.User; +import org.junit.jupiter.api.Test; +import use_cases.login_registration.user_register_usecase.InstructorSaveRequest; +import use_cases.login_registration.user_register_usecase.StudentSaveRequest; +import use_cases.login_registration.user_register_usecase.UserRegSaveRequest; + +import java.time.LocalDateTime; + +public class UserRegSaveRequestTest { + + @Test + void testinitializeStudentUser() { + StudentUser u = new StudentUser("poodles", "flooperflopple"); + StudentSaveRequest ussr = new StudentSaveRequest("poodles", "flooperflopple", u, + LocalDateTime.now()); + User u2 = ussr.initializeUser(); + assert u2 != null; + assert u2.getName().equals("poodles"); + assert u2.getPass().equals("flooperflopple"); + } + + @Test + void testinitializeInstructorUser() { + InstructorUser u = new InstructorUser("poodles", "flooperflopple"); + InstructorSaveRequest ussr = new InstructorSaveRequest("poodles", "flooperflopple", u, + LocalDateTime.now()); + User u2 = ussr.initializeUser(); + assert u2 != null; + assert u2.getName().equals("poodles"); + assert u2.getPass().equals("flooperflopple"); + } + +}