Search in sources :

Example 1 with Person

use of uk.nhs.digital.intranet.model.Person in project hippo by NHS-digital-website.

the class SearchPageComponentTest method peopleQueryReturnsResultsAndPopulatesTabs.

@Test
public void peopleQueryReturnsResultsAndPopulatesTabs() throws ProviderCommunicationException {
    MockHstRequest request = new MockHstRequest();
    request.setParameterMap("", Collections.emptyMap());
    request.addParameter(REQUEST_ATTR_QUERY, "query string here");
    mockHstRequestContext.setAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME, "logged-into-microsoft-access-token");
    request.addParameter(REQUEST_ATTR_AREA, "people");
    int newsResults = 13;
    int tasksResults = 5;
    int teamsResults = 2;
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(anyString(), eq(SearchArea.NEWS))).thenReturn(newsResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(anyString(), eq(SearchArea.TASKS))).thenReturn(tasksResults);
    Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(anyString(), eq(SearchArea.TEAMS))).thenReturn(teamsResults);
    List<Person> expectedPeopleResults = Collections.singletonList(new Person("1", "bob", "finance"));
    Mockito.when(graphProvider.getPeople(anyString())).thenReturn(expectedPeopleResults);
    underTest.doBeforeRender(request, new MockHstResponse());
    assertEquals(expectedPeopleResults, request.getAttribute(REQUEST_ATTR_PEOPLE_RESULTS));
    Mockito.verify(bloomreachSearchProvider, Mockito.never()).getBloomreachResults(anyString(), anyInt(), anyInt(), any());
    List<SearchResultTab> tabs = (List<SearchResultTab>) request.getAttribute(REQUEST_ATTR_SEARCH_TABS);
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.NEWS, newsResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.TASKS, tasksResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.TEAMS, teamsResults)));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.PEOPLE, expectedPeopleResults.size())));
    assertTrue(tabs.contains(new SearchResultTab(SearchArea.ALL, newsResults + tasksResults + teamsResults + expectedPeopleResults.size())));
}
Also used : MockHstRequest(org.hippoecm.hst.mock.core.component.MockHstRequest) MockHstResponse(org.hippoecm.hst.mock.core.component.MockHstResponse) SearchResultTab(uk.nhs.digital.intranet.model.SearchResultTab) ArrayList(java.util.ArrayList) List(java.util.List) Person(uk.nhs.digital.intranet.model.Person) Test(org.junit.Test)

Example 2 with Person

use of uk.nhs.digital.intranet.model.Person in project hippo by NHS-digital-website.

the class PersonFactoryTest method createsPersonListFromUserList.

@Test
public void createsPersonListFromUserList() {
    final User user1 = getUser("user1", null);
    final User user2 = getUser("user2", null);
    final User user3 = getUser("user3", null);
    final List<User> users = Arrays.asList(user1, user2, user3);
    final List<Person> persons = personFactory.createPersons(users);
    assertEquals(3, persons.size());
    IntStream.range(0, 3).forEach(index -> {
        assertEquals(users.get(index).getDisplayName(), persons.get(index).getDisplayName());
        assertEquals(users.get(index).getDepartment(), persons.get(index).getDepartment());
        assertEquals(users.get(index).getId(), persons.get(index).getId());
        assertNull(persons.get(index).getBusinessPhones());
        assertNull(persons.get(index).getEmail());
        assertNull(persons.get(index).getPhoneNumber());
        assertNull(persons.get(index).getJobRole());
        assertNull(persons.get(index).getOfficeLocation());
        assertNull(persons.get(index).getPhoto());
    });
}
Also used : User(uk.nhs.digital.intranet.json.User) Person(uk.nhs.digital.intranet.model.Person) Test(org.junit.Test)

Example 3 with Person

use of uk.nhs.digital.intranet.model.Person in project hippo by NHS-digital-website.

the class PersonFactoryTest method createsPersonFromUserAndPhotoUsingUserPrincipalNameAsMail.

@Test
public void createsPersonFromUserAndPhotoUsingUserPrincipalNameAsMail() {
    final String userName = "user1";
    final User user = getUser(userName, null);
    final Person person = personFactory.createPerson(user, PHOTO);
    assertEquals(user.getDisplayName(), person.getDisplayName());
    assertEquals(user.getBusinessPhones(), person.getBusinessPhones());
    assertEquals(user.getDepartment(), person.getDepartment());
    assertEquals(user.getJobTitle(), person.getJobRole());
    assertEquals(user.getUserPrincipalName(), person.getEmail());
    assertEquals(user.getMobilePhone(), person.getPhoneNumber());
    assertEquals(user.getId(), person.getId());
    assertEquals(PHOTO, person.getPhoto());
}
Also used : User(uk.nhs.digital.intranet.json.User) Person(uk.nhs.digital.intranet.model.Person) Test(org.junit.Test)

Example 4 with Person

use of uk.nhs.digital.intranet.model.Person in project hippo by NHS-digital-website.

the class PersonFactoryTest method createsPersonFromUserAndPhoto.

@Test
public void createsPersonFromUserAndPhoto() {
    final String userName = "user1";
    final User user = getUser(userName, String.format(MAIL_FORMAT, userName));
    final Person person = personFactory.createPerson(user, PHOTO);
    assertEquals(user.getDisplayName(), person.getDisplayName());
    assertEquals(user.getBusinessPhones(), person.getBusinessPhones());
    assertEquals(user.getDepartment(), person.getDepartment());
    assertEquals(user.getJobTitle(), person.getJobRole());
    assertEquals(user.getMail(), person.getEmail());
    assertEquals(user.getMobilePhone(), person.getPhoneNumber());
    assertEquals(user.getId(), person.getId());
    assertEquals(PHOTO, person.getPhoto());
}
Also used : User(uk.nhs.digital.intranet.json.User) Person(uk.nhs.digital.intranet.model.Person) Test(org.junit.Test)

Example 5 with Person

use of uk.nhs.digital.intranet.model.Person in project hippo by NHS-digital-website.

the class PersonComponent method doBeforeRender.

@Override
public void doBeforeRender(HstRequest request, HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);
    final String accessToken = (String) RequestContextProvider.get().getAttribute(Constants.ACCESS_TOKEN_PROPERTY_NAME);
    if (!StringUtils.hasText(accessToken)) {
        request.setAttribute("accessTokenRequired", true);
        return;
    }
    final String id = getComponentParameter("id");
    try {
        final Person person = graphProvider.getPerson(id);
        request.setAttribute("person", person);
    } catch (final ProviderCommunicationException e) {
        request.setAttribute("errorMessage", PROVIDER_COMMUNICATION_ERROR_MESSAGE);
    }
}
Also used : ProviderCommunicationException(uk.nhs.digital.intranet.model.exception.ProviderCommunicationException) Person(uk.nhs.digital.intranet.model.Person)

Aggregations

Person (uk.nhs.digital.intranet.model.Person)5 Test (org.junit.Test)4 User (uk.nhs.digital.intranet.json.User)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MockHstRequest (org.hippoecm.hst.mock.core.component.MockHstRequest)1 MockHstResponse (org.hippoecm.hst.mock.core.component.MockHstResponse)1 SearchResultTab (uk.nhs.digital.intranet.model.SearchResultTab)1 ProviderCommunicationException (uk.nhs.digital.intranet.model.exception.ProviderCommunicationException)1