PublishingEventHelper { public NodeRef createNode(NodeRef queueNode, PublishingDetails details) throws Exception { checkChannelAccess(details.getPublishChannelId()); Set<String> statusChannelIds = details.getStatusUpdateChannels(); if (isEmpty(statusChannelIds) == false) for (String statusChannelId : statusChannelIds) { checkChannelAccess(statusChannelId); } String name = GUID.generate(); Map<QName, Serializable> props = buildPublishingEventProperties(details, name); ChildAssociationRef newAssoc = nodeService.createNode(queueNode, ASSOC_PUBLISHING_EVENT, QName.createQName(NAMESPACE, name), TYPE_PUBLISHING_EVENT, props); NodeRef eventNode = newAssoc.getChildRef(); serializePublishNodes(eventNode, details); return eventNode; }  void setNodeService(NodeService nodeService); void setContentService(ContentService contentService); void setTransferManifestNodeFactory(TransferManifestNodeFactory transferManifestNodeFactory); void setVersionService(VersionService versionService); void setWorkflowService(WorkflowService workflowService); void setWorkflowEngineId(String workflowEngineId); void setSerializer(NodeSnapshotSerializer serializer); void setPermissionService(PermissionService permissionService); PublishingEvent getPublishingEvent(NodeRef eventNode); List<PublishingEvent> getPublishingEvents(List<NodeRef> eventNodes); NodeRef createNode(NodeRef queueNode, PublishingDetails details); List<NodeRef> findPublishingEventNodes(final NodeRef queue, PublishingEventFilter filter); List<NodeRef> getEventNodesForPublishedNodes(final NodeRef queue, NodeRef... publishedNodes); List<NodeRef> getEventNodesForPublishedNodes(final NodeRef queue, Collection<NodeRef> publishedNodes); List<NodeRef> getEventNodesForUnpublishedNodes(final NodeRef queue, Collection<NodeRef> unpublishedNodes); List<NodeRef> getEventNodesForPublishedNode(final NodeRef queue, NodeRef publishedNode); List<NodeRef> getEventNodesForUnpublishedNode(final NodeRef queue, NodeRef unpublishedNode); List<PublishingEvent> findPublishingEvents(NodeRef queue, PublishingEventFilter filter); PublishingEvent getPublishingEvent(String id); NodeRef getPublishingEventNode(String id); String startPublishingWorkflow(NodeRef eventNode, Calendar scheduledTime); Calendar getScheduledTime(NodeRef eventNode); Calendar getScheduledTime(Map<QName, Serializable> eventProperties); NodeRef getLastPublishEvent(NodeRef source, NodeRef channelNode); void cancelEvent(String id); AssociationRef linkToLastEvent(NodeRef publishedNode, NodeRef eventNode); PublishingDetails createPublishingDetails(); static final String WORKFLOW_DEFINITION_NAME; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testCreateNode() throws Exception { when(permissionService.hasPermission(any(NodeRef.class), anyString())).thenReturn(AccessStatus.ALLOWED); ContentWriter writer = mock(ContentWriter.class); when(contentService.getWriter(any(NodeRef.class), eq(PROP_PUBLISHING_EVENT_PAYLOAD), eq(true))) .thenReturn(writer); OutputStream outputStream = mock(OutputStream.class); when(writer.getContentOutputStream()).thenReturn(outputStream); NodeSnapshotSerializer serializer = mock(NodeSnapshotSerializer.class); helper.setSerializer(serializer); NodeRef queue = new NodeRef("foo: NodeRef event = new NodeRef("foo: ChildAssociationRef childAssoc = new ChildAssociationRef(ASSOC_PUBLISHING_EVENT, queue, null, event); when(nodeService.createNode(any(NodeRef.class), any(QName.class), any(QName.class), any(QName.class), anyMap())) .thenReturn(childAssoc); String channelId = "test: Calendar schedule = Calendar.getInstance(); String comment = "The comment"; PublishingDetails details = new PublishingDetailsImpl() .setSchedule(schedule) .setPublishChannelId(channelId) .setComment(comment); NodeRef result = helper.createNode(queue, details); assertEquals(event, result); ArgumentCaptor<Map> argument = ArgumentCaptor.forClass(Map.class); verify(nodeService) .createNode(eq(queue), eq(ASSOC_PUBLISHING_EVENT), any(QName.class), eq(TYPE_PUBLISHING_EVENT), argument.capture()); Map<QName, Serializable> props = argument.getValue(); assertNotNull(props.get(ContentModel.PROP_NAME)); assertEquals(channelId, props.get(PROP_PUBLISHING_EVENT_CHANNEL)); assertEquals(comment, props.get(PROP_PUBLISHING_EVENT_COMMENT)); assertEquals(schedule.getTime(), props.get(PROP_PUBLISHING_EVENT_TIME)); assertEquals(schedule.getTimeZone().getID(), props.get(PROP_PUBLISHING_EVENT_TIME_ZONE)); }