18
18
import java .util .stream .Collectors ;
19
19
20
20
public class TestRunEmails extends Emails {
21
+ public TestRunEmails () throws AqualityException {
22
+ super ();
23
+ }
24
+
21
25
private AppProperties appProperties = new AppProperties ();
26
+ public void sendTestRunResultsToTeam (TestRunDto testRun , List <UserDto > users ) throws AqualityException , MessagingException , IOException , URISyntaxException {
27
+ ProjectDto project = getProject (testRun .getProject_id ());
22
28
23
- public void sendTestRunResultsToTeam (TestRunDto testRun , List <UserDto > users ) throws IOException , JSONException , SQLException , NamingException , IllegalAccessException , InstantiationException , MessagingException , URISyntaxException , AqualityException {
24
- ProjectDao projectDao = new ProjectDao ();
25
- ProjectDto projectDto = new ProjectDto ();
26
- projectDto .setId (testRun .getProject_id ());
27
- projectDto = projectDao .searchAll (projectDto ).get (0 );
28
- List <TestResultDto > testResults = testRun .getTestResults ();
29
- double totalResultsNum = testResults .size ();
30
- double passedResultsNum = (int ) testResults .stream ().filter (x -> x .getFinal_result ().getColor () == 5 ).count ();
31
- double failedResultsNum = (int ) testResults .stream ().filter (x -> x .getFinal_result ().getColor () == 1 ).count ();
32
- double notExecutedResultsNum = (int ) testResults .stream ().filter (x -> x .getFinal_result ().getColor () == 3 || x .getFinal_result ().getColor () == 2 || x .getFinal_result ().getColor () == 4 ).count ();
33
- List <TestResultDto > failedResults = testResults .stream ().filter (x -> x .getFinal_result ().getColor () != 5 ).collect (Collectors .toList ());
34
- List <TestResultDto > appIssues = failedResults .stream ().filter (x -> x .getTest_resolution ().getColor () == 1 ).collect (Collectors .toList ());
35
- List <TestResultDto > otherIssues = failedResults .stream ().filter (x -> x .getTest_resolution ().getColor () != 1 && x .getTest_resolution ().getColor () != 2 && x .getTest_resolution ().getColor () != 3 ).collect (Collectors .toList ());
36
- double successRate = passedResultsNum /totalResultsNum *100 ;
37
- String rateColor = successRate > 85 ? "#009900" : successRate > 65 ? "#ff6601" : "#cc2100" ;
38
- StringBuilder overview = new StringBuilder (appIssues .size () > 0 ? " <p style=\" font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;font-weight: bold;\" >Application Issues Overview:</p>\n " : "" );
39
- for (TestResultDto testResult : appIssues ) {
40
- overview .append (" <p style=\" font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;\" >" ).append (testResult .getTest ().getName ()).append (": " ).append (testResult .getComment () != null ? testResult .getComment () : "No comment for This Failure." ).append ("</p>\n " );
41
- }
29
+ double failedCount = getFailedResultsCount (testRun .getTestResults ());
30
+ double passedCount = getPassedResultsCount (testRun .getTestResults ());
31
+ double totalCount = getTotalResultsCount (testRun .getTestResults ());
32
+ double notExecutedCount = getNotExecutedResultsCount (testRun .getTestResults ());
33
+ double successRate = getSuccessRate (passedCount , totalCount );
34
+
35
+ List <TestResultDto > failed = getFailedResults (testRun .getTestResults ());
36
+ List <TestResultDto > appIssues = getAppIssues (failed );
37
+ List <TestResultDto > otherIssues = getOtherIssues (failed );
42
38
43
39
EmailDto email = new EmailDto ();
44
- email .setSubject ("[RP]:" + projectDto .getName () + " - " + new DecimalFormat ("##.##" ).format (successRate ) + "% - " + testRun .getBuild_name ());
40
+ email .setSubject ("[RP]:" + project .getName () + " - " + new DecimalFormat ("##.##" ).format (successRate ) + "% - " + testRun .getBuild_name ());
45
41
email .setContent ("<div style=\" \n " +
46
42
"margin-left: 20px;\n " +
47
43
"padding-left: 20px;\" >\n " +
@@ -60,32 +56,32 @@ public void sendTestRunResultsToTeam(TestRunDto testRun, List<UserDto> users) th
60
56
" font-weight: bold;\n " +
61
57
" font-family: Calibri, sans-serif;\n " +
62
58
" font-size: 15px;\n " +
63
- " line-height: 10px;\" href=\" " + hostUri () + "#/project/" + projectDto .getId () + "/testrun/" + testRun .getId () + "\" >View on " + appProperties .getName () + "</a>\n " +
59
+ " line-height: 10px;\" href=\" " + baseURL + "#/project/" + project .getId () + "/testrun/" + testRun .getId () + "\" >View on " + appProperties .getName () + "</a>\n " +
64
60
" </div>\n " +
65
61
" <hr>\n " +
66
- " <div style=\" margin: 0;font-family: Calibri, sans-serif;height:50px; padding-top:20px; color:" + rateColor + ";font-size: 30px;\" >\n " +
62
+ " <div style=\" margin: 0;font-family: Calibri, sans-serif;height:50px; padding-top:20px; color:" + getRateColor ( successRate ) + ";font-size: 30px;\" >\n " +
67
63
" Success Rate: " + new DecimalFormat ("##.##" ).format (successRate ) + "%\n " +
68
64
" </div>\n " +
69
65
" <br/>\n " +
70
66
" <p style=\" font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;font-weight: bold;\" >Test Results:</p>\n " +
71
67
" <p style=\" margin: 0; color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\" >\n " +
72
- " Passed | " + new DecimalFormat ("##" ).format (passedResultsNum ) + " | " + new DecimalFormat ("##.##" ).format (passedResultsNum / totalResultsNum *100 ) + "% </p>\n " +
68
+ " Passed | " + new DecimalFormat ("##" ).format (passedCount ) + " | " + new DecimalFormat ("##.##" ).format (passedCount / totalCount *100 ) + "% </p>\n " +
73
69
" <p style=\" margin: 0;color:#e27070;text-transform: uppercase;font-family: Calibri, sans-serif;\" >\n " +
74
- " Failed | " + new DecimalFormat ("##" ).format (failedResultsNum ) + " | " + new DecimalFormat ("##.##" ).format (failedResultsNum / totalResultsNum *100 ) +"% </p>\n " +
70
+ " Failed | " + new DecimalFormat ("##" ).format (failedCount ) + " | " + new DecimalFormat ("##.##" ).format (failedCount / totalCount *100 ) +"% </p>\n " +
75
71
" <p style=\" margin: 0;color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\" >\n " +
76
- " Not Executed | " + new DecimalFormat ("##" ).format (notExecutedResultsNum ) + " | " + new DecimalFormat ("##.##" ).format (notExecutedResultsNum / totalResultsNum *100 ) +"% </p>\n " +
72
+ " Not Executed | " + new DecimalFormat ("##" ).format (notExecutedCount ) + " | " + new DecimalFormat ("##.##" ).format (notExecutedCount / totalCount *100 ) +"% </p>\n " +
77
73
" <br/>\n " +
78
74
" <p style=\" font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;font-weight: bold;\" >Failed Test Resolutions:</p>\n " +
79
75
" <p style=\" margin: 0;color:#e27070;text-transform: uppercase;font-family: Calibri, sans-serif;\" >\n " +
80
76
" Application Issues | " + appIssues .size () + " </p>\n " +
81
77
" <p style=\" margin: 0;color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\" >\n " +
82
- " Test Issues | " + (int ) failedResults .stream ().filter (x -> x .getTest_resolution ().getColor () == 2 ).count () + " </p>\n " +
78
+ " Test Issues | " + (int ) failed .stream ().filter (x -> x .getTest_resolution ().getColor () == 2 ).count () + " </p>\n " +
83
79
" <p style=\" margin: 0;color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\" >\n " +
84
- " Not Assigned | " + (int ) failedResults .stream ().filter (x -> x .getTest_resolution ().getColor () == 3 ).count () + " </p>\n " +
80
+ " Not Assigned | " + (int ) failed .stream ().filter (x -> x .getTest_resolution ().getColor () == 3 ).count () + " </p>\n " +
85
81
" <p style=\" margin: 0;color:#676767;text-transform: uppercase;font-family: Calibri, sans-serif;\" >\n " +
86
82
" Other Issues | " + otherIssues .size () + " </p>\n " +
87
83
" <br/>\n " +
88
- overview +
84
+ buildIssuesOverview ( appIssues ) +
89
85
" <br/>\n " +
90
86
" <hr>\n " +
91
87
" <br/>\n " +
@@ -100,15 +96,73 @@ public void sendTestRunResultsToTeam(TestRunDto testRun, List<UserDto> users) th
100
96
" </p>\n " +
101
97
"</div>" );
102
98
email .setRecipients (getProjectMemberRecipients (users ));
103
- EmailSettingsDao emailSettingsDao = new EmailSettingsDao ();
104
- EmailSettingsDto settings = emailSettingsDao .getAll ().get (0 );
105
- settings .setPassword (emailSettingsDao .getAdminSecret (settings .getPassword ()));
106
- EmailUtil emailUtil = new EmailUtil (settings );
107
- emailUtil .SendHtmlEmail (email .getRecipients (), email .getSubject (), email .getContent ());
99
+ if (!sendEmail (email )) {
100
+ throw new AqualityException ("Was not able to send Email!" );
101
+ }
102
+ }
103
+
104
+ private ProjectDto getProject (Integer id ) throws AqualityException {
105
+ ProjectDao projectDao = new ProjectDao ();
106
+ ProjectDto projectDto = new ProjectDto ();
107
+ projectDto .setId (id );
108
+ return projectDao .getEntityById (projectDto );
108
109
}
109
110
110
111
private List <String > getProjectMemberRecipients (List <UserDto > users ) {
111
112
return users .stream ().map (UserDto ::getEmail ).collect (Collectors .toList ());
112
113
}
113
114
115
+ private double getSuccessRate (double passedCount , double totalCount ) {
116
+ return passedCount /totalCount *100 ;
117
+ }
118
+
119
+ private List <TestResultDto > getAppIssues (List <TestResultDto > testResults ) {
120
+ return testResults .stream ().filter (x -> x .getTest_resolution ().getColor () == 1 ).collect (Collectors .toList ());
121
+ }
122
+
123
+ private List <TestResultDto > getFailedResults (List <TestResultDto > testResults ) {
124
+ return testResults .stream ().filter (x -> x .getFinal_result ().getColor () != 5 ).collect (Collectors .toList ());
125
+ }
126
+
127
+ private List <TestResultDto > getOtherIssues (List <TestResultDto > testResults ) {
128
+ return testResults .stream ().filter (x -> x .getTest_resolution ().getColor () != 1 && x .getTest_resolution ().getColor () != 2 && x .getTest_resolution ().getColor () != 3 ).collect (Collectors .toList ());
129
+ }
130
+
131
+ private double getTotalResultsCount (List <TestResultDto > testResults ) {
132
+ return testResults .size ();
133
+ }
134
+
135
+ private double getNotExecutedResultsCount (List <TestResultDto > testResults ) {
136
+ return (int ) testResults .stream ().filter (x -> x .getFinal_result ().getColor () == 3 || x .getFinal_result ().getColor () == 2 || x .getFinal_result ().getColor () == 4 ).count ();
137
+ }
138
+
139
+ private double getPassedResultsCount (List <TestResultDto > testResults ) {
140
+ return (int ) testResults .stream ().filter (x -> x .getFinal_result ().getColor () == 5 ).count ();
141
+ }
142
+
143
+ private double getFailedResultsCount (List <TestResultDto > testResults ) {
144
+ return (int ) testResults .stream ().filter (x -> x .getFinal_result ().getColor () == 1 ).count ();
145
+ }
146
+
147
+ private String getRateColor (double successRate ) {
148
+ return successRate > 85 ? "#009900" : successRate > 65 ? "#ff6601" : "#cc2100" ;
149
+ }
150
+
151
+ private StringBuilder buildIssuesOverview (List <TestResultDto > appIssues ){
152
+ StringBuilder overview = new StringBuilder (appIssues .size () > 0 ? " <p style=\" font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;font-weight: bold;\" >Application Issues Overview:</p>\n " : "" );
153
+
154
+ for (TestResultDto testResult : appIssues ) {
155
+ overview
156
+ .append (" <p style=\" font-family: Calibri, sans-serif;margin:0;color: #4c4c4c;\" >" )
157
+ .append (testResult .getTest ().getName ())
158
+ .append (": " )
159
+ .append (
160
+ testResult .getComment () != null
161
+ ? testResult .getComment ()
162
+ : "No comment for This Failure." )
163
+ .append ("</p>\n " );
164
+ }
165
+
166
+ return overview ;
167
+ }
114
168
}
0 commit comments