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);
}
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));
}
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());
}
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());
}
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());
}
Aggregations