Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target
work
.idea
*.iml
.classpath
.project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ public class CucumberResult {
final List<FeatureResult> featureResults;
final int passPercentage;
final int totalScenarios;

public CucumberResult(List<FeatureResult> featureResults, int totalScenarios, int passPercentage) {
this.featureResults = featureResults;
this.totalScenarios = totalScenarios;
this.passPercentage = passPercentage;
}

public int getPassPercentage() {
return this.passPercentage;
}

public int getTotalFeatures() {
return this.featureResults.size();
}

public int getTotalScenarios() {
return this.totalScenarios;
}

public List<FeatureResult> getFeatureResults() {
return this.featureResults;
}

public String toSlackMessage(final String jobName,
final int buildNumber, final String channel, final String jenkinsUrl, final String extra) {
final JsonObject json = new JsonObject();
Expand Down Expand Up @@ -66,7 +66,7 @@ private String getJenkinsHyperlink(final String jenkinsUrl, final String jobName
s.append("/");
return s.toString();
}

public String toHeader(final String jobName, final int buildNumber, final String jenkinsUrl, final String extra) {
StringBuilder s = new StringBuilder();
if (StringUtils.isNotEmpty(extra)) {
Expand All @@ -83,11 +83,11 @@ public String toHeader(final String jobName, final int buildNumber, final String
s.append(">");
return s.toString();
}

private void addCaption(final JsonObject json, final int buildNumber, final String jobName, final String jenkinsUrl, final String extra) {
json.addProperty("pretext", toHeader(jobName, buildNumber, jenkinsUrl, extra));
}

private void addColourAndIcon(JsonObject json, String good, String value) {
json.addProperty("color", good);
json.addProperty("icon_emoji", value);
Expand All @@ -111,7 +111,7 @@ private JsonArray getFields(final String jobName, final int buildNumber, final S
return fields;
}


private JsonObject shortObject(final String value) {
JsonObject obj = new JsonObject();
obj.addProperty("value", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ public FeatureResult(String name, int passPercentage) {
public String toString() {
return this.name + "=" + this.passPercentage;
}

public String getName() {
return this.name;
}

public String getFeatureUri() {
return this.name.replace(".feature", "-feature") + ".html";
return this.name.replaceAll("/", "-").replace(".feature", "-feature") + ".html";
}

public String getDisplayName() {
return this.name.replaceAll("_", " ").replace(".feature", "");
}

public int getPassPercentage() {
return this.passPercentage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public void canGenerateFullSuccessfulSlackMessage() throws FileNotFoundException
assertEquals(8, result.getTotalScenarios());
assertEquals(8, result.getTotalFeatures());
assertEquals(100, result.getPassPercentage());

String slackMessage = result.toSlackMessage("test-job", 7, "channel", "http://jenkins:8080/", null);
assertNotNull(slackMessage);
assertTrue(slackMessage.contains("<http://jenkins:8080/job/test-job/7/cucumber-html-reports/validate_gerrit_home_page-feature.html|validate gerrit home page>"));
assertTrue(slackMessage.contains("<http://jenkins:8080/job/test-job/7/cucumber-html-reports/features-validate_gerrit_home_page-feature.html|features/validate gerrit home page>"));
}

@Test
Expand All @@ -49,7 +49,7 @@ public void canGenerateMinimalSuccessfulSlackMessage() throws FileNotFoundExcept
String slackMessage = result.toSlackMessage("test-job", 7, "channel", "http://jenkins:8080/", null);
assertNotNull(slackMessage);
}

@Test
public void canGenerateFullFailedSlackMessage() throws FileNotFoundException {
JsonElement element = loadTestResultFile("failed-result.json");
Expand All @@ -73,7 +73,7 @@ public void canGenerateMinimalFailedSlackMessage() throws FileNotFoundException
assertEquals(1, result.getTotalFeatures());
assertEquals(87, result.getPassPercentage());
}

@Test
public void canGenerateGoodMessage() {
String slackMessage = successfulResult().toSlackMessage("test-job", 1, "channel", "http://jenkins:8080/", null);
Expand Down Expand Up @@ -107,15 +107,15 @@ private JsonElement getResultFileAsJsonElement(InputStream stream) {
final JsonReader jsonReader = new JsonReader(new InputStreamReader(stream));
return gson.fromJson(jsonReader, JsonElement.class);
}

private CucumberResult successfulResult() {
return new CucumberResult(Arrays.asList(new FeatureResult("Dummy Test", 100)),1,100);
}

private CucumberResult badResult() {
return new CucumberResult(Arrays.asList(new FeatureResult("Dummy Test", 0)),1,0);
}

private CucumberResult marginalResult() {
return new CucumberResult(Arrays.asList(new FeatureResult("Dummy Test", 99)),1,99);
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/resources/successful-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"type": "scenario"
}
],
"uri": "validate_confluence_home_page.feature"
"uri": "features/validate_confluence_home_page.feature"
},
{
"id": "validate-gerrit-home-page",
Expand Down Expand Up @@ -107,7 +107,7 @@
"type": "scenario"
}
],
"uri": "validate_gerrit_home_page.feature"
"uri": "features/validate_gerrit_home_page.feature"
},
{
"id": "validate-jenkins-home-page",
Expand Down Expand Up @@ -162,7 +162,7 @@
"type": "scenario"
}
],
"uri": "validate_jenkins_home_page.feature"
"uri": "features/validate_jenkins_home_page.feature"
},
{
"id": "validate-jira-home-page",
Expand Down Expand Up @@ -217,7 +217,7 @@
"type": "scenario"
}
],
"uri": "validate_jira_home_page.feature"
"uri": "features/validate_jira_home_page.feature"
},
{
"id": "validate-login-page",
Expand Down Expand Up @@ -296,7 +296,7 @@
"type": "scenario"
}
],
"uri": "validate_login_page.feature"
"uri": "features/validate_login_page.feature"
},
{
"id": "validate-nexus-home-page",
Expand Down Expand Up @@ -351,7 +351,7 @@
"type": "scenario"
}
],
"uri": "validate_nexus_home_page.feature"
"uri": "features/validate_nexus_home_page.feature"
},
{
"id": "validate-register-developer-page",
Expand Down Expand Up @@ -430,7 +430,7 @@
"type": "scenario"
}
],
"uri": "validate_register_developer_page.feature"
"uri": "features/validate_register_developer_page.feature"
},
{
"id": "validate-sonar-home-page",
Expand Down Expand Up @@ -485,6 +485,6 @@
"type": "scenario"
}
],
"uri": "validate_sonar_home_page.feature"
"uri": "features/validate_sonar_home_page.feature"
}
]