use of org.broadinstitute.consent.http.models.Institution in project consent by DataBiosphere.
the class InstitutionDAOTest method testInsertInstitutionDuplicateName.
@Test
public void testInsertInstitutionDuplicateName() {
Institution institution = createInstitution();
Integer userId = institution.getCreateUserId();
try {
institutionDAO.insertInstitution(institution.getName(), institution.getItDirectorName(), institution.getItDirectorEmail(), userId, institution.getCreateDate());
Assert.fail("CREATE should fail due to UNIQUE constraint violation (name)");
// JBDI wraps ALL SQL exceptions under the generic class UnableToExecuteStatementException
// Test is specifically looking for UNIQUE constraint violations, so I need to catch and unwrap the error to confirm
} catch (Exception e) {
assertEquals("23505", ((PSQLException) e.getCause()).getSQLState());
}
}
use of org.broadinstitute.consent.http.models.Institution in project consent by DataBiosphere.
the class UserDAOTest method testUpdateDACUser_case1.
@Test
public void testUpdateDACUser_case1() {
User user = createUser();
Institution firstInstitute = createInstitution();
String newEmail = getRandomEmailAddress();
userDAO.updateUser("Dac User Test", user.getDacUserId(), newEmail, firstInstitute.getId());
User user2 = userDAO.findUserById(user.getDacUserId());
assertEquals(user2.getAdditionalEmail(), newEmail);
assertEquals(user2.getInstitution().getId(), firstInstitute.getId());
}
use of org.broadinstitute.consent.http.models.Institution in project consent by DataBiosphere.
the class UserDAOTest method testFindDACUserById.
@Test
public void testFindDACUserById() {
User user = createUserWithRole(UserRoles.ALUMNI.getRoleId());
assertNotNull(user);
assertFalse(user.getRoles().isEmpty());
addUserRole(UserRoles.ADMIN.getRoleId(), user.getDacUserId());
addUserRole(UserRoles.RESEARCHER.getRoleId(), user.getDacUserId());
addUserRole(UserRoles.DATAOWNER.getRoleId(), user.getDacUserId());
User user2 = userDAO.findUserById(user.getDacUserId());
assertNotNull(user2);
assertEquals(user.getEmail(), user2.getEmail());
// Assert roles are fetched correctly
assertTrue(user2.getRoles().stream().anyMatch(r -> r.getRoleId().equals(UserRoles.ALUMNI.getRoleId())));
assertTrue(user2.getRoles().stream().anyMatch(r -> r.getRoleId().equals(UserRoles.ADMIN.getRoleId())));
assertTrue(user2.getRoles().stream().anyMatch(r -> r.getRoleId().equals(UserRoles.RESEARCHER.getRoleId())));
assertTrue(user2.getRoles().stream().anyMatch(r -> r.getRoleId().equals(UserRoles.DATAOWNER.getRoleId())));
// assert institution base data is present if available
User user3 = createUserWithInstitution();
User queriedUser3 = userDAO.findUserById(user3.getDacUserId());
assert (queriedUser3.getDacUserId()).equals(user3.getDacUserId());
assertNotNull(queriedUser3.getInstitutionId());
assert (queriedUser3.getInstitution().getId()).equals(user3.getInstitution().getId());
}
use of org.broadinstitute.consent.http.models.Institution in project consent by DataBiosphere.
the class UserDAOTest method testGetCardsForUnregisteredUsers.
@Test
public void testGetCardsForUnregisteredUsers() {
Institution institution = createInstitution();
LibraryCard card = createLCForUnregisteredUser(institution.getId());
List<User> users = userDAO.getCardsForUnregisteredUsers(institution.getId());
assertEquals(1, users.size());
User user = users.get(0);
List<LibraryCard> cards = user.getLibraryCards();
LibraryCard userCard = cards.get(0);
assertEquals(card.getUserEmail(), user.getEmail());
assertEquals(1, cards.size());
assertEquals(card.getId(), userCard.getId());
assertEquals(null, card.getUserId());
}
use of org.broadinstitute.consent.http.models.Institution in project consent by DataBiosphere.
the class DarCollectionDAOTest method testGetFilteredListForResearcher_InstitutionTerm.
@Test
public void testGetFilteredListForResearcher_InstitutionTerm() {
DataAccessRequest dar = createDataAccessRequestV3();
User user = userDAO.findUserById(dar.getUserId());
Institution institution = institutionDAO.findInstitutionById(user.getInstitutionId());
String testTerm = generateTestTerm(institution.getName());
List<DarCollection> collections = darCollectionDAO.getFilteredListForResearcher("dar_code", "ASC", dar.getUserId(), testTerm);
assertEquals(1, collections.size());
DarCollection targetCollection = collections.get(0);
assertEquals(5, targetCollection.getDars().size());
DataAccessRequest targetDar = new ArrayList<>(targetCollection.getDars().values()).get(0);
assertEquals(targetCollection.getDarCode(), targetDar.getData().getDarCode());
}
Aggregations