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