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.net.URL;
22
23 import com.meterware.httpunit.GetMethodWebRequest;
24 import com.meterware.httpunit.TextBlock;
25 import com.meterware.httpunit.WebConversation;
26 import com.meterware.httpunit.WebRequest;
27 import com.meterware.httpunit.WebResponse;
28 import org.w3c.dom.html.HTMLAnchorElement;
29
30
31
32
33
34
35 public class CiManagementReportTest extends AbstractProjectInfoTestCase {
36
37
38
39 private static final WebConversation WEB_CONVERSATION = new WebConversation();
40
41
42
43
44
45
46 public void testReport() throws Exception {
47 generateReport(getGoal(), "ci-management-plugin-config.xml");
48 assertTrue(
49 "Test html generated", getGeneratedReport("ci-management.html").exists());
50
51 URL reportURL = getGeneratedReport("ci-management.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("ci mangement project info", getString("report.ci-management.title"));
64 assertEquals(expectedTitle, response.getTitle());
65
66
67 TextBlock[] textBlocks = response.getTextBlocks();
68 assertEquals(getString("report.ci-management.name"), textBlocks[1].getText());
69 assertEquals(getString("report.ci-management.nocim"), textBlocks[2].getText());
70 }
71
72
73
74
75
76
77
78 public void testCiNameReport() throws Exception {
79 generateReport(getGoal(), "ci-management-plugin-with-ci-section-config.xml");
80 assertTrue(
81 "Test html generated", getGeneratedReport("ci-management.html").exists());
82
83 URL reportURL = getGeneratedReport("ci-management.html").toURI().toURL();
84 assertNotNull(reportURL);
85
86
87 WebRequest request = new GetMethodWebRequest(reportURL.toString());
88 WebResponse response = WEB_CONVERSATION.getResponse(request);
89
90
91 assertTrue(response.isHTML());
92 assertTrue(response.getContentLength() > 0);
93
94
95 TextBlock[] textBlocks = response.getTextBlocks();
96 TextBlock textBlock = textBlocks[2];
97 assertTrue(textBlock.getText().startsWith("This project uses "));
98 assertEquals(3, textBlock.getNode().getChildNodes().getLength());
99 HTMLAnchorElement anchor =
100 (HTMLAnchorElement) textBlock.getNode().getChildNodes().item(1);
101 assertEquals("https://www.jetbrains.com/teamcity/", anchor.getAttribute("href"));
102 assertEquals("TeamCity", anchor.getFirstChild().getNodeValue());
103 }
104
105 @Override
106 protected String getGoal() {
107 return "ci-management";
108 }
109 }