@Test(expected = EmailExistsException.class) public void shouldNotAllowDuplicateEmails() { allMotechUsers.add( new MotechUserCouchdbImpl( "user1", "testpassword", "*****@*****.**", "id", asList("ADMIN"), "")); allMotechUsers.add( new MotechUserCouchdbImpl( "user2", "testpassword1", "*****@*****.**", "id2", asList("ADMIN"), "")); }
@Test public void findByUserNameShouldBeCaseInsensitive() { String userName = "******"; allMotechUsers.add( new MotechUserCouchdbImpl(userName, "testpassword", "", "id", asList("ADMIN"), "")); assertNotNull(allMotechUsers.findByUserName("TESTUSER")); }
@Test public void shouldNotCreateNewAccountIfUserAlreadyExists() { String userName = "******"; allMotechUsers.add( new MotechUserCouchdbImpl(userName, "testpassword", "", "id", asList("ADMIN"), "")); allMotechUsers.add( new MotechUserCouchdbImpl(userName, "testpassword1", "", "id2", asList("ADMIN"), "")); MotechUser motechUser = allMotechUsers.findByUserName("userName"); final List<MotechUserCouchdbImpl> allWebUsers = ((AllMotechUsersCouchdbImpl) allMotechUsers).getAll(); final int numberOfUsersWithSameUserName = Lambda.select(allWebUsers, HasPropertyWithValue.hasProperty("userName", equalTo(userName))) .size(); assertEquals(1, numberOfUsersWithSameUserName); assertEquals("testpassword", motechUser.getPassword()); assertEquals("id", motechUser.getExternalId()); }
@Test public void findByUserName() { MotechUser motechUser = new MotechUserCouchdbImpl("testuser", "testpassword", "", "id", asList("ADMIN"), ""); allMotechUsers.add(motechUser); MotechUser testUser = allMotechUsers.findByUserName("testuser"); assertEquals("testuser", testUser.getUserName()); }
@Test public void shouldListWebUsersByRole() { MotechUser provider1 = new MotechUserCouchdbImpl( "provider1", "testpassword", "*****@*****.**", "id1", asList("PROVIDER"), ""); MotechUser provider2 = new MotechUserCouchdbImpl( "provider2", "testpassword", "*****@*****.**", "id2", asList("PROVIDER"), ""); MotechUser cmfAdmin = new MotechUserCouchdbImpl( "cmfadmin", "testpassword", "*****@*****.**", "id3", asList("CMFADMIN"), ""); MotechUser itAdmin = new MotechUserCouchdbImpl( "itadmin", "testpassword", "*****@*****.**", "id4", asList("ITADMIN"), ""); allMotechUsers.add(provider1); allMotechUsers.add(provider2); allMotechUsers.add(cmfAdmin); allMotechUsers.add(itAdmin); List<? extends MotechUser> providers = allMotechUsers.findByRole("PROVIDER"); assertEquals(asList("id1", "id2"), extract(providers, on(MotechUser.class).getExternalId())); }