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