Search in sources :

Example 1 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class ResearcherServiceTest method setUp.

@Before
public void setUp() {
    GoogleUser googleUser = new GoogleUser();
    googleUser.setName("Test User");
    googleUser.setEmail("test@gmail.com");
    authUser = new AuthUser(googleUser);
    user = new User();
    user.setEmail(authUser.getEmail());
    user.setDacUserId(RandomUtils.nextInt(1, 10));
    user.setDisplayName(RandomStringUtils.random(10));
    MockitoAnnotations.initMocks(this);
}
Also used : GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Before(org.junit.Before)

Example 2 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class UserServiceTest method testFindUserWithPropertiesAsJsonObjectByIdNonAuthUser.

@Test
public void testFindUserWithPropertiesAsJsonObjectByIdNonAuthUser() {
    User user = generateUser();
    UserStatusInfo info = new UserStatusInfo().setUserEmail(user.getEmail()).setEnabled(true).setUserSubjectId("subjectId");
    AuthUser authUser = new AuthUser().setEmail("not the user's email address").setAuthToken(RandomStringUtils.random(30, true, false)).setUserStatusInfo(info);
    when(userDAO.findUserById(anyInt())).thenReturn(user);
    when(libraryCardDAO.findLibraryCardsByUserId(anyInt())).thenReturn(List.of(new LibraryCard()));
    when(userPropertyDAO.findResearcherPropertiesByUser(anyInt())).thenReturn(List.of(new UserProperty()));
    initService();
    JsonObject userJson = service.findUserWithPropertiesByIdAsJsonObject(authUser, user.getDacUserId());
    assertNotNull(userJson);
    assertTrue(userJson.get(UserService.LIBRARY_CARDS_FIELD).getAsJsonArray().isJsonArray());
    assertTrue(userJson.get(UserService.RESEARCHER_PROPERTIES_FIELD).getAsJsonArray().isJsonArray());
    assertNull(userJson.get(UserService.USER_STATUS_INFO_FIELD));
}
Also used : LibraryCard(org.broadinstitute.consent.http.models.LibraryCard) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) SimplifiedUser(org.broadinstitute.consent.http.service.UserService.SimplifiedUser) UserProperty(org.broadinstitute.consent.http.models.UserProperty) UserStatusInfo(org.broadinstitute.consent.http.models.sam.UserStatusInfo) JsonObject(com.google.gson.JsonObject) AuthUser(org.broadinstitute.consent.http.models.AuthUser) Test(org.junit.Test)

Example 3 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class DacResourceTest method testRemoveDacChairAsAdmin.

@Test
public void testRemoveDacChairAsAdmin() {
    Dac dac = buildDac(null);
    when(dacService.findById(any())).thenReturn(dac);
    User admin = buildAdmin(authUser);
    User member = buildUser();
    when(userService.findUserByEmail(authUser.getEmail())).thenReturn(admin);
    when(dacService.findUserById(member.getDacUserId())).thenReturn(member);
    Response response = dacResource.removeDacChair(authUser, dac.getDacId(), member.getDacUserId());
    assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) Test(org.junit.Test)

Example 4 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class DarCollectionResourceTest method testResubmitDarCollection_CollectionNotCanceled.

@Test
public void testResubmitDarCollection_CollectionNotCanceled() {
    int userId = 1;
    User user = mock(User.class);
    when(userService.findUserByEmail(anyString())).thenReturn(user);
    when(user.getDacUserId()).thenReturn(userId);
    DarCollection collection = mock(DarCollection.class);
    when(collection.getCreateUserId()).thenReturn(userId);
    DataAccessRequest dar = mock(DataAccessRequest.class);
    DataAccessRequestData data = mock(DataAccessRequestData.class);
    String referenceId = UUID.randomUUID().toString();
    when(data.getStatus()).thenReturn("Not Canceled");
    when(dar.getData()).thenReturn(data);
    when(dar.getReferenceId()).thenReturn(referenceId);
    Map<String, DataAccessRequest> darMap = Map.of(dar.getReferenceId(), dar);
    when(collection.getDars()).thenReturn(darMap);
    when(darCollectionService.getByCollectionId(any())).thenReturn(collection);
    initResource();
    Response response = resource.resubmitDarCollection(authUser, 1);
    assertEquals(HttpStatusCodes.STATUS_CODE_BAD_REQUEST, response.getStatus());
}
Also used : DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 5 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class DarCollectionResourceTest method testGetCollectionByIdDacMemberNoDatasetIdMatch.

@Test
public void testGetCollectionByIdDacMemberNoDatasetIdMatch() {
    List<UserRole> chairRole = List.of(new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName()));
    User chair = new User(3, authUser.getEmail(), "Display Name", new Date(), chairRole, authUser.getEmail());
    DarCollection collection = mockDarCollection();
    collection.setCreateUser(researcher);
    collection.setCreateUserId(researcher.getDacUserId());
    DataSet dataSet = new DataSet();
    dataSet.setDataSetId(3);
    collection.addDataset(dataSet);
    when(darCollectionService.getByCollectionId(any())).thenReturn(collection);
    when(userService.findUserByEmail(anyString())).thenReturn(chair);
    when(darCollectionService.findDatasetIdsByUser(any())).thenReturn(Arrays.asList(1, 2));
    initResource();
    Response response = resource.getCollectionById(authUser, collection.getDarCollectionId());
    assertEquals(HttpStatusCodes.STATUS_CODE_NOT_FOUND, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) UserRole(org.broadinstitute.consent.http.models.UserRole) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Aggregations

AuthUser (org.broadinstitute.consent.http.models.AuthUser)187 User (org.broadinstitute.consent.http.models.User)172 Test (org.junit.Test)106 Response (javax.ws.rs.core.Response)96 NotFoundException (javax.ws.rs.NotFoundException)53 Produces (javax.ws.rs.Produces)50 Path (javax.ws.rs.Path)44 RolesAllowed (javax.annotation.security.RolesAllowed)42 GoogleUser (org.broadinstitute.consent.http.authentication.GoogleUser)39 UserRole (org.broadinstitute.consent.http.models.UserRole)36 BadRequestException (javax.ws.rs.BadRequestException)31 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)28 DarCollection (org.broadinstitute.consent.http.models.DarCollection)26 ForbiddenException (javax.ws.rs.ForbiddenException)25 Consumes (javax.ws.rs.Consumes)24 Gson (com.google.gson.Gson)22 GET (javax.ws.rs.GET)22 PaginationResponse (org.broadinstitute.consent.http.models.PaginationResponse)19 Vote (org.broadinstitute.consent.http.models.Vote)19 POST (javax.ws.rs.POST)18