1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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 }