Fixed unpublishing events.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29696 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2011-08-11 16:52:06 +00:00
parent 340338d4d0
commit 4940091515

View File

@@ -82,8 +82,8 @@ import org.alfresco.repo.web.scripts.BaseWebScriptTest;
import org.alfresco.repo.web.scripts.WebScriptUtil; import org.alfresco.repo.web.scripts.WebScriptUtil;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.publishing.PublishingDetails;
import org.alfresco.service.cmr.publishing.NodeSnapshot; import org.alfresco.service.cmr.publishing.NodeSnapshot;
import org.alfresco.service.cmr.publishing.PublishingDetails;
import org.alfresco.service.cmr.publishing.PublishingEvent; import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingPackageEntry; import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
@@ -260,16 +260,36 @@ public class PublishingRestApiTest extends BaseWebScriptTest
assertEquals("Channel2 name should not have changed!", name2, renamedCH2.getName()); assertEquals("Channel2 name should not have changed!", name2, renamedCH2.getName());
} }
@SuppressWarnings("unchecked")
public void testPublishingQueuePost() throws Exception public void testPublishingQueuePost() throws Exception
{
// Create some content.
NodeRef textNode = testHelper.createContentNode("plainContent", "Some plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN);
try
{
checkPublishingQueuePost(textNode);
}
finally
{
// Clean up events
List<PublishingEvent> events = publishingService.getEventsForPublishedNode(textNode);
List<String> ids = CollectionUtils.transform(events, new Function<PublishingEvent, String>()
{
public String apply(PublishingEvent value)
{
return value.getId();
}
});
testHelper.addEvents(ids);
}
}
@SuppressWarnings("unchecked")
private void checkPublishingQueuePost(NodeRef textNode) throws Exception
{ {
// Create publish and status update channels. // Create publish and status update channels.
Channel publishChannel = testHelper.createChannel(publishAnyType); Channel publishChannel = testHelper.createChannel(publishAnyType);
Channel statusChannel = testHelper.createChannel(statusUpdateType); Channel statusChannel = testHelper.createChannel(statusUpdateType);
// Create some content.
NodeRef textNode = testHelper.createContentNode("plainContent", "Some plain text", MimetypeMap.MIMETYPE_TEXT_PLAIN);
// Post empty content. // Post empty content.
sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, "", JSON), 400); sendRequest(new PostRequest(PUBLISHING_QUEUE_URL, "", JSON), 400);
@@ -370,17 +390,22 @@ public class PublishingRestApiTest extends BaseWebScriptTest
// Check unpublish was called // Check unpublish was called
verify(publishAnyChannelType) verify(publishAnyChannelType)
.unpublish(eq(mappedTextNode), anyMap()); .unpublish(eq(mappedTextNode), anyMap());
// Check can get unpublish event.
String protocol = textNode.getStoreRef().getProtocol();
String storeId = textNode.getStoreRef().getIdentifier();
String nodeId = textNode.getId();
String textNodeUrl = MessageFormat.format(PUBLISHING_EVENTS_URL, protocol, storeId, nodeId);
// Clean up events // Get events on textNode1 before any events created.
List<PublishingEvent> events= publishingService.getEventsForPublishedNode(textNode); Response response = sendRequest(new GetRequest(textNodeUrl), 200);
List<String> ids = CollectionUtils.transform(events, new Function<PublishingEvent, String>() JSONArray data = getDataArray(response);
{
public String apply(PublishingEvent value) List<PublishingEvent> unpublishEvents = publishingService.getEventsForUnpublishedNode(textNode);
{ assertEquals(1, unpublishEvents.size());
return value.getId(); PublishingEvent unpublishedEvent = unpublishEvents.get(0);
}
}); checkContainsEvent(data, unpublishedEvent.getId());
testHelper.addEvents(ids);
} }
public void testPublishingEventsGet() throws Exception public void testPublishingEventsGet() throws Exception
@@ -431,6 +456,7 @@ public class PublishingRestApiTest extends BaseWebScriptTest
response = sendRequest(new GetRequest(textNode2Url), 200); response = sendRequest(new GetRequest(textNode2Url), 200);
data = getDataArray(response); data = getDataArray(response);
assertEquals(0, data.length()); assertEquals(0, data.length());
} }
public void testChannelTypesGet() throws Exception public void testChannelTypesGet() throws Exception
@@ -575,9 +601,6 @@ public class PublishingRestApiTest extends BaseWebScriptTest
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put(CHANNEL_ID, publishChannel.getId()); json.put(CHANNEL_ID, publishChannel.getId());
json.put(COMMENT, comment); json.put(COMMENT, comment);
// Calendar schedule = Calendar.getInstance();
// schedule.add(Calendar.SECOND, 1);
// json.put(SCHEDULED_TIME, WebScriptUtil.buildCalendarModel(schedule));
Collection<String> publishNodes = Collections.singleton(node.toString()); Collection<String> publishNodes = Collections.singleton(node.toString());
if(publish) if(publish)
{ {