mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
119558 gcornwell: Merged code coverage improvements to 5.1-MC1 (5.1.0) r117774 gjames: RA-567: Increase /workflow/processes API code coverage r117773 gjames: RA-567: /workflow/processes coverage, removed unused ActivitiTypeConverter r116883 gjames: RA-531: reapplied change after merge, for MultiTServiceImpl test coverage r116629 gjames: RA-568 Increase /workflow/process-definitions API code coverage r116574 gjames: RA-569 Increase /workflow/tasks API code coverage r116286 gjames: RA-567: Increase /workflow/processes API code coverage r115853 gjames: RA-566: Increasing /people api coverage (description field) r115811 gjames: RA-566: Increasing /people api coverage r113007 gjames: Adding additional test coverage for DictionaryNamespaceComponent and DynamicNamespacePrefixResolver RA-521 r113006 gjames: Adding additional test coverage for DictionaryNamespaceComponent and DictionaryComponent RA-514 r112969 gjames: Adding additional test coverage for TemplateServiceImpl RA-530 r112960 gjames: Alternative test approach for ModuleServiceImpl RA-520 r112703 gjames: Adding additional test coverage for NodeLocatorService RA-522 r112702 gjames: Adding additional test coverage for JobLockServiceImpl RA-516 r112699 gjames: Adding additional test coverage for ModuleServiceImpl RA-520 r112508 gjames: Adding additional test coverage for RenditionServiceImpl RA-526 r112476 gjames: Adding additional test coverage for ContentServiceImpl RA-513 r112475 gjames: Adding additional test coverage for MimetypeMap RA-519 r112238 gjames: Adding additional test coverage for MimetypeMap RA-519 r112237 gjames: Adding additional test coverage for TaggingService RA-529 r112236 gjames: Adding additional test coverage for MultiTServiceImpl RA-531 r112206 gjames: Adding additional test coverage for ContentServiceImpl RA-513 r112167 gcornwell: RA-523: Increase NodeService code coverage (removed redundant code that was testing a version store we no longer use) r112102 gjames: Reverted changes to PermissionServiceImpl for RA-524 r112048 gjames: Temporarily removed some PermissionServiceImpl code. I need to put it back. r111620 gjames: Adding additional test coverage for PermissionService RA-524 r111619 gjames: Added some @Override to make Sonar happier r111456 gjames: Adding additional test coverage for AuthenticationService RA-509 r111427 gjames: Adding additional test coverage for AttributeService RA-509 r111317 gjames: Adding additional test coverage for WorkflowService RA-533 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@119945 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
238 lines
9.6 KiB
Java
238 lines
9.6 KiB
Java
/*
|
|
* Copyright (C) 2005-2012 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.version;
|
|
|
|
import org.alfresco.error.AlfrescoRuntimeException;
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.repo.content.EmptyContentReader;
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.repo.content.MimetypeMapTest;
|
|
import org.alfresco.repo.content.transform.ContentTransformer;
|
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
|
import org.alfresco.service.cmr.repository.ContentReader;
|
|
import org.alfresco.service.cmr.repository.ContentService;
|
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
import org.alfresco.service.cmr.repository.NoTransformerException;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.TransformationOptions;
|
|
import org.alfresco.service.cmr.version.Version;
|
|
import org.alfresco.test_category.OwnJVMTestsCategory;
|
|
import org.junit.experimental.categories.Category;
|
|
|
|
import java.util.HashMap;
|
|
|
|
/**
|
|
* Tests for retrieving frozen content from a verioned node
|
|
*
|
|
* @author Roy Wetherall
|
|
*/
|
|
@Category(OwnJVMTestsCategory.class)
|
|
public class ContentServiceImplTest extends BaseVersionStoreTest
|
|
{
|
|
/**
|
|
* Test content data
|
|
*/
|
|
private final static String UPDATED_CONTENT = "This content has been updated with a new value.";
|
|
|
|
/**
|
|
* The version content store
|
|
*/
|
|
private ContentService contentService;
|
|
|
|
/**
|
|
* Called during the transaction setup
|
|
*/
|
|
protected void onSetUpInTransaction() throws Exception
|
|
{
|
|
super.onSetUpInTransaction();
|
|
|
|
// Get the instance of the required content service
|
|
this.contentService = (ContentService)this.applicationContext.getBean("contentService");
|
|
}
|
|
|
|
/**
|
|
* Test getReader
|
|
*/
|
|
public void testGetReader()
|
|
{
|
|
// Create a new versionable node
|
|
NodeRef versionableNode = createNewVersionableNode();
|
|
|
|
// Create a new version
|
|
Version version = createVersion(versionableNode, this.versionProperties);
|
|
NodeRef versionNodeRef = version.getFrozenStateNodeRef();
|
|
|
|
// Get the content reader for the frozen node
|
|
ContentReader contentReader = this.contentService.getReader(versionNodeRef, ContentModel.PROP_CONTENT);
|
|
assertNotNull(contentReader);
|
|
assertEquals(TEST_CONTENT, contentReader.getContentString());
|
|
|
|
// Now update the content and verison again
|
|
ContentWriter contentWriter = this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, true);
|
|
assertNotNull(contentWriter);
|
|
contentWriter.putContent(UPDATED_CONTENT);
|
|
Version version2 = createVersion(versionableNode, this.versionProperties);
|
|
NodeRef version2NodeRef = version2.getFrozenStateNodeRef();
|
|
|
|
// Get the content reader for the new verisoned content
|
|
ContentReader contentReader2 = this.contentService.getReader(version2NodeRef, ContentModel.PROP_CONTENT);
|
|
assertNotNull(contentReader2);
|
|
assertEquals(UPDATED_CONTENT, contentReader2.getContentString());
|
|
}
|
|
|
|
public void testTransformAndNulls()
|
|
{
|
|
NodeRef versionableNode = createNewVersionableNode();
|
|
ContentReader contentReader = this.contentService.getReader(versionableNode, ContentModel.PROP_CONTENT);
|
|
ContentWriter contentWriter = this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, false);
|
|
|
|
//Call deprecated methods
|
|
assertTrue(this.contentService.isTransformable(contentReader, contentWriter));
|
|
this.contentService.transform(contentReader, contentWriter, new HashMap<String, Object>());
|
|
assertNotNull(this.contentService.getActiveTransformers(contentReader.getMimetype(), contentWriter.getMimetype(), new TransformationOptions()));
|
|
assertNull(this.contentService.getTransformer(MimetypeMap.MIMETYPE_TEXT_PLAIN, MimetypeMap.MIMETYPE_IMAGE_PNG, new TransformationOptions()));
|
|
|
|
// this.nodeService.setProperty(versionableNode, ContentModel.PROP_NAME, "for debugTransformers.txt");
|
|
try
|
|
{
|
|
this.contentService.transform(new MimetypeMapTest.DummyContentReader(MimetypeMap.MIMETYPE_TEXT_PLAIN),
|
|
new MimetypeMapTest.DummyContentWriter(MimetypeMap.MIMETYPE_IMAGE_PNG),
|
|
new TransformationOptions(versionableNode,ContentModel.PROP_NAME, null, null));
|
|
} catch (NoTransformerException nte)
|
|
{
|
|
nte.getMessage().contains("No transformation exists");
|
|
}
|
|
|
|
try
|
|
{
|
|
this.contentService.transform(null, null);
|
|
fail("Should throw exception");
|
|
}
|
|
catch (AlfrescoRuntimeException are)
|
|
{
|
|
are.getMessage().contains("The content reader must be set");
|
|
}
|
|
|
|
ContentReader empty = new EmptyContentReader("empty.txt");
|
|
try
|
|
{
|
|
this.contentService.transform(empty, null);
|
|
fail("Should throw exception");
|
|
}
|
|
catch (AlfrescoRuntimeException are)
|
|
{
|
|
are.getMessage().contains("The content reader mimetype must be set");
|
|
}
|
|
|
|
try
|
|
{
|
|
this.contentService.isTransformable(empty, null, new TransformationOptions());
|
|
fail("Should throw exception");
|
|
}
|
|
catch (AlfrescoRuntimeException are)
|
|
{
|
|
are.getMessage().contains("The content reader mimetype must be set");
|
|
}
|
|
|
|
try
|
|
{
|
|
contentWriter.setMimetype(null);
|
|
this.contentService.transform(contentReader, contentWriter);
|
|
fail("Should throw exception");
|
|
}
|
|
catch (AlfrescoRuntimeException are)
|
|
{
|
|
are.getMessage().contains("The content writer mimetype must be set");
|
|
}
|
|
|
|
try
|
|
{
|
|
contentWriter.setMimetype(null);
|
|
this.contentService.isTransformable(contentReader, contentWriter, new TransformationOptions());
|
|
fail("Should throw exception");
|
|
}
|
|
catch (AlfrescoRuntimeException are)
|
|
{
|
|
are.getMessage().contains("The content writer mimetype must be set");
|
|
}
|
|
}
|
|
/**
|
|
* Test getWriter
|
|
*/
|
|
public void testGetWriter()
|
|
{
|
|
// Create a new versionable node
|
|
NodeRef versionableNode = createNewVersionableNode();
|
|
|
|
// Create a new version
|
|
Version version = createVersion(versionableNode, this.versionProperties);
|
|
|
|
// Get writer is not supported by the version content service
|
|
try
|
|
{
|
|
ContentWriter contentWriter = this.contentService.getWriter(
|
|
version.getFrozenStateNodeRef(),
|
|
ContentModel.PROP_CONTENT,
|
|
true);
|
|
contentWriter.putContent("bobbins");
|
|
fail("This operation is not supported.");
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
// An exception should be raised
|
|
}
|
|
}
|
|
|
|
// Commented out as OpenOffice is not on the build machines.
|
|
// public void testGetTransformer0()
|
|
// {
|
|
// ContentTransformer transformer = contentService.getTransformer("test", "application/vnd.ms-excel", 0,
|
|
// "application/x-shockwave-flash", new TransformationOptions());
|
|
// assertTrue("Should have found a transformer for 0 bytes", transformer != null);
|
|
// }
|
|
//
|
|
// public void testGetTransformer10K()
|
|
// {
|
|
// ContentTransformer transformer = contentService.getTransformer("test", "application/vnd.ms-excel", 1024*10,
|
|
// "application/x-shockwave-flash", new TransformationOptions());
|
|
// assertTrue("Should have found a transformer for 10 K", transformer != null);
|
|
// }
|
|
//
|
|
// public void testGetTransformer1M()
|
|
// {
|
|
// ContentTransformer transformer = contentService.getTransformer("test", "application/vnd.ms-excel", 1024*1024,
|
|
// "application/x-shockwave-flash", new TransformationOptions());
|
|
// assertTrue("Should have found a transformer for 1M", transformer != null);
|
|
// }
|
|
//
|
|
// public void testGetTransformer10M()
|
|
// {
|
|
// ContentTransformer transformer = contentService.getTransformer("test", "application/vnd.ms-excel", 1024*1024*10,
|
|
// "application/x-shockwave-flash", new TransformationOptions());
|
|
// assertTrue("Should NOT have found a transformer for 10M as the is a 1M limit on xsl mimetype", transformer == null);
|
|
// }
|
|
//
|
|
// public void testGetMaxSourceSizeByes()
|
|
// {
|
|
// long maxSourceSizeBytes = contentService.getMaxSourceSizeBytes("application/vnd.ms-excel",
|
|
// "application/x-shockwave-flash", new TransformationOptions());
|
|
// assertEquals("Should have found a transformer that can handle 1M", 1024*1024, maxSourceSizeBytes);
|
|
// }
|
|
}
|