Search in sources :

Example 51 with User

use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.

the class LoginServletTest method testDoPost_BadPass.

@Test
public void testDoPost_BadPass() throws IOException, ServletException {
    Mockito.when(mockRequest.getParameter("username")).thenReturn("test_username");
    Mockito.when(mockRequest.getParameter("password")).thenReturn("badpass");
    UserStore mockUserStore = Mockito.mock(UserStore.class);
    Mockito.when(mockUserStore.isUserRegistered("test_username")).thenReturn(true);
    String hashedPassword = BCrypt.hashpw("password", BCrypt.gensalt());
    User testUser = new User(UUID.randomUUID(), "test_username", hashedPassword, "test biography", Instant.now());
    Mockito.when(mockUserStore.getUser("test_username")).thenReturn(testUser);
    loginServlet.setUserStore(mockUserStore);
    HttpSession mockSession = Mockito.mock(HttpSession.class);
    Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
    loginServlet.doPost(mockRequest, mockResponse);
    Mockito.verify(mockUserStore, Mockito.never()).addUser(Mockito.any(User.class));
    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) HttpSession(javax.servlet.http.HttpSession) Test(org.junit.Test)

Example 52 with User

use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.

the class UserStoreTest method testGetUser_byUsername_notFound.

@Test
public void testGetUser_byUsername_notFound() {
    User resultUser = userStore.getUser("fake username");
    Assert.assertNull(resultUser);
}
Also used : User(codeu.model.data.User) Test(org.junit.Test)

Example 53 with User

use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.

the class UserStoreTest method testGetUser_byUsername_found.

@Test
public void testGetUser_byUsername_found() {
    User resultUser = userStore.getUser(USER_ONE.getName());
    assertEquals(USER_ONE, resultUser);
}
Also used : User(codeu.model.data.User) Test(org.junit.Test)

Example 54 with User

use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.

the class UserStoreTest method testGetUser_byId_found.

@Test
public void testGetUser_byId_found() {
    User resultUser = userStore.getUser(USER_ONE.getId());
    assertEquals(USER_ONE, resultUser);
}
Also used : User(codeu.model.data.User) Test(org.junit.Test)

Example 55 with User

use of codeu.model.data.User in project codeu-2018-team12 by codeu-2018-team12.

the class UserStoreTest method testAddUser.

@Test
public void testAddUser() {
    User inputUser = new User(UUID.randomUUID(), "test_username", "password", null, Instant.now());
    userStore.addUser(inputUser);
    User resultUser = userStore.getUser("test_username");
    assertEquals(inputUser, resultUser);
    Mockito.verify(mockPersistentStorageAgent).writeThrough(inputUser);
}
Also used : User(codeu.model.data.User) Test(org.junit.Test)

Aggregations

User (codeu.model.data.User)91 Test (org.junit.Test)60 Conversation (codeu.model.data.Conversation)36 Message (codeu.model.data.Message)23 UserStore (codeu.model.store.basic.UserStore)9 UUID (java.util.UUID)9 HttpSession (javax.servlet.http.HttpSession)8 Activity (codeu.model.data.Activity)7 Instant (java.time.Instant)7 ArrayList (java.util.ArrayList)7 PersistentDataStoreException (codeu.model.store.persistence.PersistentDataStoreException)2 Entity (com.google.appengine.api.datastore.Entity)2 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)2 Query (com.google.appengine.api.datastore.Query)2 Comparator (java.util.Comparator)2 ActivityStore (codeu.model.store.basic.ActivityStore)1 OutputSettings (org.jsoup.nodes.Document.OutputSettings)1