Search in sources :

Example 1 with UserStatusInfo

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));
}
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 2 with UserStatusInfo

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

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

Example 4 with UserStatusInfo

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());
}
Also used : TosResponse(org.broadinstitute.consent.http.models.sam.TosResponse) Response(javax.ws.rs.core.Response) UserStatusInfo(org.broadinstitute.consent.http.models.sam.UserStatusInfo) Test(org.junit.Test)

Aggregations

UserStatusInfo (org.broadinstitute.consent.http.models.sam.UserStatusInfo)4 Test (org.junit.Test)4 JsonObject (com.google.gson.JsonObject)2 AuthUser (org.broadinstitute.consent.http.models.AuthUser)2 LibraryCard (org.broadinstitute.consent.http.models.LibraryCard)2 User (org.broadinstitute.consent.http.models.User)2 UserProperty (org.broadinstitute.consent.http.models.UserProperty)2 SimplifiedUser (org.broadinstitute.consent.http.service.UserService.SimplifiedUser)2 Response (javax.ws.rs.core.Response)1 TosResponse (org.broadinstitute.consent.http.models.sam.TosResponse)1