ro.isdc.wro.util
Class WroTestUtils

java.lang.Object
  extended by ro.isdc.wro.util.WroTestUtils

public class WroTestUtils
extends Object

WroTestUtils.

Author:
Alex Objelean

Constructor Summary
WroTestUtils()
           
 
Method Summary
static void assertProcessorSupportResourceTypes(ResourcePreProcessor processor, ResourceType... expectedResourceTypes)
          Asserts that a processor supports provided resource types.
static void compare(InputStream expected, InputStream actual)
          Compare if content of expected stream is the same as content of the actual stream.
static void compare(InputStream input, InputStream expected, ResourcePostProcessor processor)
           
static void compare(Reader resultReader, Reader expectedReader, ResourcePostProcessor processor)
          Compare contents of two resources (files) by performing some sort of processing on input resource.
static void compare(String expected, String actual)
          Compares two strings by removing trailing spaces & tabs for correct comparison.
static void compareFromDifferentFolders(File sourceFolder, File targetFolder, ResourcePreProcessor processor)
          Process and compare all the files from the sourceFolder and compare them with the files from the targetFolder.
static void compareFromDifferentFoldersByExtension(File sourceFolder, File targetFolder, String extension, ResourcePostProcessor processor)
          TODO run tests in parallel
static void compareFromDifferentFoldersByExtension(File sourceFolder, File targetFolder, String extension, ResourcePreProcessor processor)
           
static void compareFromDifferentFoldersByName(File sourceFolder, File targetFolder, String srcExtension, String targetExtension, ResourcePostProcessor processor)
          Compares files with the same name from sourceFolder against it's counterpart in targetFolder, but allows source and target files to have different extensions.
static void compareFromSameFolder(File sourceFolder, org.apache.commons.io.filefilter.IOFileFilter sourceFileFilter, Transformer<String> toTargetFileName, ResourcePreProcessor processor)
           
static void compareProcessedResourceContents(String inputResourceUri, String expectedContentResourceUri, ResourcePostProcessor processor)
          Compare contents of two resources (files) by performing some sort of processing on input resource.
static Injector createInjector()
           
static UriLocator createResourceMockingLocator()
           
static UriLocatorFactory createResourceMockingLocatorFactory()
           
static void forEachFileInFolder(File folder, Function<File,Void> function)
          Applies a function for each file from a folder.
static InputStream getInputStream(String uri)
           
static void init(WroModelFactory factory)
           
static void initProcessor(ResourcePostProcessor processor)
           
static void initProcessor(ResourcePreProcessor processor)
           
static void runConcurrently(Callable<Void> task)
          Run the task concurrently 50 times.
static void runConcurrently(Callable<Void> task, int times)
          Runs a task concurrently.
static BaseWroManagerFactory simpleManagerFactory()
           
static WroModelFactory simpleModelFactory(WroModel model)
          Creates a model factory for a given model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WroTestUtils

public WroTestUtils()
Method Detail

simpleManagerFactory

public static BaseWroManagerFactory simpleManagerFactory()
Returns:
a BaseWroManagerFactory which uses an empty model.

compareProcessedResourceContents

public static void compareProcessedResourceContents(String inputResourceUri,
                                                    String expectedContentResourceUri,
                                                    ResourcePostProcessor processor)
                                             throws IOException
Compare contents of two resources (files) by performing some sort of processing on input resource.

Parameters:
inputResourceUri - uri of the resource to process.
expectedContentResourceUri - uri of the resource to compare with processed content.
processor - a closure used to process somehow the input content.
Throws:
IOException

getInputStream

public static InputStream getInputStream(String uri)
                                  throws IOException
Throws:
IOException

init

public static void init(WroModelFactory factory)

initProcessor

public static void initProcessor(ResourcePreProcessor processor)

initProcessor

public static void initProcessor(ResourcePostProcessor processor)

compare

public static void compare(Reader resultReader,
                           Reader expectedReader,
                           ResourcePostProcessor processor)
                    throws IOException
Compare contents of two resources (files) by performing some sort of processing on input resource.

Parameters:
inputResourceUri - uri of the resource to process.
expectedContentResourceUri - uri of the resource to compare with processed content.
processor - a closure used to process somehow the input content.
Throws:
IOException

compare

public static void compare(InputStream input,
                           InputStream expected,
                           ResourcePostProcessor processor)
                    throws IOException
Throws:
IOException

compare

public static void compare(InputStream expected,
                           InputStream actual)
                    throws IOException
Compare if content of expected stream is the same as content of the actual stream. When compared content is not equal, the assertion error will be thrown.

Parameters:
expected - InputStream of the expected content.
actual - InputStream of the actual content.
Throws:
IOException

compare

public static void compare(String expected,
                           String actual)
Compares two strings by removing trailing spaces & tabs for correct comparison.


compareFromSameFolder

public static void compareFromSameFolder(File sourceFolder,
                                         org.apache.commons.io.filefilter.IOFileFilter sourceFileFilter,
                                         Transformer<String> toTargetFileName,
                                         ResourcePreProcessor processor)

compareFromDifferentFolders

public static void compareFromDifferentFolders(File sourceFolder,
                                               File targetFolder,
                                               ResourcePreProcessor processor)
                                        throws IOException
Process and compare all the files from the sourceFolder and compare them with the files from the targetFolder.

Throws:
IOException

compareFromDifferentFoldersByExtension

public static void compareFromDifferentFoldersByExtension(File sourceFolder,
                                                          File targetFolder,
                                                          String extension,
                                                          ResourcePreProcessor processor)
                                                   throws IOException
Throws:
IOException

compareFromDifferentFoldersByExtension

public static void compareFromDifferentFoldersByExtension(File sourceFolder,
                                                          File targetFolder,
                                                          String extension,
                                                          ResourcePostProcessor processor)
                                                   throws IOException
TODO run tests in parallel

Throws:
IOException

compareFromDifferentFoldersByName

public static void compareFromDifferentFoldersByName(File sourceFolder,
                                                     File targetFolder,
                                                     String srcExtension,
                                                     String targetExtension,
                                                     ResourcePostProcessor processor)
                                              throws IOException
Compares files with the same name from sourceFolder against it's counterpart in targetFolder, but allows source and target files to have different extensions. TODO run tests in parallel

Throws:
IOException

forEachFileInFolder

public static void forEachFileInFolder(File folder,
                                       Function<File,Void> function)
Applies a function for each file from a folder. The folder should contain at least one file to process, otherwise an exception will be thrown.

Parameters:
folder - File representing the folder where the files will be used from processing.
function - Function to apply on each found file.

runConcurrently

public static void runConcurrently(Callable<Void> task,
                                   int times)
                            throws Exception
Runs a task concurrently. Allows to test thread-safe behavior.

Parameters:
task - a Callable to run concurrently.
Throws:
Exception - if any of the executed tasks fails.

runConcurrently

public static void runConcurrently(Callable<Void> task)
                            throws Exception
Run the task concurrently 50 times.

Throws:
Exception

createInjector

public static Injector createInjector()
Returns:
a default Injector to be used by test classes.

simpleModelFactory

public static WroModelFactory simpleModelFactory(WroModel model)
Creates a model factory for a given model.


assertProcessorSupportResourceTypes

public static void assertProcessorSupportResourceTypes(ResourcePreProcessor processor,
                                                       ResourceType... expectedResourceTypes)
Asserts that a processor supports provided resource types.


createResourceMockingLocatorFactory

public static UriLocatorFactory createResourceMockingLocatorFactory()
Returns:
an implementation of UriLocatorFactory which always return a valid stream which contains the resource uri as content.

createResourceMockingLocator

public static UriLocator createResourceMockingLocator()
Returns:
an implementation of UriLocator which always return a valid stream which contains the resource uri as content.


Copyright © 2008-2013. All Rights Reserved.