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