org.alfresco.repo.content.transform
Class AbstractContentTransformerTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.alfresco.repo.content.transform.AbstractContentTransformerTest
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AppleIWorksContentTransformerTest, ArchiveContentTransformerTest, BinaryPassThroughContentTransformerTest, ComplexContentTransformerTest, ContentTransformerRegistryTest, FailoverContentTransformerTest, HtmlParserContentTransformerTest, ImageMagickContentTransformerTest, MailContentTransformerTest, MediaWikiContentTransformerTest, OpenOfficeContentTransformerTest, PdfBoxContentTransformerTest, PdfBoxPdfToImageContentTransformerTest, PoiContentTransformerTest, PoiOOXMLContentTransformerTest, StringExtractingContentTransformerTest, TextMiningContentTransformerTest, TextToPdfContentTransformerTest, TikaPoweredContentTransformerTest

public abstract class AbstractContentTransformerTest
extends junit.framework.TestCase

Provides a base set of tests for testing ContentTransformer implementations.


Field Summary
protected  org.springframework.context.ApplicationContext ctx
          This context will be fetched each time, but almost always will have been cached by ApplicationContextHelper
protected  org.alfresco.service.cmr.repository.MimetypeService mimetypeService
           
protected static java.lang.String QUICK_CONTENT
           
protected  ServiceRegistry serviceRegistry
           
 
Constructor Summary
AbstractContentTransformerTest()
           
 
Method Summary
protected  void additionalContentCheck(java.lang.String sourceMimetype, java.lang.String targetMimetype, java.lang.String contents)
          Allows implementations to do some extra checks on the results of the content as found by AbstractContentTransformerTest.testAllConversions()
protected static org.alfresco.service.cmr.repository.ContentReader buildContentReader(java.lang.String text, java.nio.charset.Charset encoding)
          Writes the supplied text out to a temporary file, and opens a content reader onto it.
protected  java.lang.String[] getQuickFilenames(java.lang.String sourceMimetype)
          For the given mime type, returns one or more quick* files to be tested.
protected abstract  ContentTransformer getTransformer(java.lang.String sourceMimetype, java.lang.String targetMimetype)
          Fetches a transformer to test for a given transformation.
protected  boolean isQuickPhraseExpected(java.lang.String targetMimetype)
          This method is an extension point for enabling/disabling an assertion that the "quick brown fox" phrase is present in the transformed content.
protected  boolean isQuickWordsExpected(java.lang.String targetMimetype)
          This method is an extension point for enabling/disabling an assertion that the "quick brown fox" words are each present in the transformed content.
protected  boolean isTransformationExcluded(java.lang.String sourceExtension, java.lang.String targetExtension)
          This method is an extension point for excluding certain transformations in a subclass.
static java.io.File loadNamedQuickTestFile(java.lang.String quickname)
          Helper method to load one of the "The quick brown fox" files from the classpath.
static java.io.File loadQuickTestFile(java.lang.String extension)
          Helper method to load one of the "The quick brown fox" files from the classpath.
protected  void setUp()
          Ensures that the temp locations are cleaned out before the tests start
 void testAllConversions()
          Tests the full range of transformations available on the transformer subject to the available test files and the reliability of the transformer itself.
 void testSetUp()
          Check that all objects are present
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

QUICK_CONTENT

protected static java.lang.String QUICK_CONTENT

ctx

protected org.springframework.context.ApplicationContext ctx
This context will be fetched each time, but almost always will have been cached by ApplicationContextHelper


serviceRegistry

protected ServiceRegistry serviceRegistry

mimetypeService

protected org.alfresco.service.cmr.repository.MimetypeService mimetypeService
Constructor Detail

AbstractContentTransformerTest

public AbstractContentTransformerTest()
Method Detail

getTransformer

protected abstract ContentTransformer getTransformer(java.lang.String sourceMimetype,
                                                     java.lang.String targetMimetype)
Fetches a transformer to test for a given transformation. The transformer does not have to be reliable for the given format - if it isn't then it will be ignored.

Parameters:
sourceMimetype - the sourceMimetype to be tested
targetMimetype - the targetMimetype to be tested
Returns:
Returns the ContentTranslators that will be tested by the methods implemented in this class. A null return value is acceptable if the source and target mimetypes are not of interest.

setUp

protected void setUp()
              throws java.lang.Exception
Ensures that the temp locations are cleaned out before the tests start

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception

testSetUp

public void testSetUp()
               throws java.lang.Exception
Check that all objects are present

Throws:
java.lang.Exception

loadNamedQuickTestFile

public static java.io.File loadNamedQuickTestFile(java.lang.String quickname)
                                           throws java.io.IOException
Helper method to load one of the "The quick brown fox" files from the classpath.

Parameters:
the - file required, eg quick.txt
Returns:
Returns a test resource loaded from the classpath or null if no resource could be found.
Throws:
java.io.IOException

loadQuickTestFile

public static java.io.File loadQuickTestFile(java.lang.String extension)
                                      throws java.io.IOException
Helper method to load one of the "The quick brown fox" files from the classpath.

Parameters:
the - file extension required, eg txt for the file quick.txt
Returns:
Returns a test resource loaded from the classpath or null if no resource could be found.
Throws:
java.io.IOException

getQuickFilenames

protected java.lang.String[] getQuickFilenames(java.lang.String sourceMimetype)
For the given mime type, returns one or more quick* files to be tested. By default this is just quick + the default extension. However, you can override this if you need special rules, eg quickOld.foo, quickMid.foo and quickNew.foo for differing versions of the file format.


buildContentReader

protected static org.alfresco.service.cmr.repository.ContentReader buildContentReader(java.lang.String text,
                                                                                      java.nio.charset.Charset encoding)
                                                                               throws java.io.IOException
Writes the supplied text out to a temporary file, and opens a content reader onto it.

Throws:
java.io.IOException

testAllConversions

public void testAllConversions()
                        throws java.lang.Exception
Tests the full range of transformations available on the transformer subject to the available test files and the reliability of the transformer itself.

Each transformation is repeated several times, with a transformer being requested for each transformation. In the case where optimizations are being done around the selection of the most appropriate transformer, different transformers could be used during the iteration process.

Results for the transformations are dumped to a temporary file named AbstractContentTransformerTest-results-1234.txt.

Throws:
java.lang.Exception

additionalContentCheck

protected void additionalContentCheck(java.lang.String sourceMimetype,
                                      java.lang.String targetMimetype,
                                      java.lang.String contents)
Allows implementations to do some extra checks on the results of the content as found by AbstractContentTransformerTest.testAllConversions()


isQuickPhraseExpected

protected boolean isQuickPhraseExpected(java.lang.String targetMimetype)
This method is an extension point for enabling/disabling an assertion that the "quick brown fox" phrase is present in the transformed content. By default, the phrase is expected in all text/plain outputs.

Parameters:
targetMimetype - mimetype of the target of the transformation
Returns:
true if phrase is expected else false.

isQuickWordsExpected

protected boolean isQuickWordsExpected(java.lang.String targetMimetype)
This method is an extension point for enabling/disabling an assertion that the "quick brown fox" words are each present in the transformed content. By default, the words in the phrase are expected in all text/* outputs.

Parameters:
targetMimetype - mimetype of the target of the transformation
Returns:
true if each word is expected else false.

isTransformationExcluded

protected boolean isTransformationExcluded(java.lang.String sourceExtension,
                                           java.lang.String targetExtension)
This method is an extension point for excluding certain transformations in a subclass. The default implementation returns false for all mime type pairs.

Parameters:
sourceExtension -
targetExtension -
Returns:


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.