@Test
public void testCreateArchive()
throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException,
IOException
{
final MockManager mm = new MockManager();
final MockAndControlForAssemblyArchiver macMgr = new MockAndControlForAssemblyArchiver( mm );
macMgr.expectGetArchiver( "zip", Archiver.class );
macMgr.expectGetDestFile( new File( "test" ) );
final MockControl phaseControl = MockControl.createControl( AssemblyArchiverPhase.class );
mm.add( phaseControl );
final AssemblyArchiverPhase phase = (AssemblyArchiverPhase) phaseControl.getMock();
phase.execute( null, null, null, null );
phaseControl.setMatcher( MockControl.ALWAYS_MATCHER );
final MockControl csControl = MockControl.createControl( AssemblerConfigurationSource.class );
mm.add( csControl );
final AssemblerConfigurationSource configSource = (AssemblerConfigurationSource) csControl.getMock();
final File tempDir = fileManager.createTempDir();
FileUtils.deleteDirectory( tempDir );
configSource.getTemporaryRootDirectory();
csControl.setReturnValue( tempDir, MockControl.ZERO_OR_MORE );
configSource.isDryRun();
csControl.setReturnValue( false, MockControl.ZERO_OR_MORE );
configSource.isIgnoreDirFormatExtensions();
csControl.setReturnValue( false, MockControl.ZERO_OR_MORE );
final File outDir = fileManager.createTempDir();
macMgr.archiver.setDestFile( new File( outDir, "full-name.zip" ) );
try
{
macMgr.archiver.createArchive();
}
catch ( final ArchiverException e )
{
fail( "Should never happen" );
}
catch ( final IOException e )
{
fail( "Should never happen" );
}
configSource.getOutputDirectory();
csControl.setReturnValue( outDir );
configSource.getFinalName();
csControl.setReturnValue( "finalName" );
configSource.getArchiverConfig();
csControl.setReturnValue( null, MockControl.ZERO_OR_MORE );
configSource.getWorkingDirectory();
csControl.setReturnValue( new File( "." ), MockControl.ZERO_OR_MORE );
configSource.isUpdateOnly();
csControl.setReturnValue( false, MockControl.ZERO_OR_MORE );
configSource.isIgnorePermissions();
csControl.setReturnValue( true, MockControl.ZERO_OR_MORE );
final Assembly assembly = new Assembly();
assembly.setId( "id" );
final AssemblyContext context = new DefaultAssemblyContext();
try
{
macMgr.dependencyResolver.resolve( assembly, configSource, context );
macMgr.dependencyResolverControl.setMatcher( MockControl.ALWAYS_MATCHER );
}
catch ( final DependencyResolutionException e )
{
fail( "Should never happen" );
}
mm.replayAll();
final DefaultAssemblyArchiver subject = createSubject( macMgr, Collections.singletonList( phase ), null );
subject.createArchive( assembly, "full-name", "zip", configSource );
mm.verifyAll();
}