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.gpg.it;
20  
21  import java.io.File;
22  import java.util.Arrays;
23  import java.util.Collection;
24  
25  import org.apache.maven.shared.invoker.InvocationRequest;
26  import org.junit.jupiter.api.Test;
27  import org.junit.jupiter.params.ParameterizedTest;
28  import org.junit.jupiter.params.provider.MethodSource;
29  
30  import static org.junit.jupiter.api.Assertions.assertEquals;
31  import static org.junit.jupiter.api.Assertions.assertNotNull;
32  import static org.junit.jupiter.api.Assertions.assertTrue;
33  
34  public class GpgSignArtifactIT extends ITSupport {
35      public static Collection<Object[]> data() {
36          return Arrays.asList(new Object[][] {
37              {
38                  "/it/sign-release-in-default-dir/pom.xml",
39                  "/target/gpg/tarballs/",
40                  new String[] {"sign-release-in-default-dir-1.0.jar.asc"}
41              },
42              {
43                  "/it/sign-release-in-output-dir/pom.xml",
44                  "/target/signed-files/tarballs/",
45                  new String[] {"sign-release-in-output-dir-1.0.jar.asc"}
46              },
47              {
48                  "/it/sign-release-in-root-dir/pom.xml",
49                  "/signed-files/tarballs/",
50                  new String[] {"sign-release-in-root-dir-1.0.jar.asc"}
51              },
52              {
53                  "/it/sign-release-in-same-dir/pom.xml",
54                  "/target/tarballs/",
55                  new String[] {"sign-release-in-same-dir-1.0.jar", "sign-release-in-same-dir-1.0.jar.asc"}
56              },
57          });
58      }
59  
60      @MethodSource("data")
61      @ParameterizedTest
62      void testPlacementOfArtifactInOutputDirectory(String pomPath, String expectedFileLocation, String[] expectedFiles)
63              throws Exception {
64          // given
65          final File pomFile = InvokerTestUtils.getTestResource(pomPath);
66          final InvocationRequest request =
67                  InvokerTestUtils.createRequest(pomFile, mavenUserSettings, gpgHome, "gpg", true);
68          final File integrationTestRootDirectory = new File(pomFile.getParent());
69          final File expectedOutputDirectory = new File(integrationTestRootDirectory + expectedFileLocation);
70  
71          // when
72          InvokerTestUtils.executeRequest(request, mavenHome, localRepository);
73  
74          // then
75          assertTrue(expectedOutputDirectory.isDirectory());
76  
77          String[] outputFiles = expectedOutputDirectory.list();
78          assertNotNull(outputFiles);
79  
80          Arrays.sort(outputFiles);
81          Arrays.sort(expectedFiles);
82          assertEquals(Arrays.toString(expectedFiles), Arrays.toString(outputFiles));
83      }
84  
85      @Test
86      void testWorstPracticesStillWork() throws Exception {
87          // given
88          final File pomFile = InvokerTestUtils.getTestResource("/it/sign-release-in-same-dir/pom.xml");
89          final InvocationRequest request =
90                  InvokerTestUtils.createRequest(pomFile, mavenUserSettings, gpgHome, "gpg", false);
91          request.addArg("-Dgpg.bestPractices=false");
92          request.addArg("-Dgpg.passphrase=TEST");
93  
94          final File integrationTestRootDirectory = new File(pomFile.getParent());
95          final File expectedOutputDirectory = new File(integrationTestRootDirectory + "/target/tarballs/");
96  
97          // when
98          InvokerTestUtils.executeRequest(request, mavenHome, localRepository);
99  
100         // then
101         assertTrue(expectedOutputDirectory.isDirectory());
102 
103         String[] outputFiles = expectedOutputDirectory.list();
104         assertNotNull(outputFiles);
105 
106         String[] expectedFiles =
107                 new String[] {"sign-release-in-same-dir-1.0.jar", "sign-release-in-same-dir-1.0.jar.asc"};
108         Arrays.sort(outputFiles);
109         Arrays.sort(expectedFiles);
110         assertEquals(Arrays.toString(expectedFiles), Arrays.toString(outputFiles));
111     }
112 }