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( "source-repository.html" ).exists() );
56
57 URL reportURL = getGeneratedReport( "source-repository.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 assertEquals( getString( "report.scm.name" ) + " - " + getString( "report.scm.title" ),
70 response.getTitle() );
71
72
73 TextBlock[] textBlocks = response.getTextBlocks();
74
75 assertEquals( textBlocks.length, 6 );
76
77 assertEquals( getString( "report.scm.overview.title" ), textBlocks[0].getText() );
78 assertEquals( getString( "report.scm.general.intro" ), textBlocks[1].getText() );
79 assertEquals( getString( "report.scm.webaccess.title" ), textBlocks[2].getText() );
80 assertEquals( getString( "report.scm.webaccess.nourl" ), textBlocks[3].getText() );
81 assertEquals( getString( "report.scm.accessbehindfirewall.title" ), textBlocks[4].getText() );
82 assertEquals( getString( "report.scm.accessbehindfirewall.general.intro" ), textBlocks[5].getText() );
83 }
84
85
86
87
88
89
90 public void testReportWithWrongUrl()
91 throws Exception
92 {
93 File pluginXmlFile = new File( getBasedir(), "src/test/resources/plugin-configs/"
94 + "scm-wrong-url-plugin-config.xml" );
95 Mojo mojo = lookupMojo( "scm", pluginXmlFile );
96 assertNotNull( "Mojo found.", mojo );
97
98 setVariableValueToObject( mojo, "anonymousConnection", "scm:svn" );
99 try
100 {
101 mojo.execute();
102 assertTrue( "IllegalArgumentException NOT catched", false );
103 }
104 catch ( IllegalArgumentException e )
105 {
106 assertTrue( "IllegalArgumentException catched", true );
107 }
108
109 tearDown();
110 setUp();
111
112 mojo = lookupMojo( "scm", pluginXmlFile );
113 assertNotNull( "Mojo found.", mojo );
114 setVariableValueToObject( mojo, "anonymousConnection", "scm:svn:http" );
115 try
116 {
117 mojo.execute();
118 assertTrue( "IllegalArgumentException NOT catched", false );
119 }
120 catch ( Exception e )
121 {
122 assertTrue( "IllegalArgumentException catched", true );
123 }
124
125 tearDown();
126 setUp();
127
128 mojo = lookupMojo( "scm", pluginXmlFile );
129 assertNotNull( "Mojo found.", mojo );
130 setVariableValueToObject( mojo, "anonymousConnection", "scm" );
131 try
132 {
133 mojo.execute();
134 assertTrue( "IllegalArgumentException NOT catched", false );
135 }
136 catch ( Exception e )
137 {
138 assertTrue( "IllegalArgumentException catched", true );
139 }
140 }
141 }