Search in sources :

Example 16 with UserPropertiesV1

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

the class UserDaoImplTest method test.

@Test
public void test() {
    assertEquals(0, _dao.getNumberOfUserRoles());
    UserRole adminRole = new UserRole("admin");
    UserRole userRole = new UserRole("user");
    _dao.saveOrUpdateUserRole(adminRole);
    _dao.saveOrUpdateUserRole(userRole);
    assertEquals(2, _dao.getNumberOfUserRoles());
    assertEquals(0, _dao.getNumberOfUsersWithRole(adminRole));
    assertEquals(0, _dao.getNumberOfUsersWithRole(userRole));
    User userA = new User();
    userA.setCreationTime(new Date());
    userA.setProperties(new UserPropertiesV1());
    userA.getRoles().add(userRole);
    _dao.saveOrUpdateUser(userA);
    assertEquals(0, _dao.getNumberOfUsersWithRole(adminRole));
    assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
    User userB = new User();
    userB.setCreationTime(new Date());
    userB.setProperties(new UserPropertiesV1());
    userB.getRoles().add(adminRole);
    _dao.saveOrUpdateUser(userB);
    assertEquals(1, _dao.getNumberOfUsersWithRole(adminRole));
    assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
    userA.getRoles().add(adminRole);
    _dao.saveOrUpdateUser(userA);
    assertEquals(2, _dao.getNumberOfUsersWithRole(adminRole));
    assertEquals(1, _dao.getNumberOfUsersWithRole(userRole));
}
Also used : User(org.onebusaway.users.model.User) UserRole(org.onebusaway.users.model.UserRole) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Date(java.util.Date) Test(org.junit.Test)

Example 17 with UserPropertiesV1

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

the class UserPropertiesMigrationImplTest method testNeedsMigration.

@Test
public void testNeedsMigration() {
    UserPropertiesV1 v1 = new UserPropertiesV1();
    assertFalse(_service.needsMigration(v1, UserPropertiesV1.class));
    assertTrue(_service.needsMigration(v1, UserPropertiesV2.class));
    UserPropertiesV2 v2 = new UserPropertiesV2();
    assertTrue(_service.needsMigration(v2, UserPropertiesV1.class));
    assertFalse(_service.needsMigration(v2, UserPropertiesV2.class));
}
Also used : UserPropertiesV2(org.onebusaway.users.model.properties.UserPropertiesV2) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Test(org.junit.Test)

Example 18 with UserPropertiesV1

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

the class UserPropertiesServiceV1ImplTest method testMergeUsers03.

@Test
public void testMergeUsers03() throws BookmarkException {
    User userA = createUser();
    _service.setLastSelectedStopIds(userA, Arrays.asList("A"));
    _service.setDefaultLocation(userA, "here", 47.0, -122.0);
    _service.addStopBookmark(userA, "bookmark a", Arrays.asList("A", "C"), new RouteFilter());
    User userB = createUser();
    _service.setLastSelectedStopIds(userB, Arrays.asList("B"));
    _service.setDefaultLocation(userB, "there", 48.0, -123.0);
    _service.addStopBookmark(userB, "bookmark b", Arrays.asList("B", "A"), new RouteFilter());
    _service.mergeProperties(userA, userB);
    UserPropertiesV1 props = getProperties(userB);
    List<String> bookmarks = props.getBookmarkedStopIds();
    assertEquals(4, bookmarks.size());
    assertEquals("B", bookmarks.get(0));
    assertEquals("A", bookmarks.get(1));
    assertEquals("A", bookmarks.get(2));
    assertEquals("C", bookmarks.get(3));
    assertEquals("there", props.getDefaultLocationName());
    assertEquals(48.0, props.getDefaultLocationLat(), 0.0);
    assertEquals(-123.0, props.getDefaultLocationLon(), 0.0);
    assertEquals("B", props.getLastSelectedStopId());
}
Also used : User(org.onebusaway.users.model.User) RouteFilter(org.onebusaway.users.model.properties.RouteFilter) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Test(org.junit.Test)

Example 19 with UserPropertiesV1

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

the class UserPropertiesServiceV1ImplTest method testMergeUsers01.

@Test
public void testMergeUsers01() throws BookmarkException {
    User userA = createUser();
    _service.setLastSelectedStopIds(userA, Arrays.asList("A"));
    _service.addStopBookmark(userA, "bookmark a", Arrays.asList("A", "C"), new RouteFilter());
    User userB = createUser();
    _service.setDefaultLocation(userB, "here", 47.0, -122.0);
    _service.addStopBookmark(userB, "bookmark b", Arrays.asList("C", "B"), new RouteFilter());
    _service.mergeProperties(userA, userB);
    UserPropertiesV1 props = getProperties(userB);
    List<String> bookmarks = props.getBookmarkedStopIds();
    assertEquals(4, bookmarks.size());
    assertEquals("C", bookmarks.get(0));
    assertEquals("B", bookmarks.get(1));
    assertEquals("A", bookmarks.get(2));
    assertEquals("C", bookmarks.get(3));
    assertEquals("here", props.getDefaultLocationName());
    assertEquals(47.0, props.getDefaultLocationLat(), 0.0);
    assertEquals(-122.0, props.getDefaultLocationLon(), 0.0);
    assertEquals("A", props.getLastSelectedStopId());
}
Also used : User(org.onebusaway.users.model.User) RouteFilter(org.onebusaway.users.model.properties.RouteFilter) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Test(org.junit.Test)

Example 20 with UserPropertiesV1

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

the class UserPropertiesServiceV1ImplTest method testMergeUsers02.

@Test
public void testMergeUsers02() throws BookmarkException {
    User userA = createUser();
    _service.setLastSelectedStopIds(userA, Arrays.asList("A"));
    _service.setDefaultLocation(userA, "here", 47.0, -122.0);
    _service.addStopBookmark(userA, "bookmark A", Arrays.asList("A", "C"), new RouteFilter());
    User userB = createUser();
    _service.mergeProperties(userA, userB);
    UserPropertiesV1 props = getProperties(userB);
    List<String> bookmarks = props.getBookmarkedStopIds();
    assertEquals(2, bookmarks.size());
    assertEquals("A", bookmarks.get(0));
    assertEquals("C", bookmarks.get(1));
    assertEquals("here", props.getDefaultLocationName());
    assertEquals(47.0, props.getDefaultLocationLat(), 0.0);
    assertEquals(-122.0, props.getDefaultLocationLon(), 0.0);
    assertEquals("A", props.getLastSelectedStopId());
}
Also used : User(org.onebusaway.users.model.User) RouteFilter(org.onebusaway.users.model.properties.RouteFilter) UserPropertiesV1(org.onebusaway.users.model.UserPropertiesV1) Test(org.junit.Test)

Aggregations

UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)20 Test (org.junit.Test)9 User (org.onebusaway.users.model.User)7 RouteFilter (org.onebusaway.users.model.properties.RouteFilter)4 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)4 Date (java.util.Date)3 Bookmark (org.onebusaway.users.model.properties.Bookmark)3 HashSet (java.util.HashSet)1 BookmarkBean (org.onebusaway.users.client.model.BookmarkBean)1 UserProperties (org.onebusaway.users.model.UserProperties)1 UserRole (org.onebusaway.users.model.UserRole)1 UserPropertiesV3 (org.onebusaway.users.model.properties.UserPropertiesV3)1 UserPropertiesV4 (org.onebusaway.users.model.properties.UserPropertiesV4)1