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