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.assertEquals;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertNotNull;
23
24 import java.io.File;
25
26 import org.apache.maven.plugin.MojoFailureException;
27 import org.apache.maven.plugin.testing.MojoRule;
28 import org.codehaus.plexus.util.FileUtils;
29 import org.junit.Before;
30 import org.junit.Rule;
31 import org.junit.Test;
32
33
34
35
36 @SuppressWarnings("deprecation")
37 public class CommonsSiteCompressionMojoTest {
38
39 private static final String COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH = "target/testing-commons-release-plugin";
40
41 @Rule
42 public final MojoRule rule = new MojoRule() {
43 @Override
44 protected void before() throws Throwable {
45
46 }
47
48 @Override
49 protected void after() {
50
51 }
52 };
53
54 protected CommonsSiteCompressionMojo mojo;
55
56 @Before
57 public void setUp() throws Exception {
58 final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
59 if (testingDirectory.exists()) {
60 FileUtils.deleteDirectory(testingDirectory);
61 }
62 }
63
64 @Test
65 public void testCompressSiteSuccess() throws Exception {
66 final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
67 testingDirectory.mkdir();
68 final File testPom = new File("src/test/resources/mojos/compress-site/compress-site.xml");
69 assertNotNull(testPom);
70 assertTrue(testPom.exists());
71 mojo = (CommonsSiteCompressionMojo) rule.lookupMojo("compress-site", testPom);
72 mojo.execute();
73 final File siteZip = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH + "/site.zip");
74 assertTrue(siteZip.exists());
75 }
76
77 @Test
78 public void testCompressSiteDirNonExistentFailure() throws Exception {
79 final File testPom = new File("src/test/resources/mojos/compress-site/compress-site-failure.xml");
80 assertNotNull(testPom);
81 assertTrue(testPom.exists());
82 mojo = (CommonsSiteCompressionMojo) rule.lookupMojo("compress-site", testPom);
83 try {
84 mojo.execute();
85 } catch (final MojoFailureException e) {
86 assertEquals(
87 "\"mvn site\" was not run before this goal, or a siteDirectory did not exist.", e.getMessage()
88 );
89 }
90 }
91
92 @Test
93 public void testDisabled() throws Exception {
94 final File testPom = new File("src/test/resources/mojos/compress-site/compress-site-disabled.xml");
95 assertNotNull(testPom);
96 assertTrue(testPom.exists());
97 mojo = (CommonsSiteCompressionMojo) rule.lookupMojo("compress-site", testPom);
98 mojo.execute();
99 final File testingDirectory = new File(COMMONS_RELEASE_PLUGIN_TEST_DIR_PATH);
100 assertFalse(testingDirectory.exists());
101 }
102 }