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.junit.Before;
35  import org.junit.Test;
36  import org.junit.runner.RunWith;
37  import org.mockito.junit.MockitoJUnitRunner;
38  
39  @RunWith( MockitoJUnitRunner.class )
40  public class FileSetAssemblyPhaseTest
41  {
42      private FileSetAssemblyPhase phase;
43      
44      @Before
45      public void setUp() 
46      {
47          this.phase = new FileSetAssemblyPhase();
48      }
49  
50      @Test
51      public void testShouldNotFailWhenNoFileSetsSpecified()
52          throws Exception
53      {
54          final Assembly assembly = new Assembly();
55          assembly.setId( "test" );
56  
57          this.phase.execute( assembly, null, null );
58      }
59  
60      @Test
61      public void testShouldAddOneFileSet()
62          throws Exception
63      {
64          final Assembly assembly = new Assembly();
65  
66          assembly.setId( "test" );
67          assembly.setIncludeBaseDirectory( false );
68  
69          final FileSet fs = new FileSet();
70          fs.setOutputDirectory( "/out" );
71          fs.setDirectory( "/input" );
72          fs.setFileMode( "777" );
73          fs.setDirectoryMode( "777" );
74  
75          assembly.addFileSet( fs );
76  
77          final MavenProject project = new MavenProject( new Model() );
78          project.setGroupId( "GROUPID" );
79  
80          final int dirMode = Integer.parseInt( "777", 8 );
81          final int fileMode = Integer.parseInt( "777", 8 );
82  
83          final int[] modes = { -1, -1, dirMode, fileMode };
84  
85          // the logger sends a debug message with this info inside the addFileSet(..) method..
86          final Archiver archiver = mock( Archiver.class );
87          when( archiver.getOverrideDirectoryMode() ).thenReturn( modes[0] );
88          when( archiver.getOverrideFileMode() ).thenReturn( modes[1] );
89      
90          final AssemblerConfigurationSource configSource = mock( AssemblerConfigurationSource.class );
91          when( configSource.getProject() ).thenReturn( project );
92          when( configSource.getFinalName() ).thenReturn( "final-name" );
93          
94          DefaultAssemblyArchiverTest.setupInterpolators( configSource, project );
95  
96          this.phase.execute( assembly, archiver, configSource );
97  
98          // result of easymock migration, should be assert of expected result instead of verifying methodcalls
99          verify( configSource ).getArchiveBaseDirectory();
100         verify( configSource, atLeastOnce() ).getFinalName();
101         verify( configSource, atLeastOnce() ).getMavenSession();
102         verify( configSource, atLeastOnce() ).getProject();
103 
104         verify( archiver ).getOverrideDirectoryMode();
105         verify( archiver ).getOverrideFileMode();
106     }
107 }