PublishingEventHelper { public PublishingEvent getPublishingEvent(NodeRef eventNode) throws AlfrescoRuntimeException { if (eventNode == null) { return null; } Map<QName, Serializable> props = nodeService.getProperties(eventNode); String statusStr = (String) props.get(PROP_PUBLISHING_EVENT_STATUS); Status status = Status.valueOf(statusStr); String channel = (String) props.get(PROP_PUBLISHING_EVENT_CHANNEL); Date createdTime = (Date) props.get(ContentModel.PROP_CREATED); String creator = (String) props.get(ContentModel.PROP_CREATOR); Date modifiedTime = (Date) props.get(ContentModel.PROP_MODIFIED); String modifier = (String) props.get(ContentModel.PROP_MODIFIER); String comment = (String) props.get(PROP_PUBLISHING_EVENT_COMMENT); Calendar scheduledTime = getScheduledTime(props); PublishingPackage publishingPackage = getPublishingPackage(eventNode, channel); StatusUpdate statusUpdate = buildStatusUpdate(props); return new PublishingEventImpl(eventNode.toString(), status, channel, publishingPackage, createdTime, creator,modifiedTime, modifier, scheduledTime, comment, statusUpdate); }  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; }
@Test public void testGetPublishingEvent() throws Exception { ContentReader reader = mock(ContentReader.class); InputStream inputStream = mock(InputStream.class); when(reader.getContentInputStream()).thenReturn(inputStream); when(contentService.getReader(any(NodeRef.class), any(QName.class))) .thenReturn(reader); NodeSnapshotSerializer serializer = mock(NodeSnapshotSerializer.class); helper.setSerializer(serializer); PublishingEvent result = helper.getPublishingEvent((NodeRef)null); assertNull(result); String comment = "The comment"; Status status = Status.COMPLETED; Date modified= new Date(); Date created = new Date(modified.getTime()-3600000); String creatorName = "The creator"; String modifierName = "The modifier"; Calendar schedule = Calendar.getInstance(); schedule.add(Calendar.MONTH, 6); Date scheduledTime = schedule.getTime(); String scheduledTimeZone = schedule.getTimeZone().getID(); Map<QName, Serializable> props = new HashMap<QName, Serializable>(); props.put(PROP_PUBLISHING_EVENT_COMMENT, comment); props.put(PROP_PUBLISHING_EVENT_STATUS, status.name()); props.put(PROP_PUBLISHING_EVENT_TIME, scheduledTime); props.put(PROP_PUBLISHING_EVENT_TIME_ZONE, scheduledTimeZone); props.put(ContentModel.PROP_CREATED, created); props.put(ContentModel.PROP_CREATOR, creatorName); props.put(ContentModel.PROP_MODIFIED, modified); props.put(ContentModel.PROP_MODIFIER, modifierName); NodeRef eventNode = new NodeRef("foo: when(nodeService.getProperties(eventNode)).thenReturn(props); result = helper.getPublishingEvent(eventNode); assertEquals(eventNode.toString(), result.getId()); assertEquals(comment, result.getComment()); assertEquals(status, result.getStatus()); assertEquals(schedule, result.getScheduledTime()); assertEquals(created, result.getCreatedTime()); assertEquals(creatorName, result.getCreator()); assertEquals(modified, result.getModifiedTime()); assertEquals(modifierName, result.getModifier()); }