mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix up google doc tests
- Added service initialisation method to service so the "health" of the service can be determined - Unit tests do not fail if the google doc service has not been configured correctly git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20046 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,6 +1,21 @@
|
|||||||
/**
|
/*
|
||||||
*
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
*/
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package org.alfresco.repo.googledocs;
|
package org.alfresco.repo.googledocs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package org.alfresco.repo.googledocs;
|
package org.alfresco.repo.googledocs;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -9,6 +27,13 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
*/
|
*/
|
||||||
public interface GoogleDocsService
|
public interface GoogleDocsService
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Initialises the googles doc service, checking the provided credentials are correct. This need
|
||||||
|
* not be called manually since other service calls will initialise the service on demand, but it can
|
||||||
|
* be helpful to know the "health" of the service up front.
|
||||||
|
*/
|
||||||
|
void initialise() throws GoogleDocsServiceInitException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a google doc from a given node. The content of the node will be used
|
* Create a google doc from a given node. The content of the node will be used
|
||||||
* as a basis of the associated google doc. If the node has no content a new, empty google
|
* as a basis of the associated google doc. If the node has no content a new, empty google
|
||||||
|
@@ -208,7 +208,7 @@ public class GoogleDocsServiceImpl implements GoogleDocsService, GoogleDocsModel
|
|||||||
/**
|
/**
|
||||||
* Initialise google docs services
|
* Initialise google docs services
|
||||||
*/
|
*/
|
||||||
public void initialiseGoogleDocsService()
|
public void initialise() throws GoogleDocsServiceInitException
|
||||||
{
|
{
|
||||||
if (initialised == false)
|
if (initialised == false)
|
||||||
{
|
{
|
||||||
@@ -219,7 +219,7 @@ public class GoogleDocsServiceImpl implements GoogleDocsService, GoogleDocsModel
|
|||||||
|
|
||||||
if (username == null ||username.length() == 0 || password == null)
|
if (username == null ||username.length() == 0 || password == null)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("No Goolge Docs credentials found. Please set the Google Docs authentication configuration.");
|
throw new GoogleDocsServiceInitException("No Goolge Docs credentials found. Please set the Google Docs authentication configuration.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -230,7 +230,7 @@ public class GoogleDocsServiceImpl implements GoogleDocsService, GoogleDocsModel
|
|||||||
}
|
}
|
||||||
catch (AuthenticationException e)
|
catch (AuthenticationException e)
|
||||||
{
|
{
|
||||||
throw new AlfrescoRuntimeException("Unable to connect to Google Docs. Please check the Google Docs authentication configuration.", e);
|
throw new GoogleDocsServiceInitException("Unable to connect to Google Docs. Please check the Google Docs authentication configuration.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
initialised = true;
|
initialised = true;
|
||||||
@@ -250,7 +250,14 @@ public class GoogleDocsServiceImpl implements GoogleDocsService, GoogleDocsModel
|
|||||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||||
|
|
||||||
// Initialise google doc services
|
// Initialise google doc services
|
||||||
initialiseGoogleDocsService();
|
try
|
||||||
|
{
|
||||||
|
initialise();
|
||||||
|
}
|
||||||
|
catch (GoogleDocsServiceInitException e)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unable to create google doc, because service could not be initialised.", e);
|
||||||
|
}
|
||||||
|
|
||||||
// Get property values
|
// Get property values
|
||||||
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||||
@@ -295,7 +302,14 @@ public class GoogleDocsServiceImpl implements GoogleDocsService, GoogleDocsModel
|
|||||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||||
|
|
||||||
// Initialise google doc services
|
// Initialise google doc services
|
||||||
initialiseGoogleDocsService();
|
try
|
||||||
|
{
|
||||||
|
initialise();
|
||||||
|
}
|
||||||
|
catch (GoogleDocsServiceInitException e)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unable to create google doc, because service could not be initialised.", e);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -485,7 +499,14 @@ public class GoogleDocsServiceImpl implements GoogleDocsService, GoogleDocsModel
|
|||||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||||
|
|
||||||
// Initialise google doc services
|
// Initialise google doc services
|
||||||
initialiseGoogleDocsService();
|
try
|
||||||
|
{
|
||||||
|
initialise();
|
||||||
|
}
|
||||||
|
catch (GoogleDocsServiceInitException e)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("Unable to create google doc, because service could not be initialised.", e);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.googledocs;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Google docs service initialisation exception class.
|
||||||
|
*/
|
||||||
|
public class GoogleDocsServiceInitException extends Exception
|
||||||
|
{
|
||||||
|
/** Serial version UUID */
|
||||||
|
private static final long serialVersionUID = -2104024155137888545L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message error message
|
||||||
|
*/
|
||||||
|
public GoogleDocsServiceInitException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param message error message
|
||||||
|
* @param cause causing exception
|
||||||
|
*/
|
||||||
|
public GoogleDocsServiceInitException(String message, Throwable cause)
|
||||||
|
{
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cause causing exception
|
||||||
|
*/
|
||||||
|
public GoogleDocsServiceInitException(Throwable cause)
|
||||||
|
{
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
@@ -31,7 +31,6 @@ import junit.framework.TestCase;
|
|||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
||||||
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.site.SiteServiceImpl;
|
import org.alfresco.repo.site.SiteServiceImpl;
|
||||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||||
@@ -181,58 +180,78 @@ public class GoogleDocumentServiceTest extends TestCase implements GoogleDocsMod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isGoogleServiceAvailable()
|
||||||
|
{
|
||||||
|
boolean result = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
googleDocsService.initialise();
|
||||||
|
}
|
||||||
|
catch (GoogleDocsServiceInitException e)
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public void testGoogleDocUploadDownload() throws Exception
|
public void testGoogleDocUploadDownload() throws Exception
|
||||||
{
|
{
|
||||||
googleDocsService.createGoogleDoc(nodeRefDoc, GoogleDocsPermissionContext.SHARE_WRITE);
|
if (isGoogleServiceAvailable() == true)
|
||||||
|
{
|
||||||
|
googleDocsService.createGoogleDoc(nodeRefDoc, GoogleDocsPermissionContext.SHARE_WRITE);
|
||||||
|
|
||||||
assertTrue(nodeService.hasAspect(nodeRefDoc, ASPECT_GOOGLERESOURCE));
|
assertTrue(nodeService.hasAspect(nodeRefDoc, ASPECT_GOOGLERESOURCE));
|
||||||
assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_URL));
|
assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_URL));
|
||||||
assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_ID));
|
assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_ID));
|
||||||
assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_TYPE));
|
assertNotNull(nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_TYPE));
|
||||||
|
|
||||||
System.out.println("Google doc URL: " + nodeService.getProperty(nodeRefDoc, PROP_URL));
|
System.out.println("Google doc URL: " + nodeService.getProperty(nodeRefDoc, PROP_URL));
|
||||||
System.out.println("Google doc type: " + nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_TYPE));
|
System.out.println("Google doc type: " + nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_TYPE));
|
||||||
System.out.println("Google doc id: " + nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_ID));
|
System.out.println("Google doc id: " + nodeService.getProperty(nodeRefDoc, PROP_RESOURCE_ID));
|
||||||
String downloadFile = downloadFile(googleDocsService.getGoogleDocContent(nodeRefDoc), ".doc");
|
String downloadFile = downloadFile(googleDocsService.getGoogleDocContent(nodeRefDoc), ".doc");
|
||||||
System.out.println("Download file: " + downloadFile);
|
System.out.println("Download file: " + downloadFile);
|
||||||
|
|
||||||
// googleDocsService.upload(nodeRefSpread, GoogleDocsPermissionContext.SHARE_WRITE);
|
// googleDocsService.upload(nodeRefSpread, GoogleDocsPermissionContext.SHARE_WRITE);
|
||||||
//
|
//
|
||||||
// assertTrue(nodeService.hasAspect(nodeRefSpread, ASPECT_GOOGLERESOURCE));
|
// assertTrue(nodeService.hasAspect(nodeRefSpread, ASPECT_GOOGLERESOURCE));
|
||||||
// assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_URL));
|
// assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_URL));
|
||||||
// assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_ID));
|
// assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_ID));
|
||||||
// assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_TYPE));
|
// assertNotNull(nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_TYPE));
|
||||||
//
|
//
|
||||||
// System.out.println("Google doc URL: " + nodeService.getProperty(nodeRefSpread, PROP_URL));
|
// System.out.println("Google doc URL: " + nodeService.getProperty(nodeRefSpread, PROP_URL));
|
||||||
// System.out.println("Google doc type: " + nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_TYPE));
|
// System.out.println("Google doc type: " + nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_TYPE));
|
||||||
// System.out.println("Google doc id: " + nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_ID));
|
// System.out.println("Google doc id: " + nodeService.getProperty(nodeRefSpread, PROP_RESOURCE_ID));
|
||||||
// downloadFile = downloadFile(googleDocsService.download(nodeRefSpread), ".xls");
|
// downloadFile = downloadFile(googleDocsService.download(nodeRefSpread), ".xls");
|
||||||
// System.out.println("Download file: " + downloadFile);
|
// System.out.println("Download file: " + downloadFile);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCheckOutCheckIn() throws Exception
|
public void testCheckOutCheckIn() throws Exception
|
||||||
{
|
{
|
||||||
ContentReader contentReader = contentService.getReader(nodeRef2, ContentModel.PROP_CONTENT);
|
if (isGoogleServiceAvailable() == true)
|
||||||
assertNull(contentReader);
|
{
|
||||||
|
ContentReader contentReader = contentService.getReader(nodeRef2, ContentModel.PROP_CONTENT);
|
||||||
|
assertNull(contentReader);
|
||||||
|
|
||||||
// Check out the empty google document
|
// Check out the empty google document
|
||||||
NodeRef workingCopy = checkOutCheckInService.checkout(nodeRef2);
|
NodeRef workingCopy = checkOutCheckInService.checkout(nodeRef2);
|
||||||
|
|
||||||
assertTrue(nodeService.hasAspect(workingCopy, ASPECT_GOOGLERESOURCE));
|
assertTrue(nodeService.hasAspect(workingCopy, ASPECT_GOOGLERESOURCE));
|
||||||
assertNotNull(nodeService.getProperty(workingCopy, PROP_URL));
|
assertNotNull(nodeService.getProperty(workingCopy, PROP_URL));
|
||||||
assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_ID));
|
assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_ID));
|
||||||
assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE));
|
assertNotNull(nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE));
|
||||||
|
|
||||||
System.out.println("Google doc URL: " + nodeService.getProperty(workingCopy, PROP_URL));
|
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 type: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_TYPE));
|
||||||
System.out.println("Google doc id: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_ID));
|
System.out.println("Google doc id: " + nodeService.getProperty(workingCopy, PROP_RESOURCE_ID));
|
||||||
|
|
||||||
checkOutCheckInService.checkin(workingCopy, null);
|
checkOutCheckInService.checkin(workingCopy, null);
|
||||||
|
|
||||||
assertFalse(nodeService.hasAspect(nodeRefDoc, ASPECT_GOOGLERESOURCE));
|
assertFalse(nodeService.hasAspect(nodeRefDoc, ASPECT_GOOGLERESOURCE));
|
||||||
contentReader = contentService.getReader(nodeRef2, ContentModel.PROP_CONTENT);
|
contentReader = contentService.getReader(nodeRef2, ContentModel.PROP_CONTENT);
|
||||||
assertNotNull(contentReader);
|
assertNotNull(contentReader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user