Search in sources :

Example 11 with UserStore

use of codeu.model.store.basic.UserStore in project codeu-2018-team12 by codeu-2018-team12.

the class RegisterServletTest method testDoPost_ExistingUser.

@Test
public void testDoPost_ExistingUser() throws IOException, ServletException {
    Mockito.when(mockRequest.getParameter("username")).thenReturn("test username");
    Mockito.when(mockRequest.getParameter("password")).thenReturn("test password");
    Mockito.when(mockRequest.getParameter("confirmPassword")).thenReturn("test password");
    UserStore mockUserStore = Mockito.mock(UserStore.class);
    Mockito.when(mockUserStore.isUserRegistered("test username")).thenReturn(true);
    registerServlet.setUserStore(mockUserStore);
    ActivityStore mockActivityStore = Mockito.mock(ActivityStore.class);
    registerServlet.setActivityStore(mockActivityStore);
    HttpSession mockSession = Mockito.mock(HttpSession.class);
    Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
    registerServlet.doPost(mockRequest, mockResponse);
    Mockito.verify(mockRequest).setAttribute("error", "That username is already taken.");
    Mockito.verify(mockUserStore, Mockito.never()).addUser(Mockito.any(User.class));
    Mockito.verify(mockActivityStore, Mockito.never()).addActivity(Mockito.any(Activity.class));
}
Also used : ActivityStore(codeu.model.store.basic.ActivityStore) UserStore(codeu.model.store.basic.UserStore) User(codeu.model.data.User) HttpSession(javax.servlet.http.HttpSession) Activity(codeu.model.data.Activity) Test(org.junit.Test)

Example 12 with UserStore

use of codeu.model.store.basic.UserStore in project codeu-2018-team12 by codeu-2018-team12.

the class ConversationTest method testCreate.

@Test
public void testCreate() {
    UUID id = UUID.randomUUID();
    UUID owner = UUID.randomUUID();
    String title = "Test_Title";
    Instant creation = Instant.now();
    Conversation conversation = new Conversation(id, owner, title, creation);
    UserStore userStore = UserStore.getInstance();
    User ownerUser = userStore.getUser(owner);
    List<User> conversationUsers = conversation.getConversationUsers();
    Assert.assertEquals(id, conversation.getId());
    Assert.assertEquals(owner, conversation.getOwnerId());
    Assert.assertEquals(title, conversation.getTitle());
    Assert.assertEquals(creation, conversation.getCreationTime());
    Assert.assertTrue(conversationUsers.contains(ownerUser));
}
Also used : UserStore(codeu.model.store.basic.UserStore) Instant(java.time.Instant) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with UserStore

use of codeu.model.store.basic.UserStore in project CodeU-Spring-2018 by maksymko.

the class LoginServletTest method testDoPost_ExistingUserWrongPassword.

@Test
public void testDoPost_ExistingUserWrongPassword() throws IOException, ServletException {
    Mockito.when(mockRequest.getParameter("username")).thenReturn("test username");
    Mockito.when(mockRequest.getParameter("password")).thenReturn("wrong password");
    UserStore mockUserStore = Mockito.mock(UserStore.class);
    loginServlet.setUserStore(mockUserStore);
    Mockito.when(mockUserStore.isUserRegistered("test username")).thenReturn(true);
    User mockUser = Mockito.mock(User.class);
    Mockito.when(mockUserStore.getUser("test username")).thenReturn(mockUser);
    Mockito.when(mockUser.getPassword()).thenReturn(BCrypt.hashpw("correct password", BCrypt.gensalt()));
    loginServlet.doPost(mockRequest, mockResponse);
    Mockito.verify(mockRequest).setAttribute("error", "Invalid password.");
    Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Also used : UserStore(codeu.model.store.basic.UserStore) User(codeu.model.data.User) Test(org.junit.Test)

Example 14 with UserStore

use of codeu.model.store.basic.UserStore in project CodeU-Spring-2018 by maksymko.

the class RegisterServletTest method testDoPost_ExistingUser.

@Test
public void testDoPost_ExistingUser() throws IOException, ServletException {
    Mockito.when(mockRequest.getParameter("username")).thenReturn("test username");
    UserStore mockUserStore = Mockito.mock(UserStore.class);
    Mockito.when(mockUserStore.isUserRegistered("test username")).thenReturn(true);
    registerServlet.setUserStore(mockUserStore);
    HttpSession mockSession = Mockito.mock(HttpSession.class);
    Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
    registerServlet.doPost(mockRequest, mockResponse);
    Mockito.verify(mockRequest).setAttribute("error", "That username is already taken.");
    Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Also used : UserStore(codeu.model.store.basic.UserStore) HttpSession(javax.servlet.http.HttpSession) Test(org.junit.Test)

Example 15 with UserStore

use of codeu.model.store.basic.UserStore in project CodeU-Spring-2018 by jwang281.

the class LoginServletTest method testDoPost_UnregisteredUser.

@Test
public void testDoPost_UnregisteredUser() throws IOException, ServletException {
    UserStore mockUserStore = Mockito.mock(UserStore.class);
    Mockito.when(mockUserStore.isUserRegistered("unregistered_username")).thenReturn(false);
    loginServlet.setUserStore(mockUserStore);
    HttpSession mockSession = Mockito.mock(HttpSession.class);
    Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
    loginServlet.doPost(mockRequest, mockResponse);
    Mockito.verify(mockRequest).setAttribute("error", "That username was not found.");
    Mockito.verify(mockRequestDispatcher).forward(mockRequest, mockResponse);
}
Also used : UserStore(codeu.model.store.basic.UserStore) HttpSession(javax.servlet.http.HttpSession) Test(org.junit.Test)

Aggregations

UserStore (codeu.model.store.basic.UserStore)17 Test (org.junit.Test)17 HttpSession (javax.servlet.http.HttpSession)14 User (codeu.model.data.User)12 Activity (codeu.model.data.Activity)2 ActivityStore (codeu.model.store.basic.ActivityStore)2 Instant (java.time.Instant)1 UUID (java.util.UUID)1