Search in sources :

Example 26 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserPropertiesServiceV1ImplTest method createUser.

private User createUser() {
    User user = new User();
    user.setProperties(new UserPropertiesV1());
    return user;
}
Also used : User(org.onebusaway.users.model.User) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1)

Example 27 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserServiceImplTest method testCompletePhoneNumberRegistration.

@Test
public void testCompletePhoneNumberRegistration() {
    User userA = createUser(1234);
    UserIndexKey key = new UserIndexKey(UserIndexTypes.PHONE_NUMBER, "12065551234");
    UserDao userDao = Mockito.mock(UserDao.class);
    _service.setUserDao(userDao);
    Mockito.when(userDao.getUserForId(1234)).thenReturn(userA);
    UserIndex migratedIndex = new UserIndex();
    migratedIndex.setId(key);
    migratedIndex.setUser(userA);
    migratedIndex.setCredentials("");
    Mockito.when(userDao.getUserIndexForId(key)).thenReturn(migratedIndex);
    UserIndexRegistrationService registrationService = Mockito.mock(UserIndexRegistrationService.class);
    _service.setUserIndexRegistrationService(registrationService);
    UserRegistration registration = new UserRegistration(1234, "5555");
    Mockito.when(registrationService.getRegistrationForUserIndexKey(key)).thenReturn(registration);
    UserPropertiesService userPropertiesService = Mockito.mock(UserPropertiesService.class);
    _service.setUserPropertiesService(userPropertiesService);
    User userB = createUser(1235);
    UserIndex index = createUserIndex(key.getType(), key.getValue(), userB);
    UserIndex updated = _service.completePhoneNumberRegistration(index, "5554");
    assertTrue(updated == null);
    updated = _service.completePhoneNumberRegistration(index, "5555");
    assertTrue(updated != null);
    Mockito.verify(userPropertiesService).mergeProperties(userB, userA);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserIndexRegistrationService(org.onebusaway.users.services.internal.UserIndexRegistrationService) UserDao(org.onebusaway.users.services.UserDao) UserPropertiesService(org.onebusaway.users.services.UserPropertiesService) UserRegistration(org.onebusaway.users.services.internal.UserRegistration) Test(org.junit.Test)

Example 28 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserServiceImplTest method testRegisterPhoneNumber.

@Test
public void testRegisterPhoneNumber() {
    User user = createUser(1234);
    double total = 0;
    int n = 100;
    for (int i = 0; i < n; i++) {
        UserIndexRegistrationService registration = Mockito.mock(UserIndexRegistrationService.class);
        _service.setUserIndexRegistrationService(registration);
        String code = _service.registerPhoneNumber(user, "+12065551234");
        UserIndexKey key = new UserIndexKey(UserIndexTypes.PHONE_NUMBER, "12065551234");
        Mockito.verify(registration).setRegistrationForUserIndexKey(key, 1234, code);
        int codeAsNumber = Integer.parseInt(code);
        assertTrue(codeAsNumber >= 1000);
        assertTrue(codeAsNumber <= 9999);
        total += codeAsNumber;
    }
    double mu = total / n;
    assertEquals(5500, mu, 1000);
}
Also used : UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserIndexRegistrationService(org.onebusaway.users.services.internal.UserIndexRegistrationService) Test(org.junit.Test)

Example 29 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class UserServiceImplTest method createUser.

private User createUser(int userId) {
    User user = new User();
    user.setId(userId);
    user.setCreationTime(new Date());
    return user;
}
Also used : User(org.onebusaway.users.model.User) Date(java.util.Date)

Example 30 with User

use of org.onebusaway.users.model.User in project onebusaway-application-modules by camsys.

the class KeysResource method saveOrUpdateKey.

// Private methods
private void saveOrUpdateKey(String apiKey, Long minApiRequestInterval, String contactName, String contactCompany, String contactEmail, String contactDetails) throws Exception {
    UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
    UserIndex userIndexForId = _userService.getUserIndexForId(key);
    if (userIndexForId != null) {
        throw new Exception("API key " + apiKey + " already exists.");
    }
    UserIndex userIndex = _userService.getOrCreateUserForIndexKey(key, "", true);
    _userPropertiesService.authorizeApi(userIndex.getUser(), minApiRequestInterval);
    // Set the API Key contact info
    User user = userIndex.getUser();
    _userPropertiesService.updateApiKeyContactInfo(user, contactName, contactCompany, contactEmail, contactDetails);
    // Clear the cached value here
    _userService.getMinApiRequestIntervalForKey(apiKey, true);
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

User (org.onebusaway.users.model.User)56 UserIndex (org.onebusaway.users.model.UserIndex)23 UserIndexKey (org.onebusaway.users.model.UserIndexKey)16 Test (org.junit.Test)13 Date (java.util.Date)9 UserBean (org.onebusaway.users.client.model.UserBean)8 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)7 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 List (java.util.List)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)4 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)4 Criteria (org.hibernate.Criteria)4 HibernateException (org.hibernate.HibernateException)4 Session (org.hibernate.Session)4 UserDetail (org.onebusaway.admin.model.ui.UserDetail)4 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)4 UserRole (org.onebusaway.users.model.UserRole)3