use of org.onehippo.repository.mock.MockSession in project hippo by NHS-digital-website.
the class ApiCatalogueJcrRepositoryTest method taxonomyFiltersMapping_returnsConfigurationInYaml_whenAvailable.
@Test
public void taxonomyFiltersMapping_returnsConfigurationInYaml_whenAvailable() throws IOException, RepositoryException {
// given
final MockSession session = JcrTestUtilsHst.mockJcrRepo("/test-data/ApiCatalogueJcrRepositoryTest/filters-taxonomy-mapping.yaml", ImmutableMap.of("website:taxonomymapping", BaseDocument.class), "//*[" + "(@hippo:paths='cb7449f4-930c-4a51-9bfd-b0a562c8700e')" + " and (@hippo:availability='live')" + " and not(@jcr:primaryType='nt:frozenNode')" + " and (@hippostd:state = 'published')" + "]" + " order by @jcr:score descending ", "content/documents/administration/website/developer-hub/taxonomy-filters-mapping/taxonomy-filters-mapping[3]");
final ApiCatalogueJcrRepository apiCatalogueJcrRepository = new ApiCatalogueJcrRepository(session);
// when
final String actualTaxonomyFiltersMappingYaml = apiCatalogueJcrRepository.taxonomyFiltersMapping().orElse("nothing was returned");
// then
assertThat("Taxonomy Filters Mapping Yaml was returned.", actualTaxonomyFiltersMappingYaml, is("some: 'yaml'"));
}
use of org.onehippo.repository.mock.MockSession in project hippo by NHS-digital-website.
the class JcrTestUtilsHst method mockJcrRepo.
public static MockSession mockJcrRepo(final String repositoryYaml, final Map<String, Class<? extends HippoBean>> jcrPrimaryNodeTypeBeanPairs, final MockHstRequestContext hstRequestContext, final String expectedQuery, final String... expectedNodesAbsolutePaths) throws IOException, RepositoryException {
final NhsdMockQueryManager jcrQueryManager = new NhsdMockQueryManager();
final MockNode root = MockNode.root(jcrQueryManager);
MockNodeFactory.importYaml(repositoryYaml, root);
final HstQueryManagerImpl hstQueryManager = new HstQueryManagerImpl(null, new ObjectConverterImpl(Optional.ofNullable(jcrPrimaryNodeTypeBeanPairs).orElse(emptyMap()), new String[0]), DateTools.Resolution.MILLISECOND);
final List<Node> expectedNodes = Optional.ofNullable(expectedNodesAbsolutePaths).map(Arrays::stream).orElse(Stream.empty()).map(path -> wrapCheckedException(() -> root.getNode(path))).collect(toList());
jcrQueryManager.registerResultHandler(query -> {
if (query.getStatement().equals(expectedQuery)) {
return new MockQueryResult(expectedNodes);
}
return new MockQueryResult(emptyList());
});
final MockSession session = root.getSession();
ReflectionTestUtils.setField(hstQueryManager, "session", session);
final Mount mount = mock(Mount.class);
final ResolvedMount resolvedMount = mock(ResolvedMount.class);
given(resolvedMount.getMount()).willReturn(mount);
given(mount.isPreview()).willReturn(false);
MockHstRequestContext requestContext = hstRequestContext;
if (requestContext == null) {
requestContext = new MockHstRequestContext();
ModifiableRequestContextProvider.set(requestContext);
}
requestContext.setDefaultHstQueryManager(hstQueryManager);
requestContext.setResolvedMount(resolvedMount);
requestContext.setSession(session);
return session;
}
Aggregations