Search in sources :

Example 66 with Institution

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());
    }
}
Also used : PSQLException(org.postgresql.util.PSQLException) Institution(org.broadinstitute.consent.http.models.Institution) PSQLException(org.postgresql.util.PSQLException) Test(org.junit.Test)

Example 67 with Institution

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());
}
Also used : User(org.broadinstitute.consent.http.models.User) Institution(org.broadinstitute.consent.http.models.Institution) Test(org.junit.Test)

Example 68 with Institution

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());
}
Also used : DataSet(org.broadinstitute.consent.http.models.DataSet) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserProperty(org.broadinstitute.consent.http.models.UserProperty) Collection(java.util.Collection) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) UserFields(org.broadinstitute.consent.http.enumeration.UserFields) User(org.broadinstitute.consent.http.models.User) Test(org.junit.Test) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) Dac(org.broadinstitute.consent.http.models.Dac) ArrayList(java.util.ArrayList) LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Institution(org.broadinstitute.consent.http.models.Institution) Election(org.broadinstitute.consent.http.models.Election) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Consent(org.broadinstitute.consent.http.models.Consent) User(org.broadinstitute.consent.http.models.User) Test(org.junit.Test)

Example 69 with Institution

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());
}
Also used : LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) User(org.broadinstitute.consent.http.models.User) Institution(org.broadinstitute.consent.http.models.Institution) Test(org.junit.Test)

Example 70 with Institution

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());
}
Also used : User(org.broadinstitute.consent.http.models.User) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Institution(org.broadinstitute.consent.http.models.Institution) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Aggregations

Institution (org.broadinstitute.consent.http.models.Institution)70 Test (org.junit.Test)50 User (org.broadinstitute.consent.http.models.User)32 LibraryCard (org.broadinstitute.consent.http.models.LibraryCard)16 Gson (com.google.gson.Gson)13 Response (javax.ws.rs.core.Response)11 AuthUser (org.broadinstitute.consent.http.models.AuthUser)9 Date (java.util.Date)7 NotFoundException (javax.ws.rs.NotFoundException)7 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Produces (javax.ws.rs.Produces)4 MappingException (org.jdbi.v3.core.mapper.MappingException)4 DarCollection (org.broadinstitute.consent.http.models.DarCollection)3 Election (org.broadinstitute.consent.http.models.Election)3 UserProperty (org.broadinstitute.consent.http.models.UserProperty)3 UserRole (org.broadinstitute.consent.http.models.UserRole)3 File (java.io.File)2 IOException (java.io.IOException)2 PermitAll (javax.annotation.security.PermitAll)2