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