use of org.broadinstitute.consent.http.models.sam.UserStatusInfo 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.sam.UserStatusInfo in project consent by DataBiosphere.
the class UserServiceTest method testFindUserWithPropertiesAsJsonObjectById.
@Test
public void testFindUserWithPropertiesAsJsonObjectById() {
User user = generateUser();
UserStatusInfo info = new UserStatusInfo().setUserEmail(user.getEmail()).setEnabled(true).setUserSubjectId("subjectId");
AuthUser authUser = new AuthUser().setEmail(user.getEmail()).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());
assertTrue(userJson.get(UserService.USER_STATUS_INFO_FIELD).getAsJsonObject().isJsonObject());
}
use of org.broadinstitute.consent.http.models.sam.UserStatusInfo in project consent by DataBiosphere.
the class SamServiceTest method testGetRegistrationInfo.
@Test
public void testGetRegistrationInfo() throws Exception {
UserStatusInfo userInfo = new UserStatusInfo().setAdminEnabled(RandomUtils.nextBoolean()).setUserEmail("test@test.org").setUserSubjectId(RandomStringUtils.random(10, false, true)).setEnabled(RandomUtils.nextBoolean());
mockServerClient.when(request()).respond(response().withHeader(Header.header("Content-Type", "application/json")).withStatusCode(200).withBody(userInfo.toString()));
UserStatusInfo authUserUserInfo = service.getRegistrationInfo(authUser);
assertNotNull(authUserUserInfo);
assertEquals(userInfo.getUserEmail(), authUserUserInfo.getUserEmail());
assertEquals(userInfo.getEnabled(), authUserUserInfo.getEnabled());
assertEquals(userInfo.getUserSubjectId(), authUserUserInfo.getUserSubjectId());
}
use of org.broadinstitute.consent.http.models.sam.UserStatusInfo in project consent by DataBiosphere.
the class SamResourceTest method testGetRegistrationInfo.
@Test
public void testGetRegistrationInfo() throws Exception {
UserStatusInfo userInfo = new UserStatusInfo().setAdminEnabled(RandomUtils.nextBoolean()).setUserEmail("test@test.org").setUserSubjectId(RandomStringUtils.random(10, false, true)).setEnabled(RandomUtils.nextBoolean());
when(service.getRegistrationInfo(any())).thenReturn(userInfo);
initResource();
Response response = resource.getRegistrationInfo(authUser);
assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
}
Aggregations