1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.report.projectinfo;
20
21 import java.io.File;
22 import java.net.URL;
23
24 import com.meterware.httpunit.GetMethodWebRequest;
25 import com.meterware.httpunit.TextBlock;
26 import com.meterware.httpunit.WebConversation;
27 import com.meterware.httpunit.WebRequest;
28 import com.meterware.httpunit.WebResponse;
29 import org.apache.maven.plugin.Mojo;
30
31
32
33
34
35
36 public class ScmReportTest extends AbstractProjectInfoTestCase {
37
38
39
40 private static final WebConversation WEB_CONVERSATION = new WebConversation();
41
42
43
44
45
46
47 public void testReport() throws Exception {
48 generateReport("scm", "scm-plugin-config.xml");
49 assertTrue("Test html generated", getGeneratedReport("scm.html").exists());
50
51 URL reportURL = getGeneratedReport("scm.html").toURI().toURL();
52 assertNotNull(reportURL);
53
54
55 WebRequest request = new GetMethodWebRequest(reportURL.toString());
56 WebResponse response = WEB_CONVERSATION.getResponse(request);
57
58
59 assertTrue(response.isHTML());
60 assertTrue(response.getContentLength() > 0);
61
62
63 String expectedTitle = prepareTitle("scm project info", getString("report.scm.title"));
64 assertEquals(expectedTitle, response.getTitle());
65
66
67 TextBlock[] textBlocks = response.getTextBlocks();
68 assertEquals(6, textBlocks.length);
69 assertEquals(getString("report.scm.overview.title"), textBlocks[0].getText());
70 assertEquals(getString("report.scm.general.intro"), textBlocks[1].getText());
71 assertEquals(getString("report.scm.webaccess.title"), textBlocks[2].getText());
72 assertEquals(getString("report.scm.webaccess.nourl"), textBlocks[3].getText());
73 assertEquals(getString("report.scm.accessbehindfirewall.title"), textBlocks[4].getText());
74 assertEquals(getString("report.scm.accessbehindfirewall.general.intro"), textBlocks[5].getText());
75 }
76
77
78
79
80
81
82 public void testReportWithWrongUrl() throws Exception {
83 File pluginXmlFile =
84 new File(getBasedir(), "src/test/resources/plugin-configs/" + "scm-wrong-url-plugin-config.xml");
85 Mojo mojo = createReportMojo("scm", pluginXmlFile);
86
87 setVariableValueToObject(mojo, "anonymousConnection", "scm:svn");
88 try {
89 mojo.execute();
90 fail("IllegalArgumentException NOT catched");
91 } catch (IllegalArgumentException e) {
92 assertTrue("IllegalArgumentException catched", true);
93 }
94
95 tearDown();
96 setUp();
97
98 mojo = lookupMojo("scm", pluginXmlFile);
99 assertNotNull("Mojo not found.", mojo);
100 setVariableValueToObject(mojo, "anonymousConnection", "scm:svn:http");
101 try {
102 mojo.execute();
103 fail("IllegalArgumentException NOT catched");
104 } catch (Exception e) {
105 assertTrue("IllegalArgumentException catched", true);
106 }
107
108 tearDown();
109 setUp();
110
111 mojo = lookupMojo("scm", pluginXmlFile);
112 assertNotNull("Mojo not found.", mojo);
113 setVariableValueToObject(mojo, "anonymousConnection", "scm");
114 try {
115 mojo.execute();
116 fail("IllegalArgumentException NOT catched");
117 } catch (Exception e) {
118 assertTrue("IllegalArgumentException catched", true);
119 }
120 }
121 }