Search in sources :

Example 51 with User

use of org.summerb.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.users.api.dto.User) Test(org.junit.Test)

Example 52 with User

use of org.summerb.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.users.api.dto.User) Test(org.junit.Test)

Example 53 with User

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

the class UserCachedTest method testDeleteUser_expectUserNotFoundException.

// (expected=UserNotFoundException.class)
@Test
public void testDeleteUser_expectUserNotFoundException() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate = userService.createUser(userToCreate);
    userService.getUserByUuid(userToCreate.getUuid());
    userService.deleteUserByUuid(userToCreate.getUuid());
    try {
        userService.getUserByUuid(userToCreate.getUuid());
        fail();
    } catch (UserNotFoundException e) {
    }
}
Also used : UserNotFoundException(org.summerb.users.api.exceptions.UserNotFoundException) User(org.summerb.users.api.dto.User) Test(org.junit.Test)

Example 54 with User

use of org.summerb.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.users.api.dto.User) Date(java.util.Date) Test(org.junit.Test)

Example 55 with User

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

the class UserServiceCachedImpl method afterPropertiesSet.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void afterPropertiesSet() throws Exception {
    CacheBuilder cacheBuilder = (CacheBuilder) CacheBuilder.newBuilder().maximumSize(1000).recordStats();
    cacheByEmail = new TransactionBoundCache<String, User>("UserCacheByEmail", cacheBuilder, loaderByEmail);
    cacheByUuid = new TransactionBoundCache<String, User>("UserCacheByUuid", cacheBuilder, loaderByUuid);
    eventBus.register(this);
}
Also used : User(org.summerb.users.api.dto.User) CacheBuilder(com.google.common.cache.CacheBuilder)

Aggregations

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