use of org.hippoecm.hst.mock.core.component.MockHstResponse in project hippo by NHS-digital-website.
the class SearchPageComponentTest method blankQueryReturnsTabs.
@Test
public void blankQueryReturnsTabs() {
MockHstRequest request = new MockHstRequest();
request.setParameterMap("", Collections.emptyMap());
int newsResults = 9;
int tasksResults = 5;
int teamsResults = 2;
Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.NEWS)).thenReturn(newsResults);
Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.TASKS)).thenReturn(tasksResults);
Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.TEAMS)).thenReturn(teamsResults);
underTest.doBeforeRender(request, new MockHstResponse());
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, 0)));
assertTrue(tabs.contains(new SearchResultTab(SearchArea.ALL, newsResults + tasksResults + teamsResults)));
}
use of org.hippoecm.hst.mock.core.component.MockHstResponse in project hippo by NHS-digital-website.
the class SearchPageComponentTest method blankQueryReturnsDocumentsForAllDocTypes.
@Test
public void blankQueryReturnsDocumentsForAllDocTypes() {
MockHstRequest request = new MockHstRequest();
request.setParameterMap("", Collections.emptyMap());
Pageable<HippoBean> documentResults = new DefaultPagination<>(Collections.singletonList(new Task()));
Mockito.when(bloomreachSearchProvider.getBloomreachResults(Mockito.nullable(String.class), anyInt(), anyInt(), eq(SearchArea.ALL))).thenReturn(documentResults);
underTest.doBeforeRender(request, new MockHstResponse());
assertEquals(documentResults, request.getAttribute(REQUEST_ATTR_PAGEABLE));
}
use of org.hippoecm.hst.mock.core.component.MockHstResponse in project hippo by NHS-digital-website.
the class SearchPageComponentTest method newsQueryLimitsSearchAreaAndPopulatesTabs.
@Test
public void newsQueryLimitsSearchAreaAndPopulatesTabs() {
MockHstRequest request = new MockHstRequest();
request.setParameterMap("", Collections.emptyMap());
request.addParameter(REQUEST_ATTR_AREA, "news");
int newsResults = 53;
int tasksResults = 5;
int teamsResults = 2;
Pageable<HippoBean> documentResults = new DefaultPagination<>(Collections.singletonList(new Task()), newsResults);
Mockito.when(bloomreachSearchProvider.getBloomreachResults(Mockito.nullable(String.class), anyInt(), anyInt(), eq(SearchArea.NEWS))).thenReturn(documentResults);
Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.TASKS)).thenReturn(tasksResults);
Mockito.when(bloomreachSearchProvider.getBloomreachResultsCount(null, SearchArea.TEAMS)).thenReturn(teamsResults);
underTest.doBeforeRender(request, new MockHstResponse());
assertEquals(documentResults, request.getAttribute(REQUEST_ATTR_PAGEABLE));
Mockito.verify(bloomreachSearchProvider, Mockito.never()).getBloomreachResultsCount(Mockito.nullable(String.class), eq(SearchArea.NEWS));
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, 0)));
assertTrue(tabs.contains(new SearchResultTab(SearchArea.ALL, newsResults + tasksResults + teamsResults)));
}
use of org.hippoecm.hst.mock.core.component.MockHstResponse 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 org.hippoecm.hst.mock.core.component.MockHstResponse in project hippo by NHS-digital-website.
the class ApiCatalogueComponentTest method setUp.
@Before
public void setUp() throws Exception {
expectedMappingYaml = "valid: 'mapping YAML'";
given(apiCatalogueRepository.taxonomyFiltersMapping()).willReturn(Optional.ofNullable(expectedMappingYaml));
givenApiCatalogueContext();
givenApiCatalogueDocumentWithInternalLinksToCatalogueDocuments();
HstServices.setComponentManager(componentManager);
givenRequestWithApiCatalogueAsContentBean();
irrelevantResponse = new MockHstResponse();
apiCatalogueComponent = new ApiCatalogueComponent();
}
Aggregations