-
Notifications
You must be signed in to change notification settings - Fork 3
Fixed testcase assertions to be env agnostic #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
reeshika-h
wants to merge
6
commits into
development
Choose a base branch
from
fix/DX-2420-pipeline-friendly
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
236a058
Refactor assertions in tests to use assertNotNull for improved valida…
reeshika-h 4ff32c9
Uncomment skipTests configuration in maven-surefire-plugin for test e…
reeshika-h eed871f
Add Slack reporting functionality and update dependencies
reeshika-h 10f0bd2
Enhance tests by adding assertions for entry parameters and headers; …
reeshika-h 6567ff4
Add SLF4J dependency and update JavaDoc links; comment out disabled t…
reeshika-h 1435a5d
Update assertions in tests to reflect expected header and entry counts
reeshika-h File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
set -e # Exit immediately if any command fails | ||
|
||
echo "🧪 Running tests..." | ||
mvn clean test | ||
|
||
echo "📄 Generating Surefire HTML report..." | ||
mvn surefire-report:report-only | ||
|
||
echo "📤 Sending test report to Slack..." | ||
mvn compile exec:java -Dexec.mainClass="com.contentstack.sdk.SanityReport" | ||
|
||
echo "✅ Done." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package com.contentstack.sdk; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
import com.slack.api.bolt.App; | ||
import com.slack.api.methods.SlackApiException; | ||
import com.slack.api.methods.response.chat.ChatPostMessageResponse; | ||
import com.slack.api.methods.response.files.FilesUploadV2Response; | ||
|
||
public class SanityReport { | ||
|
||
private static final String PROPERTIES_FILE = "src/test/resources/test-config.properties"; | ||
|
||
public void generateTestSummaryAndSendToSlack(File reportFile) throws IOException, SlackApiException { | ||
Properties properties = loadProperties(PROPERTIES_FILE); | ||
|
||
String slackToken = properties.getProperty("SLACK_BOT_TOKEN"); | ||
String slackChannelID = properties.getProperty("SLACK_CHANNEL_ID"); | ||
String signingSecret = properties.getProperty("SLACK_SIGNING_SECRET"); | ||
String slackChannel = properties.getProperty("SLACK_CHANNEL"); | ||
|
||
if (slackToken == null || slackChannelID == null) { | ||
System.err.println("Missing Slack credentials in properties."); | ||
return; | ||
} | ||
|
||
if (!reportFile.exists()) { | ||
System.err.println("Surefire report file not found at: " + reportFile.getAbsolutePath()); | ||
return; | ||
} | ||
|
||
String message = generateTestSummary(reportFile); | ||
App app = configureSlackApp(slackToken, signingSecret); | ||
|
||
sendMessageToSlack(app, slackChannel, message); | ||
uploadReportToSlack(app, slackChannelID, reportFile); | ||
} | ||
|
||
private Properties loadProperties(String filePath) { | ||
Properties properties = new Properties(); | ||
try (FileInputStream inputStream = new FileInputStream(filePath)) { | ||
properties.load(inputStream); | ||
} catch (IOException e) { | ||
System.err.println("Failed to load properties: " + e.getMessage()); | ||
} | ||
return properties; | ||
} | ||
|
||
private App configureSlackApp(String token, String secret) { | ||
App app = new App(); | ||
app.config().setSigningSecret(secret); | ||
app.config().setSingleTeamBotToken(token); | ||
return app; | ||
} | ||
|
||
private void sendMessageToSlack(App app, String channel, String message) throws IOException, SlackApiException { | ||
ChatPostMessageResponse response = app.client().chatPostMessage(r -> r | ||
.channel(channel) | ||
.text(message) | ||
); | ||
if (response.isOk()) { | ||
System.out.println("Message sent successfully!"); | ||
} else { | ||
System.err.println("Failed to send message: " + response.getError()); | ||
} | ||
} | ||
|
||
private void uploadReportToSlack(App app, String channelID, File file) throws IOException, SlackApiException { | ||
FilesUploadV2Response response = app.client().filesUploadV2(fuvr -> fuvr | ||
.channel(channelID) | ||
.initialComment("Here is the report generated") | ||
.filename(file.getName()) | ||
.file(file) | ||
); | ||
if (response.isOk()) { | ||
System.out.println("Report uploaded successfully!"); | ||
} else { | ||
System.err.println("Failed to upload report: " + response.getError()); | ||
} | ||
|
||
} | ||
|
||
private String generateTestSummary(File surefireReportFile) throws IOException { | ||
Document doc = Jsoup.parse(surefireReportFile, "UTF-8"); | ||
Elements summaryRows = doc.select("table.table tr.b"); | ||
Element summaryRow = summaryRows.first(); | ||
|
||
int totalTests = 0, errors = 0, failures = 0, skipped = 0, passedTests, totalSuites, failedSuites = 0; | ||
String duration = "0m 0s"; | ||
|
||
if (summaryRow != null) { | ||
Elements cells = summaryRow.select("td"); | ||
if (cells.size() >= 6) { | ||
totalTests = Integer.parseInt(cells.get(0).text()); | ||
errors = Integer.parseInt(cells.get(1).text()); | ||
failures = Integer.parseInt(cells.get(2).text()); | ||
skipped = Integer.parseInt(cells.get(3).text()); | ||
|
||
String timeText = cells.get(5).text(); | ||
if (timeText.contains("s")) { | ||
double seconds = Double.parseDouble(timeText.replace(" s", "")); | ||
duration = (int) seconds / 60 + "m " + (int) seconds % 60 + "s"; | ||
} | ||
} | ||
} | ||
|
||
Elements testSuiteRows = doc.select("table:contains(Class) tr"); | ||
totalSuites = testSuiteRows.size() - 1; | ||
|
||
for (Element row : testSuiteRows) { | ||
Elements errorCells = row.select("td:nth-child(4)"); | ||
Elements failureCells = row.select("td:nth-child(5)"); | ||
if (!errorCells.isEmpty() && !failureCells.isEmpty()) { | ||
try { | ||
if (Integer.parseInt(errorCells.text()) > 0 || Integer.parseInt(failureCells.text()) > 0) { | ||
failedSuites++; | ||
} | ||
} catch (NumberFormatException ignored) { | ||
} | ||
} | ||
} | ||
|
||
passedTests = totalTests - failures - errors - skipped; | ||
|
||
return "*Java CDA Test Report*\n" | ||
+ "• Total Suites: " + totalSuites + "\n" | ||
+ "• Total Tests: " + totalTests + "\n" | ||
+ "• Passed Tests: " + passedTests + "\n" | ||
+ "• Failed Suites: " + failedSuites + "\n" | ||
+ "• Failed Tests: " + failures + "\n" | ||
+ "• Skipped Tests: " + skipped + "\n" | ||
+ "• Duration: " + duration; | ||
} | ||
|
||
public static void main(String[] args) { | ||
File reportFile = new File("target/reports/surefire.html"); | ||
try { | ||
new SanityReport().generateTestSummaryAndSendToSlack(reportFile); | ||
} catch (IOException | SlackApiException e) { | ||
System.err.println("Error: " + e.getMessage()); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can u please check if the value US is valid or not? For NA region. The known valid values were NA / AWS-NA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well by default it does take the NA host. This US check is being made in live preview functionality