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(getGoal(), "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
69 assertEquals(8, textBlocks.length - 1);
70 assertEquals(getString("report.scm.overview.title"), textBlocks[1].getText());
71 assertEquals(getString("report.scm.general.intro"), textBlocks[2].getText());
72 assertEquals(getString("report.scm.webaccess.title"), textBlocks[3].getText());
73 assertEquals(getString("report.scm.webaccess.nourl"), textBlocks[4].getText());
74 assertEquals(getString("report.scm.accessbehindfirewall.title"), textBlocks[5].getText());
75 assertEquals(getString("report.scm.accessbehindfirewall.general.intro"), textBlocks[6].getText());
76 }
77
78
79
80
81
82
83 public void testReportWithWrongUrl() throws Exception {
84 File pluginXmlFile =
85 new File(getBasedir(), "src/test/resources/plugin-configs/" + "scm-wrong-url-plugin-config.xml");
86 Mojo mojo = createReportMojo(getGoal(), pluginXmlFile);
87
88 setVariableValueToObject(mojo, "anonymousConnection", "scm:svn");
89 try {
90 mojo.execute();
91 fail("IllegalArgumentException NOT catched");
92 } catch (IllegalArgumentException e) {
93 assertTrue("IllegalArgumentException catched", true);
94 }
95
96 tearDown();
97 setUp();
98
99 mojo = lookupMojo("scm", pluginXmlFile);
100 assertNotNull("Mojo not found.", mojo);
101 setVariableValueToObject(mojo, "anonymousConnection", "scm:svn:http");
102 try {
103 mojo.execute();
104 fail("IllegalArgumentException NOT catched");
105 } catch (Exception e) {
106 assertTrue("IllegalArgumentException catched", true);
107 }
108
109 tearDown();
110 setUp();
111
112 mojo = lookupMojo("scm", pluginXmlFile);
113 assertNotNull("Mojo not found.", mojo);
114 setVariableValueToObject(mojo, "anonymousConnection", "scm");
115 try {
116 mojo.execute();
117 fail("IllegalArgumentException NOT catched");
118 } catch (Exception e) {
119 assertTrue("IllegalArgumentException catched", true);
120 }
121 }
122
123 @Override
124 protected String getGoal() {
125 return "scm";
126 }
127 }