use of org.onehippo.repository.mock.MockNode in project hippo by NHS-digital-website.
the class JcrNodeUtilsTest method streamOf_returnsNodesFromNodeIteratorAsStream.
@Test
public void streamOf_returnsNodesFromNodeIteratorAsStream() {
// given
final MockNode nodeA = new MockNode("nodeA");
final MockNode nodeB = new MockNode("nodeB");
final MockNode nodeC = new MockNode("nodeC");
final NodeIterator nodeIterator = new MockNodeIterator(asList(nodeA, nodeB, nodeC));
// when
final Stream<Node> actualNodeStream = JcrNodeUtils.streamOf(nodeIterator);
// then
assertThat("Returned stream contains nodes from the iterator, exactly.", actualNodeStream.collect(toList()), containsInAnyOrder(nodeA, nodeB, nodeC));
}
use of org.onehippo.repository.mock.MockNode in project hippo by NHS-digital-website.
the class AttachmentFieldValidatorTest method createNodeConfiguration.
private Node createNodeConfiguration(boolean duplicateDisplayName) throws RepositoryException {
String displayName1 = "displayname1";
String displayName2 = "displayname2";
if (duplicateDisplayName) {
displayName1 = displayName2;
}
Node node = new MockNode("document", "doc");
node.addNode("attachment", HIPPO_ATTACHMENT_PRIMARY_NODE_TYPE).setProperty(HIPPO_FILENAME_PROPERTY_NAME, "duplicateFileName");
node.addNode("attachment2", HIPPO_ATTACHMENT_PRIMARY_NODE_TYPE).setProperty(HIPPO_FILENAME_PROPERTY_NAME, "duplicateFileName");
node.addNode("attachment/resource", DEFAULT_ATTACHMENT_NAME_WHEN_NO_FILE_UPLOADED).setProperty(HIPPO_FILENAME_PROPERTY_NAME, "another_filename");
node.getNode("attachment").setProperty(HIPPO_ATTACHMENT_DISPLAY_NAME_PROPERTY_NAME, displayName1);
node.getNode("attachment2").setProperty(HIPPO_ATTACHMENT_DISPLAY_NAME_PROPERTY_NAME, displayName2);
return node;
}
use of org.onehippo.repository.mock.MockNode in project hippo by NHS-digital-website.
the class AttachmentFieldValidatorTest method reportsValidationViloation_forBlankUploadField.
@Test
public void reportsValidationViloation_forBlankUploadField() throws Exception {
Node node = new MockNode("document", "doc");
node.addNode("attachment", HIPPO_ATTACHMENT_PRIMARY_NODE_TYPE);
node.addNode("attachment/resource", DEFAULT_ATTACHMENT_NAME_WHEN_NO_FILE_UPLOADED).setProperty(HIPPO_FILENAME_PROPERTY_NAME, DEFAULT_ATTACHMENT_NAME_WHEN_NO_FILE_UPLOADED);
given(validationContextMock.getDocumentNode()).willReturn(node);
given(validationContextMock.createViolation("blank-attachment")).willReturn(violationMock);
final Optional<Violation> violation = attachmentFieldValidator.validate(validationContextMock, nodeDecoratorMock);
assertThat("Violation has been reported, blank upload", violation.isPresent());
verify(validationContextMock).createViolation("blank-attachment");
}
use of org.onehippo.repository.mock.MockNode 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