View Javadoc
1   package org.apache.maven.plugins.assembly.archive.phase;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.mockito.Mockito.atLeastOnce;
23  import static org.mockito.Mockito.mock;
24  import static org.mockito.Mockito.verify;
25  import static org.mockito.Mockito.when;
26  
27  import org.apache.maven.model.Model;
28  import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
29  import org.apache.maven.plugins.assembly.archive.DefaultAssemblyArchiverTest;
30  import org.apache.maven.plugins.assembly.model.Assembly;
31  import org.apache.maven.plugins.assembly.model.FileSet;
32  import org.apache.maven.project.MavenProject;
33  import org.codehaus.plexus.archiver.Archiver;
34  import org.codehaus.plexus.logging.Logger;
35  import org.junit.Before;
36  import org.junit.Test;
37  import org.junit.runner.RunWith;
38  import org.mockito.junit.MockitoJUnitRunner;
39  
40  @RunWith( MockitoJUnitRunner.class )
41  public class FileSetAssemblyPhaseTest
42  {
43      private FileSetAssemblyPhase phase;
44      
45      @Before
46      public void setUp() 
47      {
48          Logger logger = mock( Logger.class );
49          when( logger.isDebugEnabled() ).thenReturn( true );
50  
51          this.phase = new FileSetAssemblyPhase();
52          phase.enableLogging( logger );
53      }
54  
55      @Test
56      public void testShouldNotFailWhenNoFileSetsSpecified()
57          throws Exception
58      {
59          final Assembly assembly = new Assembly();
60          assembly.setId( "test" );
61  
62          this.phase.execute( assembly, null, null );
63      }
64  
65      @Test
66      public void testShouldAddOneFileSet()
67          throws Exception
68      {
69          final Assembly assembly = new Assembly();
70  
71          assembly.setId( "test" );
72          assembly.setIncludeBaseDirectory( false );
73  
74          final FileSet fs = new FileSet();
75          fs.setOutputDirectory( "/out" );
76          fs.setDirectory( "/input" );
77          fs.setFileMode( "777" );
78          fs.setDirectoryMode( "777" );
79  
80          assembly.addFileSet( fs );
81  
82          final MavenProject project = new MavenProject( new Model() );
83          project.setGroupId( "GROUPID" );
84  
85          final int dirMode = Integer.parseInt( "777", 8 );
86          final int fileMode = Integer.parseInt( "777", 8 );
87  
88          final int[] modes = { -1, -1, dirMode, fileMode };
89  
90          // the logger sends a debug message with this info inside the addFileSet(..) method..
91          final Archiver archiver = mock( Archiver.class );
92          when( archiver.getOverrideDirectoryMode() ).thenReturn( modes[0] );
93          when( archiver.getOverrideFileMode() ).thenReturn( modes[1] );
94      
95          final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
96          when( configSource.getProject() ).thenReturn( project );
97          when( configSource.getFinalName() ).thenReturn( "final-name" );
98          
99          DefaultAssemblyArchiverTest.setupInterpolators( configSource, project );
100 
101         this.phase.execute( assembly, archiver, configSource );
102 
103         // result of easymock migration, should be assert of expected result instead of verifying methodcalls
104         verify( configSource ).getArchiveBaseDirectory();
105         verify( configSource, atLeastOnce() ).getFinalName();
106         verify( configSource, atLeastOnce() ).getMavenSession();
107         verify( configSource, atLeastOnce() ).getProject();
108 
109         verify( archiver ).getOverrideDirectoryMode();
110         verify( archiver ).getOverrideFileMode();
111     }
112 }