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 CommonsDistributionStagingMojoTest {
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 detachmentMojo;
52
53 private CommonsDistributionStagingMojo mojoForTest;
54
55 @Before
56 public void setUp() throws Exception {
57 final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
58 if (testingDirectory.exists()) {
59 FileUtils.deleteDirectory(testingDirectory);
60 }
61 }
62
63 @Test
64 public void testSuccess() throws Exception {
65 final File testPom = new File("src/test/resources/mojos/stage-distributions/stage-distributions.xml");
66 assertNotNull(testPom);
67 assertTrue(testPom.exists());
68 final File detachmentPom = new File("src/test/resources/mojos/detach-distributions/detach-distributions.xml");
69 assertNotNull(detachmentPom);
70 assertTrue(detachmentPom.exists());
71 mojoForTest = (CommonsDistributionStagingMojo) rule.lookupMojo("stage-distributions", testPom);
72 detachmentMojo = (CommonsDistributionDetachmentMojo) rule.lookupMojo("detach-distributions", detachmentPom);
73 detachmentMojo.execute();
74 final File releaseNotesBasedir = new File("src/test/resources/mojos/stage-distributions/");
75 mojoForTest.setBaseDir(releaseNotesBasedir);
76 mojoForTest.execute();
77 assertRequisiteFilesExist();
78 }
79
80 @Test
81 public void testDisabled() throws Exception {
82 final File testPom = new File("src/test/resources/mojos/stage-distributions/stage-distributions-disabled.xml");
83 assertNotNull(testPom);
84 assertTrue(testPom.exists());
85 mojoForTest = (CommonsDistributionStagingMojo) rule.lookupMojo("stage-distributions", testPom);
86 mojoForTest.execute();
87 final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
88 assertFalse(testingDirectory.exists());
89 }
90
91 private void assertRequisiteFilesExist() {
92 final File targetScmDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1");
93 final File releaseNotes = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/RELEASE-NOTES.txt");
94 final File readmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/README.html");
95 final File headerHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/HEADER.html");
96 final File signatureValidatorScript = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/signature-validator.sh");
97 final File binariesReadmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/README.html");
98 final File binariesHeaderHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/HEADER.html");
99 final File binTar = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/commons-text-1.4-bin.tar.gz");
100 final File binTarASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/commons-text-1.4-bin.tar.gz.asc");
101 final File binTarSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/commons-text-1.4-bin.tar.gz.sha512");
102 final File binZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/commons-text-1.4-bin.zip");
103 final File binZipASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/commons-text-1.4-bin.zip.asc");
104 final File binZipSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/commons-text-1.4-bin.zip.sha512");
105 final File sourcesReadmeHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/README.html");
106 final File sourceHeaderHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/binaries/HEADER.html");
107 final File srcTar = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/commons-text-1.4-src.tar.gz");
108 final File srcTarASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/commons-text-1.4-src.tar.gz.asc");
109 final File srcTarSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/commons-text-1.4-src.tar.gz.sha512");
110 final File srcZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/commons-text-1.4-src.zip");
111 final File srcZipASC = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/commons-text-1.4-src.zip.asc");
112 final File srcZipSha512 = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/source/commons-text-1.4-src.zip.sha512");
113 final File site = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/site");
114 final File siteIndexHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/site/index.html");
115 final File siteSubdirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/site/subdirectory");
116 final File siteSubdirectoryIndexHtml = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/scm/1.0-SNAPSHOT-RC1/site/subdirectory/index.html");
117 assertTrue(targetScmDirectory.exists());
118 assertTrue(releaseNotes.exists());
119 assertTrue(readmeHtml.exists());
120 assertTrue(headerHtml.exists());
121 assertTrue(signatureValidatorScript.exists());
122 assertTrue(binariesReadmeHtml.exists());
123 assertTrue(binariesHeaderHtml.exists());
124 assertTrue(binTar.exists());
125 assertTrue(binTarASC.exists());
126 assertTrue(binTarSha512.exists());
127 assertTrue(binZip.exists());
128 assertTrue(binZipASC.exists());
129 assertTrue(binZipSha512.exists());
130 assertTrue(sourcesReadmeHtml.exists());
131 assertTrue(sourceHeaderHtml.exists());
132 assertTrue(srcTar.exists());
133 assertTrue(srcTarASC.exists());
134 assertTrue(srcTarSha512.exists());
135 assertTrue(srcZip.exists());
136 assertTrue(srcZipASC.exists());
137 assertTrue(srcZipSha512.exists());
138 assertTrue(site.exists());
139 assertTrue(siteIndexHtml.exists());
140 assertTrue(siteSubdirectory.exists());
141 assertTrue(siteSubdirectoryIndexHtml.exists());
142 }
143 }