ALF-5060: Google Docs - Transformation failure

- Fixed up working. but slightly incorrect download URL (was downloading as HTML instead of Word format hence the transformation was broken)
- Added download root URL to configuration
- Unit test to show bug fixed



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22847 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2010-10-04 12:09:57 +00:00
parent 8ed8d3b459
commit 04629bbf04
4 changed files with 205 additions and 91 deletions

View File

@@ -31,11 +31,16 @@ import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine;
import org.alfresco.repo.rendition.executer.ReformatRenderingEngine;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteServiceImpl;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.rendition.RenditionDefinition;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
@@ -46,10 +51,13 @@ import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
import org.apache.axis.wsdl.toJava.NamespaceSelector;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
@@ -75,6 +83,7 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
private MutableAuthenticationService authenticationService;
private PersonService personService;
private ApplicationContextFactory subsystem;
private RenditionService renditionService;
private static final String USER_ONE = "GoogleDocUserOne";
private static final String USER_TWO = "GoogleDocUserTwo";
@@ -84,13 +93,14 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
private static final String USER_SIX = "GoogleDocUserSix";
private static final String USER_SEVEN = "GoogleDocUserSeven";
private NodeRef folder = null;
private NodeRef nodeRefDoc = null;
private NodeRef nodeRefSpread = null;
private NodeRef nodeRefPres = null;
private NodeRef nodeRefPdf = null;
private NodeRef nodeRef2 = null;
private UserTransaction userTransaction = null;
private NodeRef folder;
private NodeRef nodeRefDoc;
private NodeRef nodeRefSpread;
private NodeRef nodeRefPres;
private NodeRef nodeRefPdf;
private NodeRef nodeRef2;
private UserTransaction userTransaction;
private String siteId;
@Override
protected void setUp() throws Exception
@@ -105,6 +115,7 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
checkOutCheckInService = (CheckOutCheckInService)appContext.getBean("checkOutCheckInService");
authenticationService = (MutableAuthenticationService)appContext.getBean("authenticationService");
personService = (PersonService)appContext.getBean("personService");
renditionService = (RenditionService)appContext.getBean("renditionService");
// Start the user transaction
userTransaction = transactionService.getUserTransaction();
@@ -135,22 +146,22 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
// Authenticate as user one
AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
String id = GUID.generate();
siteId = GUID.generate();
// Create a site to use as holder for our test google documents
siteService.createSite("sitePreset", id, "My Title", "My Description", SiteVisibility.PUBLIC);
NodeRef container = siteService.createContainer(id, "testComponent", null, null);
siteService.createSite("sitePreset", siteId, "My Title", "My Description", SiteVisibility.PUBLIC);
NodeRef container = siteService.createContainer(siteId, "testComponent", null, null);
// Add some memberships to the site
siteService.setMembership(id, USER_TWO, SiteServiceImpl.SITE_COLLABORATOR);
siteService.setMembership(id, USER_THREE, SiteServiceImpl.SITE_CONTRIBUTOR);
siteService.setMembership(id, USER_FOUR, SiteServiceImpl.SITE_CONSUMER);
siteService.setMembership(id, USER_FIVE, SiteServiceImpl.SITE_COLLABORATOR);
siteService.setMembership(id, USER_SIX, SiteServiceImpl.SITE_COLLABORATOR);
siteService.setMembership(id, USER_SEVEN, SiteServiceImpl.SITE_COLLABORATOR);
siteService.setMembership(siteId, USER_TWO, SiteServiceImpl.SITE_COLLABORATOR);
siteService.setMembership(siteId, USER_THREE, SiteServiceImpl.SITE_CONTRIBUTOR);
siteService.setMembership(siteId, USER_FOUR, SiteServiceImpl.SITE_CONSUMER);
siteService.setMembership(siteId, USER_FIVE, SiteServiceImpl.SITE_COLLABORATOR);
siteService.setMembership(siteId, USER_SIX, SiteServiceImpl.SITE_COLLABORATOR);
siteService.setMembership(siteId, USER_SEVEN, SiteServiceImpl.SITE_COLLABORATOR);
// Create a folder in our site container
folder = fileFolderService.create(container, "myfolder", ContentModel.TYPE_FOLDER).getNodeRef();
folder = fileFolderService.create(container, "myfolder" + GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
// Create test documents
nodeRefDoc = createTestDocument("mydoc.docx", "alfresco/subsystems/googledocs/default/test.docx", MimetypeMap.MIMETYPE_WORD);
@@ -206,9 +217,11 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
@Override
protected void tearDown() throws Exception
{
siteService.deleteSite(siteId);
if (userTransaction != null)
{
userTransaction.rollback();
userTransaction.commit();
}
}
@@ -289,6 +302,46 @@ public class GoogleDocumentServiceSystemTest extends TestCase implements GoogleD
}
}
/**
* http://issues.alfresco.com/jira/browse/ALF-5060
*/
public void testALF5060() throws Exception
{
if (isGoogleServiceAvailable() == true)
{
// Create a rendition definition (doc -> pdf)
RenditionDefinition def = renditionService.createRenditionDefinition(
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "myDef"),
ReformatRenderingEngine.NAME);
def.setExecuteAsynchronously(false);
def.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_FLASH);
// Create a word document
File fileDoc = AbstractContentTransformerTest.loadQuickTestFile("doc");
NodeRef nodeRef = fileFolderService.create(folder, "testing.doc", ContentModel.TYPE_CONTENT).getNodeRef();
nodeService.addAspect(nodeRef, ASPECT_GOOGLEEDITABLE, null);
ContentWriter contentWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setEncoding("UTF-8");
contentWriter.setMimetype(MimetypeMap.MIMETYPE_WORD);
contentWriter.putContent(fileDoc);
renditionService.render(nodeRef, def);
NodeRef workingCopy = checkOutCheckInService.checkout(nodeRef);
assertTrue(nodeService.hasAspect(workingCopy, ASPECT_GOOGLERESOURCE));
assertNotNull(nodeService.getProperty(workingCopy, PROP_URL));
assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_ID));
assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE));
System.out.println("Google doc URL: " + nodeService.getProperty(workingCopy, PROP_URL));
System.out.println("Google doc type: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE));
System.out.println("Google doc id: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_ID));
checkOutCheckInService.checkin(workingCopy, null);
renditionService.render(nodeRef, def);
}
}
/**
* Utility method to download input stream to a file for inspection
*