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    *      http://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  import static org.junit.Assert.assertNotNull;
22  
23  import java.io.File;
24  
25  import org.apache.maven.plugin.testing.MojoRule;
26  import org.codehaus.plexus.util.FileUtils;
27  import org.junit.Before;
28  import org.junit.Rule;
29  import org.junit.Test;
30  
31  /**
32   * Unit tests for {@link CommonsDistributionDetachmentMojo}.
33   */
34  public class CommonsDistributionDetachmentMojoTest {
35  
36      private static final String COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH = "target/testing-commons-release-plugin";
37  
38      @Rule
39      public final MojoRule rule = new MojoRule() {
40          @Override
41          protected void before() throws Throwable {
42              // noop
43          }
44  
45          @Override
46          protected void after() {
47              // noop
48          }
49      };
50  
51      private CommonsDistributionDetachmentMojo mojo;
52  
53      @Before
54      public void setUp() throws Exception {
55          final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
56          if (testingDirectory.exists()) {
57              FileUtils.deleteDirectory(testingDirectory);
58          }
59      }
60  
61      @Test
62      public void testSuccess() throws Exception {
63          final File testPom = new File("src/test/resources/mojos/detach-distributions/detach-distributions.xml");
64          assertNotNull(testPom);
65          assertTrue(testPom.exists());
66          mojo = (CommonsDistributionDetachmentMojo) rule.lookupMojo("detach-distributions", testPom);
67          mojo.execute();
68          final File detachedSrcTarGz = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.tar.gz");
69          final File detachedSrcTarGzAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.tar.gz.asc");
70          final File detachedSrcTarGzSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.tar.gz.sha512");
71          final File detachedSrcZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.zip");
72          final File detachedSrcZipAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.zip.asc");
73          final File detachedSrcZipSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-src.zip.sha512");
74          final File detachedBinTarGz = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.tar.gz");
75          final File detachedBinTarGzAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.tar.gz.asc");
76          final File detachedBinTarGzSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.tar.gz.sha512");
77          final File detachedBinZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.zip");
78          final File detachedBinZipAsc = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.zip.asc");
79          final File detachedBinZipSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4-bin.zip.sha512");
80          final File notDetachedMockAttachedFile = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/commons-text-1.4.jar");
81          final File sha512Properties = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/sha512.properties");
82          assertTrue(detachedSrcTarGz.exists());
83          assertTrue(detachedSrcTarGzAsc.exists());
84          assertTrue(detachedSrcTarGzSha512.exists());
85          assertTrue(detachedSrcZip.exists());
86          assertTrue(detachedSrcZipAsc.exists());
87          assertTrue(detachedSrcZipSha512.exists());
88          assertTrue(detachedBinTarGz.exists());
89          assertTrue(detachedBinTarGzAsc.exists());
90          assertTrue(detachedBinTarGzSha512.exists());
91          assertTrue(detachedBinZip.exists());
92          assertTrue(detachedBinZipAsc.exists());
93          assertTrue(detachedBinZipSha512.exists());
94          assertTrue(sha512Properties.exists());
95          assertFalse(notDetachedMockAttachedFile.exists());
96      }
97  
98      @Test
99      public void testDisabled() throws Exception {
100         final File testPom = new File("src/test/resources/mojos/detach-distributions/detach-distributions-disabled.xml");
101         assertNotNull(testPom);
102         assertTrue(testPom.exists());
103         mojo = (CommonsDistributionDetachmentMojo) rule.lookupMojo("detach-distributions", testPom);
104         mojo.execute();
105         final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
106         assertFalse(testingDirectory.exists());
107     }
108 }