Search in sources :

Example 21 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserCachedTest method testUpdateUser_expectReferencesNonEqualityForReturnedDtos.

@Test
public void testUpdateUser_expectReferencesNonEqualityForReturnedDtos() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate.setDisplayName("Display name");
    userToCreate = userService.createUser(userToCreate);
    User foundUser = userService.getUserByUuid(userToCreate.getUuid());
    userToCreate.setDisplayName("Another display name");
    userService.updateUser(userToCreate);
    User foundUserAgain = userService.getUserByUuid(userToCreate.getUuid());
    assertTrue(foundUser != foundUserAgain);
    assertTrue(foundUserAgain.getDisplayName().equals("Another display name"));
}
Also used : User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Example 22 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserCachedTest method testPerformance_expectCacheFaster.

@Test
public void testPerformance_expectCacheFaster() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate = userService.createUser(userToCreate);
    int cycles = 1000;
    long before = new Date().getTime();
    for (int i = 0; i < cycles; i++) {
        userService.getUserByUuid(userToCreate.getUuid());
    }
    long after = new Date().getTime() - before;
    long beforeNonCached = new Date().getTime();
    for (int i = 0; i < cycles; i++) {
        userServiceNonCached.getUserByUuid(userToCreate.getUuid());
    }
    long afterNonCached = new Date().getTime() - beforeNonCached;
    System.out.println("Cached: " + after + "ms");
    System.out.println("Noncached: " + afterNonCached + "ms");
    assertTrue(afterNonCached / 5 > after);
}
Also used : User(org.summerb.microservices.users.api.dto.User) Date(java.util.Date) Test(org.junit.Test)

Example 23 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserCachedTest method testGetUserByEmail_expectReferencesEqualityForReturnedDtos.

@Test
public void testGetUserByEmail_expectReferencesEqualityForReturnedDtos() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate = userService.createUser(userToCreate);
    User foundUser = userService.getUserByEmail(userToCreate.getEmail());
    User foundUserCached = userService.getUserByEmail(userToCreate.getEmail());
    assertTrue(foundUser == foundUserCached);
}
Also used : User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Example 24 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserCachedTest method testGetUserByUuid_expectReferencesEqualityForReturnedDtos.

@Test
public void testGetUserByUuid_expectReferencesEqualityForReturnedDtos() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate = userService.createUser(userToCreate);
    User foundUser = userService.getUserByUuid(userToCreate.getUuid());
    User foundUserCached = userService.getUserByUuid(userToCreate.getUuid());
    assertTrue(foundUser == foundUserCached);
}
Also used : User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Example 25 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserDaoImplTest method testFindUsersByDisplayNamePartial_expectUsersWillBeFound.

@Test
public void testFindUsersByDisplayNamePartial_expectUsersWillBeFound() throws Exception {
    User user = UserFactory.createNewUserTemplate();
    user.setDisplayName("oneUHapqoiwez");
    user.setEmail("email1@aaa.ru");
    userService.createUser(user);
    user = UserFactory.createNewUserTemplate();
    user.setDisplayName("twoUHapqoiwez");
    user.setEmail("email2@aaa.ru");
    userService.createUser(user);
    user = UserFactory.createNewUserTemplate();
    user.setDisplayName("threeUHapqoiwez");
    user.setEmail("email3@aaa.ru");
    userService.createUser(user);
    user = UserFactory.createNewUserTemplate();
    user.setDisplayName("other");
    user.setEmail("other@aaa.ru");
    userService.createUser(user);
    PaginatedList<User> results = userService.findUsersByDisplayNamePartial("UHapqoiwez", new PagerParams());
    assertNotNull(results);
    assertNotNull(results.getItems());
    assertTrue(results.getItems().size() == 3);
    assertTrue(results.getTotalResults() == 3);
    results = userService.findUsersByDisplayNamePartial("eUHapqoiwez", new PagerParams());
    assertTrue(results.getItems().size() == 2);
    assertTrue(results.getTotalResults() == 2);
    results = userService.findUsersByDisplayNamePartial("UHapqoiwez", new PagerParams(0, 1));
    assertTrue(results.getItems().size() == 1);
    assertTrue(results.getTotalResults() == 3);
}
Also used : User(org.summerb.microservices.users.api.dto.User) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) Test(org.junit.Test)

Aggregations

User (org.summerb.microservices.users.api.dto.User)61 Test (org.junit.Test)34 UserNotFoundException (org.summerb.microservices.users.api.exceptions.UserNotFoundException)13 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)11 AuthToken (org.summerb.microservices.users.api.dto.AuthToken)11 UserServiceUnexpectedException (org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Date (java.util.Date)4 PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)4 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 InvalidPasswordException (org.summerb.microservices.users.api.exceptions.InvalidPasswordException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 UserDetailsImpl (org.summerb.approaches.springmvc.security.dto.UserDetailsImpl)2 ValidationContext (org.summerb.approaches.validation.ValidationContext)2 GenericException (org.summerb.utils.exceptions.GenericException)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 EventBus (com.google.common.eventbus.EventBus)1 Gson (com.google.gson.Gson)1 Locale (java.util.Locale)1 Secured (org.springframework.security.access.annotation.Secured)1