diff --git a/allure-notifications-api/src/main/java/guru/qa/allure/notifications/formatters/Formatters.java b/allure-notifications-api/src/main/java/guru/qa/allure/notifications/formatters/Formatters.java
index 08438854..d410cdbf 100644
--- a/allure-notifications-api/src/main/java/guru/qa/allure/notifications/formatters/Formatters.java
+++ b/allure-notifications-api/src/main/java/guru/qa/allure/notifications/formatters/Formatters.java
@@ -6,8 +6,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DurationFormatUtils;
-import java.text.*;
-
/**
* @author kadehar
* @since 4.0
@@ -38,20 +36,6 @@ public static String formatDuration(Long durationMillis, String format) {
return formattedDuration;
}
- public static double formatDouble(double value) {
- log.info("Formatting value {}", value);
- DecimalFormat df = new DecimalFormat("##.#");
- String tmp = df.format(value);
- NumberFormat numberFormat = NumberFormat.getInstance();
- try {
- double result = numberFormat.parse(tmp).doubleValue();
- log.info("Formatted value is {}", result);
- return result;
- } catch (ParseException e) {
- return 0.0;
- }
- }
-
public static String formatReportLink(String link) {
return link != null && link.endsWith("/") ? link + "allure" : link;
}
diff --git a/allure-notifications-api/src/main/java/guru/qa/allure/notifications/util/Percentage.java b/allure-notifications-api/src/main/java/guru/qa/allure/notifications/util/Percentage.java
index 61101c17..b45a370a 100644
--- a/allure-notifications-api/src/main/java/guru/qa/allure/notifications/util/Percentage.java
+++ b/allure-notifications-api/src/main/java/guru/qa/allure/notifications/util/Percentage.java
@@ -1,6 +1,5 @@
package guru.qa.allure.notifications.util;
-import guru.qa.allure.notifications.formatters.Formatters;
import lombok.extern.slf4j.Slf4j;
/**
@@ -13,7 +12,6 @@ public class Percentage {
public double eval(int result, int total) {
log.info("Calculate percentage for result {} by total {}", result,
total);
- double value = (result * 100.00) / total;
- return Formatters.formatDouble(value);
+ return (result * 100.00) / total;
}
}
diff --git a/allure-notifications-api/src/main/resources/templates/html.ftl b/allure-notifications-api/src/main/resources/templates/html.ftl
index b2dd78c8..e8a890e2 100644
--- a/allure-notifications-api/src/main/resources/templates/html.ftl
+++ b/allure-notifications-api/src/main/resources/templates/html.ftl
@@ -5,8 +5,8 @@
${phrases.scenario.duration}: ${time}
${phrases.scenario.totalScenarios}: ${total}
- <#if passed != 0 >- ${phrases.scenario.totalPassed}: ${passed} (${passedPercentage} %)
#if>
- <#if failed != 0 >- ${phrases.scenario.totalFailed}: ${failed} (${failedPercentage} %)
#if>
+ <#if passed != 0 >- ${phrases.scenario.totalPassed}: ${passed} (${passedPercentage?string("##.#")} %)
#if>
+ <#if failed != 0 >- ${phrases.scenario.totalFailed}: ${failed} (${failedPercentage?string("##.#")} %)
#if>
<#if broken != 0 >- ${phrases.scenario.totalBroken}: ${broken}
#if>
<#if unknown != 0 >- ${phrases.scenario.totalUnknown}: ${unknown}
#if>
<#if skipped != 0 >- ${phrases.scenario.totalSkipped}: ${skipped}
#if>
diff --git a/allure-notifications-api/src/main/resources/templates/markdown.ftl b/allure-notifications-api/src/main/resources/templates/markdown.ftl
index 681791a9..5c4d1ecd 100644
--- a/allure-notifications-api/src/main/resources/templates/markdown.ftl
+++ b/allure-notifications-api/src/main/resources/templates/markdown.ftl
@@ -4,8 +4,8 @@
*${phrases.comment}:* ${comm}
*${phrases.scenario.duration}:* ${time}
*${phrases.scenario.totalScenarios}:* ${total}
- <#if passed != 0 > *${phrases.scenario.totalPassed}:* ${passed} (${passedPercentage} %)#if>
- <#if failed != 0 > *${phrases.scenario.totalFailed}:* ${failed} (${failedPercentage} %)#if>
+ <#if passed != 0 > *${phrases.scenario.totalPassed}:* ${passed} (${passedPercentage?string("##.#")} %)#if>
+ <#if failed != 0 > *${phrases.scenario.totalFailed}:* ${failed} (${failedPercentage?string("##.#")} %)#if>
<#if broken != 0 > *${phrases.scenario.totalBroken}:* ${broken} #if>
<#if unknown != 0 >*${phrases.scenario.totalUnknown}:* ${unknown} #if>
<#if skipped != 0 >*${phrases.scenario.totalSkipped}:* ${skipped} #if>
diff --git a/allure-notifications-api/src/main/resources/templates/rocket.ftl b/allure-notifications-api/src/main/resources/templates/rocket.ftl
index ae200c13..af68f4fb 100644
--- a/allure-notifications-api/src/main/resources/templates/rocket.ftl
+++ b/allure-notifications-api/src/main/resources/templates/rocket.ftl
@@ -4,8 +4,8 @@
**-${phrases.comment}:** ${comm}
**-${phrases.scenario.duration}:** **${time}**
**-${phrases.scenario.totalScenarios}:** ${total}
- <#if passed != 0 > **-${phrases.scenario.totalPassed}:** ${passed} **(${passedPercentage} %)**#if>
- <#if failed != 0 > **-${phrases.scenario.totalFailed}:** ${failed} **(${failedPercentage} %)** #if>
+ <#if passed != 0 > **-${phrases.scenario.totalPassed}:** ${passed} **(${passedPercentage?string("##.#")} %)**#if>
+ <#if failed != 0 > **-${phrases.scenario.totalFailed}:** ${failed} **(${failedPercentage?string("##.#")} %)** #if>
<#if broken != 0 > **-${phrases.scenario.totalBroken}:** ${broken} #if>
<#if unknown != 0 > **-${phrases.scenario.totalUnknown}:** ${unknown} #if>
<#if skipped != 0 > **-${phrases.scenario.totalSkipped}:** ${skipped} #if>
diff --git a/allure-notifications-api/src/main/resources/templates/telegram.ftl b/allure-notifications-api/src/main/resources/templates/telegram.ftl
index e3998551..e1f4d33f 100644
--- a/allure-notifications-api/src/main/resources/templates/telegram.ftl
+++ b/allure-notifications-api/src/main/resources/templates/telegram.ftl
@@ -4,8 +4,8 @@
${phrases.comment}: ${comm}
${phrases.scenario.duration}: ${time}
${phrases.scenario.totalScenarios}: ${total}
- <#if passed != 0 >${phrases.scenario.totalPassed}: ${passed} (${passedPercentage} %)#if>
- <#if failed != 0 >${phrases.scenario.totalFailed}: ${failed} (${failedPercentage} %)#if>
+ <#if passed != 0 >${phrases.scenario.totalPassed}: ${passed} (${passedPercentage?string("##.#")} %)#if>
+ <#if failed != 0 >${phrases.scenario.totalFailed}: ${failed} (${failedPercentage?string("##.#")} %)#if>
<#if broken != 0 >${phrases.scenario.totalBroken}: ${broken}#if>
<#if unknown != 0 >${phrases.scenario.totalUnknown}: ${unknown}#if>
<#if skipped != 0 >${phrases.scenario.totalSkipped}: ${skipped}#if>
diff --git a/allure-notifications-api/src/test/java/guru/qa/allure/notifications/template/MessageTemplateTests.java b/allure-notifications-api/src/test/java/guru/qa/allure/notifications/template/MessageTemplateTests.java
index 3f6aa194..d3176dc0 100644
--- a/allure-notifications-api/src/test/java/guru/qa/allure/notifications/template/MessageTemplateTests.java
+++ b/allure-notifications-api/src/test/java/guru/qa/allure/notifications/template/MessageTemplateTests.java
@@ -1,5 +1,7 @@
package guru.qa.allure.notifications.template;
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mockConstruction;
@@ -8,19 +10,28 @@
import java.io.File;
import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.HashMap;
-import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.Mock;
import org.mockito.MockedConstruction;
import org.mockito.junit.jupiter.MockitoExtension;
import freemarker.template.Configuration;
import freemarker.template.Template;
+import guru.qa.allure.notifications.config.Config;
import guru.qa.allure.notifications.exceptions.MessageBuildException;
+import guru.qa.allure.notifications.json.JSON;
+import guru.qa.allure.notifications.model.phrases.Phrases;
+import guru.qa.allure.notifications.model.summary.Summary;
import guru.qa.allure.notifications.template.config.TemplateConfig;
import guru.qa.allure.notifications.template.data.MessageData;
@@ -66,4 +77,31 @@ void shouldCreateMessageFromTemplateFromJar() throws MessageBuildException, IOEx
verify(configuration).getTemplate(RESOURCES_PATH);
}
}
+
+ @ParameterizedTest
+ @CsvSource({
+ "templates/html.ftl, guru/qa/allure/notifications/template/messages/html.txt",
+ "templates/markdown.ftl, guru/qa/allure/notifications/template/messages/markdown.txt",
+ "templates/rocket.ftl, guru/qa/allure/notifications/template/messages/rocket.txt",
+ "templates/telegram.ftl, guru/qa/allure/notifications/template/messages/telegram.txt"
+ })
+ void shouldValidateGeneratedMessageFromTemplate(String templatePath, String expectedMessagePath)
+ throws IOException, URISyntaxException, MessageBuildException {
+ Config config = new JSON().parseResource(
+ "/guru/qa/allure/notifications/template/testConfig.json", Config.class);
+ Summary summary = new JSON().parseResource(
+ "/guru/qa/allure/notifications/template/testSummary.json", Summary.class);
+ ClassLoader classLoader = getClass().getClassLoader();
+ URL testSuitesUrl = classLoader.getResource("guru/qa/allure/notifications/template/testSuites.json");
+ String suitesSummaryJson = new String(Files.readAllBytes(Paths.get(testSuitesUrl.toURI())), UTF_8);
+ Phrases phrases = new JSON().parseResource("/phrases/en.json", Phrases.class);
+
+ MessageData testMessageData = new MessageData(config.getBase(), summary, suitesSummaryJson, phrases);
+ MessageTemplate messageTemplate = new MessageTemplate(testMessageData);
+
+ String messageGeneratedFromTemplate = messageTemplate.createMessageFromTemplate(templatePath);
+ URL expectedMessageUrl = classLoader.getResource(expectedMessagePath);
+ String expectedMessage = new String(Files.readAllBytes(Paths.get(expectedMessageUrl.toURI())), UTF_8);
+ assertEquals(expectedMessage, messageGeneratedFromTemplate);
+ }
}
diff --git a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/html.txt b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/html.txt
new file mode 100644
index 00000000..f877afc0
--- /dev/null
+++ b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/html.txt
@@ -0,0 +1,30 @@
+Results:
+Environment: Test
+Comment: Test comment
+Duration: 00:00:24.011
+Total scenarios: 3
+
+- Total passed: 2 (66.7 %)
+- Total failed: 1 (33.3 %)
+
+Number of test suites: 2
+
+
+
+Name of the test suite: batch-1
+Total scenarios: 2
+- Total passed: 1
+- Total failed: 1
+ |
+
+
+
+
+
+Name of the test suite: batch-2
+Total scenarios: 1
+- Total passed: 1
+ |
+
+
+Report available at the link: https://www.example.com
\ No newline at end of file
diff --git a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/markdown.txt b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/markdown.txt
new file mode 100644
index 00000000..4a728469
--- /dev/null
+++ b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/markdown.txt
@@ -0,0 +1,16 @@
+*Results:*
+*Environment:* Test
+*Comment:* Test comment
+*Duration:* 00:00:24.011
+*Total scenarios:* 3
+*Total passed:* 2 (66.7 %)
+*Total failed:* 1 (33.3 %)
+*Number of test suites:* 2
+*Name of the test suite:* batch-1
+> *Total scenarios:* 2
+> *Total passed:* 1
+> *Total failed:* 1
+*Name of the test suite:* batch-2
+> *Total scenarios:* 1
+> *Total passed:* 1
+*Report available at the link:* https://www.example.com
\ No newline at end of file
diff --git a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/rocket.txt b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/rocket.txt
new file mode 100644
index 00000000..bd492186
--- /dev/null
+++ b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/rocket.txt
@@ -0,0 +1,16 @@
+**Results:**
+**-Environment:** Test
+**-Comment:** Test comment
+**-Duration:** **00:00:24.011**
+**-Total scenarios:** 3
+**-Total passed:** 2 **(66.7 %)**
+**-Total failed:** 1 **(33.3 %)**
+**-Number of test suites:** **2**
+**-Name of the test suite:** **batch-1**
+**-Total scenarios:** **2**
+**-Total passed:** 1
+**-Total failed:** 1
+**-Name of the test suite:** **batch-2**
+**-Total scenarios:** **1**
+**-Total passed:** 1
+**Report available at the link:** https://www.example.com
\ No newline at end of file
diff --git a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/telegram.txt b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/telegram.txt
new file mode 100644
index 00000000..805a2cda
--- /dev/null
+++ b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/messages/telegram.txt
@@ -0,0 +1,16 @@
+Results:
+Environment: Test
+Comment: Test comment
+Duration: 00:00:24.011
+Total scenarios: 3
+Total passed: 2 (66.7 %)
+Total failed: 1 (33.3 %)
+Number of test suites: 2
+Name of the test suite: batch-1
+Total scenarios: 2
+Total passed: 1
+Total failed: 1
+Name of the test suite: batch-2
+Total scenarios: 1
+Total passed: 1
+Report available at the link: https://www.example.com
\ No newline at end of file
diff --git a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testConfig.json b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testConfig.json
new file mode 100644
index 00000000..dda676ef
--- /dev/null
+++ b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testConfig.json
@@ -0,0 +1,41 @@
+{
+ "base": {
+ "project": "TEST PROJECT",
+ "environment": "Test",
+ "comment": "Test comment",
+ "reportLink": "https://www.example.com",
+ "language": "en",
+ "allureFolder": "build/allure-report/",
+ "enableChart": true,
+ "logo": "logo.png",
+ "durationFormat": "HH:mm:ss.SSS",
+ "enableSuitesPublishing": "true"
+ },
+ "mail": {
+ "host": "smtp.gmail.com",
+ "port": "465",
+ "username": "user",
+ "password": "password",
+ "securityProtocol": "SSL",
+ "from": "test1@gmail.com",
+ "recipient": "test2@gmail.com"
+ },
+ "rocketChat" : {
+ "url": "https://www.example.com",
+ "auth_token": "authToken",
+ "user_id": "userId",
+ "channel": "channel",
+ "templatePath": "/templates/rocket.ftl"
+ },
+ "discord": {
+ "botToken": "testToken",
+ "channelId": "testChannelId",
+ "templatePath": "/templates/markdown.ftl"
+ },
+ "telegram": {
+ "token": "testToken",
+ "chat": "testChat",
+ "replyTo": "user",
+ "templatePath": "/templates/telegram.ftl"
+ }
+}
diff --git a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testSuites.json b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testSuites.json
new file mode 100644
index 00000000..34603a2c
--- /dev/null
+++ b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testSuites.json
@@ -0,0 +1 @@
+{"total":2,"items":[{"uid":"87b8be25e9c9e007e80824e508a2043b","name":"batch-1","statistic":{"failed":1,"broken":0,"skipped":0,"passed":1,"unknown":0,"total":2}},{"uid":"9c1ca7280386cbcc24a7a39c461dd533","name":"batch-2","statistic":{"failed":0,"broken":0,"skipped":0,"passed":1,"unknown":0,"total":1}}]}
\ No newline at end of file
diff --git a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testSummary.json b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testSummary.json
new file mode 100644
index 00000000..da748802
--- /dev/null
+++ b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testSummary.json
@@ -0,0 +1 @@
+{"reportName":"TEST Report","testRuns":[],"statistic":{"failed":1,"broken":0,"skipped":0,"passed":2,"unknown":0,"total":3},"time":{"start":1723022106448,"stop":1723022130459,"duration":24011,"minDuration":2045,"maxDuration":15512,"sumDuration":21736}}
\ No newline at end of file
diff --git a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testTemplate.ftl b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testTemplate.ftl
index d1843187..ffd8be80 100644
--- a/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testTemplate.ftl
+++ b/allure-notifications-api/src/test/resources/guru/qa/allure/notifications/template/testTemplate.ftl
@@ -5,8 +5,8 @@
${duration}: ${time}
${totalScenarios}: ${total}
- <#if passed != 0 >- ${totalPassed}: ${passed} (${passedPercentage} %)
#if>
- <#if failed != 0 >- ${totalFailed}: ${failed} (${failedPercentage} %)
#if>
+ <#if passed != 0 >- ${totalPassed}: ${passed} (${passedPercentage?string("##.#")} %)
#if>
+ <#if failed != 0 >- ${totalFailed}: ${failed} (${failedPercentage?string("##.#")} %)
#if>
<#if broken != 0 >- ${totalBroken}: ${broken}
#if>
<#if unknown != 0 >- ${totalUnknown}: ${unknown}
#if>
<#if skipped != 0 >- ${totalSkipped}: ${skipped}
#if>