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.params.ParameterizedTest;
27  import org.junit.jupiter.params.provider.MethodSource;
28  
29  import static org.junit.jupiter.api.Assertions.*;
30  
31  public class BcSignArtifactIT extends ITSupport {
32      public static Collection<Object[]> data() {
33          return Arrays.asList(new Object[][] {
34              {
35                  "/it/sign-release-in-default-dir/pom.xml",
36                  "/target/gpg/tarballs/",
37                  new String[] {"sign-release-in-default-dir-1.0.jar.asc"}
38              },
39              {
40                  "/it/sign-release-in-output-dir/pom.xml",
41                  "/target/signed-files/tarballs/",
42                  new String[] {"sign-release-in-output-dir-1.0.jar.asc"}
43              },
44              {
45                  "/it/sign-release-in-root-dir/pom.xml",
46                  "/signed-files/tarballs/",
47                  new String[] {"sign-release-in-root-dir-1.0.jar.asc"}
48              },
49              {
50                  "/it/sign-release-in-same-dir/pom.xml",
51                  "/target/tarballs/",
52                  new String[] {"sign-release-in-same-dir-1.0.jar", "sign-release-in-same-dir-1.0.jar.asc"}
53              },
54          });
55      }
56  
57      @MethodSource("data")
58      @ParameterizedTest
59      void testPlacementOfArtifactInOutputDirectory(String pomPath, String expectedFileLocation, String[] expectedFiles)
60              throws Exception {
61          // given
62          final File pomFile = InvokerTestUtils.getTestResource(pomPath);
63          final InvocationRequest request =
64                  InvokerTestUtils.createRequest(pomFile, mavenUserSettings, gpgHome, "bc", true);
65          final File integrationTestRootDirectory = new File(pomFile.getParent());
66          final File expectedOutputDirectory = new File(integrationTestRootDirectory + expectedFileLocation);
67  
68          // when
69          InvokerTestUtils.executeRequest(request, mavenHome, localRepository);
70  
71          // then
72          assertTrue(expectedOutputDirectory.isDirectory());
73  
74          String[] outputFiles = expectedOutputDirectory.list();
75          assertNotNull(outputFiles);
76  
77          Arrays.sort(outputFiles);
78          Arrays.sort(expectedFiles);
79          assertEquals(Arrays.toString(expectedFiles), Arrays.toString(outputFiles));
80      }
81  }