Package org.apache.maven.plugin.assembly.testutils

Examples of org.apache.maven.plugin.assembly.testutils.MockManager


    }

    public void testExecute_ShouldNotIncludeRepositoryIfNonSpecifiedInAssembly()
        throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException
    {
        final MockManager mm = new MockManager();

        final MockAndControlForRepositoryAssembler macRepo = new MockAndControlForRepositoryAssembler( mm );
        final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver( mm );
        final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource( mm );

        final File tempRoot = fileManager.createTempDir();

        macCS.expectGetTemporaryRootDirectory( tempRoot );

        final Assembly assembly = new Assembly();

        assembly.setId( "test" );

        mm.replayAll();

        createPhase( macRepo.repositoryAssembler, new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) ).execute( assembly,
                                                                                                             macArchiver.archiver,
                                                                                                             macCS.configSource,
                                                                                                             new DefaultAssemblyContext() );

        mm.verifyAll();
    }
View Full Code Here


    }

    public void testExecute_ShouldIncludeOneRepository()
        throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException
    {
        final MockManager mm = new MockManager();

        final MockAndControlForRepositoryAssembler macRepo = new MockAndControlForRepositoryAssembler( mm );
        final MockAndControlForArchiver macArchiver = new MockAndControlForArchiver( mm );
        final MockAndControlForConfigSource macCS = new MockAndControlForConfigSource( mm );

        final File tempRoot = fileManager.createTempDir();

        macCS.expectGetTemporaryRootDirectory( tempRoot );
        macCS.expectGetProject( new MavenProject( new Model() ) );
        macCS.expectGetFinalName( "final-name" );

        final Assembly assembly = new Assembly();

        assembly.setId( "test" );

        final Repository repo = new Repository();

        repo.setOutputDirectory( "out" );
        repo.setDirectoryMode( "777" );
        repo.setFileMode( "777" );

        final int mode = TypeConversionUtils.modeToInt( "777", new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );

        final File outDir = new File( tempRoot, "out" );

        macArchiver.expectModeChange( -1, -1, mode, mode, true );
        macArchiver.expectAddDirectory( outDir, "out/", null, null );

        macRepo.expectAssemble( outDir, repo, macCS.configSource );

        assembly.addRepository( repo );

        mm.replayAll();

        createPhase( macRepo.repositoryAssembler, new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) ).execute( assembly,
                                                                                                             macArchiver.archiver,
                                                                                                             macCS.configSource,
                                                                                                             new DefaultAssemblyContext() );

        mm.verifyAll();
    }
View Full Code Here

    }

    public void test_getModuleSetResolutionRequirements()
        throws DependencyResolutionException
    {
        final MockManager mm = new MockManager();

        final MockControl csControl = MockControl.createControl( AssemblerConfigurationSource.class );
        mm.add( csControl );

        final AssemblerConfigurationSource cs = (AssemblerConfigurationSource) csControl.getMock();

        final File rootDir = new File( "root" );
        final MavenProject project = createMavenProject( "main-group", "main-artifact", "1", rootDir );

        final File module1Dir = new File( rootDir, "module-1" );
        final MavenProject module1 = createMavenProject( "main-group", "module-1", "1", module1Dir );
        final MavenProject module1a =
            createMavenProject( "group1", "module-1a", "1", new File( module1Dir, "module-1a" ) );
        final MavenProject module1b =
            createMavenProject( "group1.b", "module-1b", "1", new File( module1Dir, "module-1b" ) );

        module1.getModel().addModule( module1a.getArtifactId() );
        module1.getModel().addModule( module1b.getArtifactId() );

        final File module2Dir = new File( rootDir, "module-2" );
        final MavenProject module2 = createMavenProject( "main-group", "module-2", "1", module2Dir );
        final MavenProject module2a =
            createMavenProject( "main-group", "module-2a", "1", new File( module2Dir, "module-2a" ) );

        module2.getModel().addModule( module2a.getArtifactId() );

        project.getModel().addModule( module1.getArtifactId() );
        project.getModel().addModule( module2.getArtifactId() );

        final List<MavenProject> allProjects = new ArrayList<MavenProject>();
        allProjects.add( project );
        allProjects.add( module1 );
        allProjects.add( module1a );
        allProjects.add( module1b );
        allProjects.add( module2 );
        allProjects.add( module2a );

        cs.getReactorProjects();
        csControl.setReturnValue( allProjects, MockControl.ZERO_OR_MORE );

        cs.getProject();
        csControl.setReturnValue( project, MockControl.ZERO_OR_MORE );

        final ResolutionManagementInfo info = new ResolutionManagementInfo( project );

        final List<ModuleSet> moduleSets = new ArrayList<ModuleSet>();

        {
            final ModuleSet ms = new ModuleSet();
            ms.addInclude( "*module1*" );
            ms.setIncludeSubModules( false );

            final ModuleBinaries mb = new ModuleBinaries();

            final DependencySet ds = new DependencySet();
            ds.setScope( Artifact.SCOPE_COMPILE );

            mb.addDependencySet( ds );
            ms.setBinaries( mb );
            moduleSets.add( ms );
        }

        {
            final ModuleSet ms = new ModuleSet();
            ms.addInclude( "main-group:*" );
            ms.setIncludeSubModules( true );

            final ModuleBinaries mb = new ModuleBinaries();

            final DependencySet ds = new DependencySet();
            ds.setScope( Artifact.SCOPE_TEST );

            mb.addDependencySet( ds );
            ms.setBinaries( mb );
            moduleSets.add( ms );
        }

        mm.replayAll();

        final DefaultDependencyResolver resolver =
            new DefaultDependencyResolver( this.resolver, metadataSource, factory, collector, logger );
        resolver.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );

        final Assembly assembly = new Assembly();
        assembly.setModuleSets( moduleSets );

        resolver.getModuleSetResolutionRequirements( assembly, info, cs );

        assertTrue( info.isResolutionRequired() );

        final Set<MavenProject> enabledProjects = info.getEnabledProjects();
        assertTrue( enabledProjects.contains( project ) );

        assertTrue( enabledProjects.contains( module1 ) );

        // these should be excluded since sub-modules are not traversable
        assertFalse( enabledProjects.contains( module1a ) );
        assertFalse( enabledProjects.contains( module1b ) );

        assertTrue( enabledProjects.contains( module2 ) );
        assertTrue( enabledProjects.contains( module2a ) );

        // these are the two we directly set above.
        assertTrue( info.getScopeFilter().isIncludeTestScope() );
        assertTrue( info.getScopeFilter().isIncludeCompileScope() );

        // this combination should be implied by the two direct scopes set above.
        assertTrue( info.getScopeFilter().isIncludeRuntimeScope() );
        assertTrue( info.getScopeFilter().isIncludeProvidedScope() );
        assertTrue( info.getScopeFilter().isIncludeSystemScope() );

        mm.verifyAll();
    }
View Full Code Here

    @Test( expected = InvalidAssemblerConfigurationException.class )
    public void failWhenAssemblyIdIsNull()
        throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException
    {
        final MockManager mm = new MockManager();
        final MockAndControlForAssemblyArchiver macMgr = new MockAndControlForAssemblyArchiver( mm );

        final MockControl csControl = MockControl.createControl( AssemblerConfigurationSource.class );
        mm.add( csControl );

        final AssemblerConfigurationSource configSource = (AssemblerConfigurationSource) csControl.getMock();

        mm.replayAll();

        final DefaultAssemblyArchiver archiver = createSubject( macMgr, null, null );
        archiver.createArchive( new Assembly(), "full-name", "zip", configSource, false);

        mm.verifyAll();
    }
View Full Code Here

    @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, false);

        mm.verifyAll();
    }
View Full Code Here

    @Test
    public void testCreateArchiver_ShouldConfigureArchiver()
        throws NoSuchArchiverException, ArchiverException
    {
        final MockManager mm = new MockManager();

        final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver( mm );

        final TestArchiverWithConfig archiver = new TestArchiverWithConfig();

        macArchiverManager.expectGetArchiver( "dummy", archiver );

        final MockControl configCtl = MockControl.createControl( AssemblerConfigurationSource.class );
        final AssemblerConfigurationSource configSource = (AssemblerConfigurationSource) configCtl.getMock();

        final String simpleConfig = "value";

        configSource.getArchiverConfig();
        configCtl.setReturnValue( "<configuration><simpleConfig>" + simpleConfig + "</simpleConfig></configuration>",
                                  MockControl.ZERO_OR_MORE );

        final MavenProject project = new MavenProject( new Model() );

        configSource.getProject();
        configCtl.setReturnValue( project, MockControl.ZERO_OR_MORE );

        configSource.getMavenSession();
        configCtl.setReturnValue( null, MockControl.ZERO_OR_MORE );

        configSource.isDryRun();
        configCtl.setReturnValue( false, MockControl.ZERO_OR_MORE );

        configSource.getWorkingDirectory();
        configCtl.setReturnValue( new File( "." ), MockControl.ZERO_OR_MORE );

        configSource.isUpdateOnly();
        configCtl.setReturnValue( false, MockControl.ZERO_OR_MORE );

        final MockControl lrCtl = MockControl.createControl( ArtifactRepository.class );
        final ArtifactRepository lr = (ArtifactRepository) lrCtl.getMock();
        mm.add( lrCtl );

        lr.getBasedir();
        lrCtl.setReturnValue( "/path/to/local/repo", MockControl.ZERO_OR_MORE );

        configSource.getLocalRepository();
        configCtl.setReturnValue( lr, MockControl.ZERO_OR_MORE );

        configSource.isIgnorePermissions();
        configCtl.setReturnValue( true, MockControl.ZERO_OR_MORE );

        mm.add( configCtl );

        mm.replayAll();

        final DefaultAssemblyArchiver subject =
            createSubject( macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null );

        subject.createArchiver( "dummy", false, "finalName", configSource, null, false);

        assertEquals( simpleConfig, archiver.getSimpleConfig() );

        mm.verifyAll();
    }
View Full Code Here

    @Test
    public void testCreateArchiver_ShouldCreateTarArchiverWithNoCompression()
        throws NoSuchArchiverException, ArchiverException
    {
        final MockManager mm = new MockManager();

        final TestTarArchiver ttArchiver = new TestTarArchiver();

        final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver( mm );

        macArchiverManager.expectGetArchiver( "tar", ttArchiver );

        final MockControl configCtl = MockControl.createControl( AssemblerConfigurationSource.class );
        final AssemblerConfigurationSource configSource = (AssemblerConfigurationSource) configCtl.getMock();

        configSource.getTarLongFileMode();
        configCtl.setReturnValue( TarLongFileMode.FAIL, MockControl.ZERO_OR_MORE );

        configSource.isDryRun();
        configCtl.setReturnValue( false, MockControl.ZERO_OR_MORE );

        configSource.getArchiverConfig();
        configCtl.setReturnValue( null, MockControl.ZERO_OR_MORE );

        configSource.getProject();
        configCtl.setReturnValue( new MavenProject( new Model() ), MockControl.ZERO_OR_MORE );

        configSource.getJarArchiveConfiguration();
        configCtl.setReturnValue( null, MockControl.ZERO_OR_MORE );

        configSource.getWorkingDirectory();
        configCtl.setReturnValue( new File( "." ), MockControl.ZERO_OR_MORE );

        configSource.isUpdateOnly();
        configCtl.setReturnValue( false, MockControl.ZERO_OR_MORE );

        configSource.isIgnorePermissions();
        configCtl.setReturnValue( true, MockControl.ZERO_OR_MORE );

        mm.add( configCtl );

        mm.replayAll();

        final DefaultAssemblyArchiver subject =
            createSubject( macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null );

        subject.createArchiver( "tar", false, "finalName", configSource, null, false);

        assertNull( ttArchiver.compressionMethod );
        assertEquals( TarLongFileMode.FAIL, ttArchiver.longFileMode.getValue() );

        mm.verifyAll();
    }
View Full Code Here

    @Test
    public void testCreateArchiver_ShouldCreateWarArchiverWithIgnoreWebxmlSetToFalse()
        throws NoSuchArchiverException, ArchiverException
    {
        final MockManager mm = new MockManager();

        final TestWarArchiver twArchiver = new TestWarArchiver();

        final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver( mm );

        macArchiverManager.expectGetArchiver( "war", twArchiver );

        final MockControl configCtl = MockControl.createControl( AssemblerConfigurationSource.class );
        final AssemblerConfigurationSource configSource = (AssemblerConfigurationSource) configCtl.getMock();

        configSource.isDryRun();
        configCtl.setReturnValue( false, MockControl.ZERO_OR_MORE );

        configSource.getArchiverConfig();
        configCtl.setReturnValue( null, MockControl.ZERO_OR_MORE );

        configSource.getMavenSession();
        configCtl.setReturnValue( null, MockControl.ZERO_OR_MORE );

        configSource.getProject();
        configCtl.setReturnValue( new MavenProject( new Model() ), MockControl.ZERO_OR_MORE );

        configSource.getJarArchiveConfiguration();
        configCtl.setReturnValue( null, MockControl.ZERO_OR_MORE );

        configSource.getWorkingDirectory();
        configCtl.setReturnValue( new File( "." ), MockControl.ZERO_OR_MORE );

        configSource.isUpdateOnly();
        configCtl.setReturnValue( false, MockControl.ZERO_OR_MORE );

        configSource.isIgnorePermissions();
        configCtl.setReturnValue( true, MockControl.ZERO_OR_MORE );

        mm.add( configCtl );

        mm.replayAll();

        final DefaultAssemblyArchiver subject =
            createSubject( macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null );

        subject.createArchiver( "war", false, null, configSource, null, false);
View Full Code Here

    @Test
    public void testCreateArchiver_ShouldCreateZipArchiver()
        throws NoSuchArchiverException, ArchiverException
    {
        final MockManager mm = new MockManager();

        final ZipArchiver archiver = new ZipArchiver();

        final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver( mm );

        macArchiverManager.expectGetArchiver( "zip", archiver );

        final MockControl configCtl = MockControl.createControl( AssemblerConfigurationSource.class );
        final AssemblerConfigurationSource configSource = (AssemblerConfigurationSource) configCtl.getMock();

        configSource.isDryRun();
        configCtl.setReturnValue( false, MockControl.ZERO_OR_MORE );

        configSource.getArchiverConfig();
        configCtl.setReturnValue( null, MockControl.ZERO_OR_MORE );

        configSource.getWorkingDirectory();
        configCtl.setReturnValue( new File( "." ), MockControl.ZERO_OR_MORE );

        configSource.isUpdateOnly();
        configCtl.setReturnValue( false, MockControl.ZERO_OR_MORE );

        configSource.isIgnorePermissions();
        configCtl.setReturnValue( true, MockControl.ZERO_OR_MORE );

        mm.add( configCtl );

        mm.replayAll();

        final DefaultAssemblyArchiver subject =
            createSubject( macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null );

        subject.createArchiver( "zip", false, null, configSource, null, false);
View Full Code Here

    @Test
    public void testCreateWarArchiver_ShouldDisableIgnoreWebxmlOption()
        throws NoSuchArchiverException
    {
        final MockManager mm = new MockManager();

        final TestWarArchiver twArchiver = new TestWarArchiver();

        final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver( mm );

        macArchiverManager.expectGetArchiver( "war", twArchiver );

        mm.replayAll();

        final DefaultAssemblyArchiver subject =
            createSubject( macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null );

        subject.createWarArchiver();
View Full Code Here

TOP

Related Classes of org.apache.maven.plugin.assembly.testutils.MockManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.