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 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
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
43 }
44
45 @Override
46 protected void after() {
47
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 }