View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.release.plugin.mojos;
18  
19  import static junit.framework.TestCase.assertTrue;
20  import static org.junit.Assert.assertFalse;
21  
22  import java.io.File;
23  
24  import org.apache.maven.api.plugin.testing.InjectMojo;
25  import org.apache.maven.api.plugin.testing.MojoTest;
26  import org.codehaus.plexus.util.FileUtils;
27  import org.junit.jupiter.api.BeforeEach;
28  import org.junit.jupiter.api.Test;
29  
30  /**
31   * Unit tests for {@link CommonsDistributionDetachmentMojo}.
32   */
33  @MojoTest
34  public class CommonsDistributionDetachmentMojoTest {
35  
36      private static final String COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH = "target/testing-commons-release-plugin";
37  
38      @BeforeEach
39      public void setUp() throws Exception {
40          final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
41          if (testingDirectory.exists()) {
42              FileUtils.deleteDirectory(testingDirectory);
43          }
44      }
45  
46      @Test
47      @InjectMojo(goal = "detach-distributions", pom = "src/test/resources/mojos/detach-distributions/detach-distributions-disabled.xml")
48      public void testDisabled(final CommonsDistributionDetachmentMojo mojo) throws Exception {
49          mojo.execute();
50          final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
51          assertFalse(testingDirectory.exists());
52      }
53  
54      @Test
55      @InjectMojo(goal = "detach-distributions", pom = "src/test/resources/mojos/detach-distributions/detach-distributions.xml")
56      public void testSuccess(final CommonsDistributionDetachmentMojo mojo) throws Exception {
57          mojo.execute();
58          final File detachedSrcTarGz = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.tar.gz");
59          final File detachedSrcTarGzAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.tar.gz.asc");
60          final File detachedSrcTarGzSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.tar.gz.sha512");
61          final File detachedSrcZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.zip");
62          final File detachedSrcZipAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.zip.asc");
63          final File detachedSrcZipSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.zip.sha512");
64          final File detachedBinTarGz = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.tar.gz");
65          final File detachedBinTarGzAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.tar.gz.asc");
66          final File detachedBinTarGzSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.tar.gz.sha512");
67          final File detachedBinZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.zip");
68          final File detachedBinZipAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.zip.asc");
69          final File detachedBinZipSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.zip.sha512");
70          final File notDetachedMockAttachedFile = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4.jar");
71          final File sha512Properties = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/sha512.properties");
72          assertTrue(detachedSrcTarGz.exists());
73          assertTrue(detachedSrcTarGzAsc.exists());
74          assertTrue(detachedSrcTarGzSha512.exists());
75          assertTrue(detachedSrcZip.exists());
76          assertTrue(detachedSrcZipAsc.exists());
77          assertTrue(detachedSrcZipSha512.exists());
78          assertTrue(detachedBinTarGz.exists());
79          assertTrue(detachedBinTarGzAsc.exists());
80          assertTrue(detachedBinTarGzSha512.exists());
81          assertTrue(detachedBinZip.exists());
82          assertTrue(detachedBinZipAsc.exists());
83          assertTrue(detachedBinZipSha512.exists());
84          assertTrue(sha512Properties.exists());
85          assertFalse(notDetachedMockAttachedFile.exists());
86      }
87  }