-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #278
- Loading branch information
Showing
25 changed files
with
520 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
27 changes: 27 additions & 0 deletions
27
...tcodeltd/jenkinsci/plugins/build_monitor/questions/project_widget/ProjectBadgesState.java
This file contains 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,27 @@ | ||
package com.smartcodeltd.jenkinsci.plugins.build_monitor.questions.project_widget; | ||
|
||
import com.smartcodeltd.jenkinsci.plugins.build_monitor.user_interface.BuildMonitorDashboard; | ||
import net.serenitybdd.core.pages.WebElementState; | ||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.Question; | ||
import net.serenitybdd.screenplay.annotations.Subject; | ||
import net.serenitybdd.screenplay.targets.Target; | ||
|
||
import static net.serenitybdd.screenplay.questions.WebElementQuestion.stateOf; | ||
|
||
@Subject("the badges of widget representing the '#projectName' project on the Build Monitor") | ||
public class ProjectBadgesState implements Question<WebElementState> { | ||
|
||
@Override | ||
public WebElementState answeredBy(Actor actor) { | ||
Target widget = BuildMonitorDashboard.Project_Widget_Badges.of(projectName); | ||
|
||
return stateOf(widget).answeredBy(actor); | ||
} | ||
|
||
public ProjectBadgesState(String projectName) { | ||
this.projectName = projectName; | ||
} | ||
|
||
private final String projectName; | ||
} |
38 changes: 38 additions & 0 deletions
38
...ava/com/smartcodeltd/jenkinsci/plugins/build_monitor/tasks/ModifyControlPanelOptions.java
This file contains 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,38 @@ | ||
package com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks; | ||
|
||
import com.smartcodeltd.jenkinsci.plugins.build_monitor.user_interface.BuildMonitorDashboard; | ||
|
||
import net.serenitybdd.screenplay.jenkins.tasks.configuration.TodoList; | ||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.Performable; | ||
import net.serenitybdd.screenplay.Task; | ||
import net.serenitybdd.screenplay.actions.Click; | ||
import net.thucydides.core.annotations.Step; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Arrays.asList; | ||
import static net.serenitybdd.screenplay.Tasks.instrumented; | ||
|
||
public class ModifyControlPanelOptions implements Task { | ||
|
||
public static ModifyControlPanelOptions to(Task... configurationTasks) { | ||
return instrumented(ModifyControlPanelOptions.class, asList(configurationTasks)); | ||
} | ||
|
||
@Override | ||
@Step("{0} modifies the Build Monitor View control panel options") | ||
public <T extends Actor> void performAs(T actor) { | ||
actor.attemptsTo( | ||
Click.on(BuildMonitorDashboard.Control_Panel), | ||
configureTheView, | ||
Click.on(BuildMonitorDashboard.Control_Panel) | ||
); | ||
} | ||
|
||
public ModifyControlPanelOptions(List<Performable> actions) { | ||
this.configureTheView.addAll(actions); | ||
} | ||
|
||
private TodoList configureTheView = TodoList.empty(); | ||
} |
24 changes: 24 additions & 0 deletions
24
...ance/src/main/java/com/smartcodeltd/jenkinsci/plugins/build_monitor/tasks/ShowBadges.java
This file contains 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,24 @@ | ||
package com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks; | ||
|
||
import com.smartcodeltd.jenkinsci.plugins.build_monitor.user_interface.BuildMonitorDashboard; | ||
|
||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.Task; | ||
import net.serenitybdd.screenplay.actions.Click; | ||
import net.thucydides.core.annotations.Step; | ||
|
||
import static net.serenitybdd.screenplay.Tasks.instrumented; | ||
|
||
public class ShowBadges implements Task { | ||
public static Task onTheDashboard() { | ||
return instrumented(ShowBadges.class); | ||
} | ||
|
||
@Step("{0} decides to display the badges on the dashboard") | ||
@Override | ||
public <T extends Actor> void performAs(T actor) { | ||
actor.attemptsTo( | ||
Click.on(BuildMonitorDashboard.Show_Badges) | ||
); | ||
} | ||
} |
This file contains 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
31 changes: 31 additions & 0 deletions
31
...nitybdd/screenplay/jenkins/tasks/configuration/build_steps/AddAGroovyPostbuildScript.java
This file contains 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,31 @@ | ||
package net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps; | ||
|
||
import net.serenitybdd.screenplay.jenkins.user_interface.project_configuration.build_steps.GroovyPostBuildStep; | ||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.Task; | ||
import net.serenitybdd.screenplay.actions.Enter; | ||
import net.thucydides.core.annotations.Step; | ||
|
||
import static net.serenitybdd.screenplay.Tasks.instrumented; | ||
|
||
public class AddAGroovyPostbuildScript implements Task { | ||
|
||
public static Task that(GroovyScript expectedOutcome) { | ||
return instrumented(AddAGroovyPostbuildScript.class, expectedOutcome); | ||
} | ||
|
||
@Step("{0} configures the Groovy PostBuild Step to execute a script that '#scriptOutcome'") | ||
@Override | ||
public <T extends Actor> void performAs(T actor) { | ||
actor.attemptsTo( | ||
AddAPostBuildAction.called("Groovy Postbuild"), | ||
Enter.theValue(scriptOutcome.code()).into(GroovyPostBuildStep.Editor) | ||
); | ||
} | ||
|
||
public AddAGroovyPostbuildScript(GroovyScript script) { | ||
this.scriptOutcome = script; | ||
} | ||
|
||
private final GroovyScript scriptOutcome; | ||
} |
58 changes: 58 additions & 0 deletions
58
...java/net/serenitybdd/screenplay/jenkins/tasks/configuration/build_steps/GroovyScript.java
This file contains 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,58 @@ | ||
package net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.base.Joiner; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
import static com.google.common.collect.Lists.transform; | ||
import static java.util.Arrays.asList; | ||
|
||
public class GroovyScript { | ||
|
||
public static GroovyScript that(String descriptionOfScriptsBehaviour) { | ||
return new GroovyScript(descriptionOfScriptsBehaviour); | ||
} | ||
|
||
public GroovyScript definedAs(String... lines) { | ||
return this.definedAs(asList(lines)); | ||
} | ||
|
||
public GroovyScript definedAs(List<String> lines) { | ||
this.code = Joiner.on('\n').join(lines); | ||
|
||
return this; | ||
} | ||
|
||
public GroovyScript andOutputs(String... lines) { | ||
return definedAs(transform(asList(lines), mapEachLineTo("echo \"%s\";"))); | ||
} | ||
|
||
public String code() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return description; | ||
} | ||
|
||
private GroovyScript(String descriptionOfScriptsBehaviour) { | ||
this.description = descriptionOfScriptsBehaviour; | ||
} | ||
|
||
private Function<String, String> mapEachLineTo(final String template) { | ||
return new Function<String, String>() { | ||
@Nullable | ||
@Override | ||
public String apply(@Nullable String line) { | ||
return String.format(template, line); | ||
} | ||
}; | ||
} | ||
|
||
private final String description; | ||
|
||
private String code = ""; | ||
} |
6 changes: 6 additions & 0 deletions
6
.../net/serenitybdd/screenplay/jenkins/tasks/configuration/build_steps/GroovyScriptThat.java
This file contains 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,6 @@ | ||
package net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps; | ||
|
||
public class GroovyScriptThat { | ||
public static final GroovyScript Adds_A_Badge = GroovyScript.that("Adds a badge") | ||
.definedAs("manager.addShortText('Coverage', 'black', 'repeating-linear-gradient(45deg, yellow, yellow 10px, Orange 10px, Orange 20px)', '0px', 'white')"); | ||
} |
7 changes: 7 additions & 0 deletions
7
...eenplay/jenkins/user_interface/project_configuration/build_steps/GroovyPostBuildStep.java
This file contains 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,7 @@ | ||
package net.serenitybdd.screenplay.jenkins.user_interface.project_configuration.build_steps; | ||
|
||
import net.serenitybdd.screenplay.targets.Target; | ||
|
||
public class GroovyPostBuildStep { | ||
public static final Target Editor = Target.the("code editor").locatedBy("(//div[@descriptorid='org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder']//textarea)[last()]"); | ||
} |
64 changes: 64 additions & 0 deletions
64
build-monitor-acceptance/src/test/java/features/ShouldDisplayBadges.java
This file contains 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,64 @@ | ||
package features; | ||
|
||
import com.smartcodeltd.jenkinsci.plugins.build_monitor.questions.ProjectWidget; | ||
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.HaveABuildMonitorViewCreated; | ||
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.ModifyControlPanelOptions; | ||
import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.ShowBadges; | ||
import environment.JenkinsSandbox; | ||
import net.serenitybdd.integration.jenkins.JenkinsInstance; | ||
import net.serenitybdd.integration.jenkins.environment.rules.InstallPlugins; | ||
import net.serenitybdd.junit.runners.SerenityRunner; | ||
import net.serenitybdd.screenplay.Actor; | ||
import net.serenitybdd.screenplay.abilities.BrowseTheWeb; | ||
import net.serenitybdd.screenplay.jenkins.HaveAProjectCreated; | ||
import net.serenitybdd.screenplay.jenkins.tasks.ScheduleABuild; | ||
import net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps.AddAGroovyPostbuildScript; | ||
import net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps.ExecuteAShellScript; | ||
import net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps.GroovyScriptThat; | ||
import net.serenitybdd.screenplayx.actions.Navigate; | ||
import net.thucydides.core.annotations.Managed; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
import static net.serenitybdd.screenplay.GivenWhenThen.*; | ||
import static net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps.ShellScriptThat.Finishes_With_Success; | ||
import static net.serenitybdd.screenplay.matchers.WebElementStateMatchers.isCurrentlyVisible; | ||
|
||
@RunWith(SerenityRunner.class) | ||
public class ShouldDisplayBadges { | ||
|
||
Actor paul = Actor.named("Paul"); | ||
|
||
@Managed public WebDriver hisBrowser; | ||
|
||
@Rule public JenkinsInstance jenkins = JenkinsSandbox.configure().afterStart( | ||
InstallPlugins.fromUpdateCenter("buildtriggerbadge", "groovy-postbuild") | ||
).create(); | ||
|
||
@Before | ||
public void actorCanBrowseTheWeb() { | ||
paul.can(BrowseTheWeb.with(hisBrowser)); | ||
} | ||
|
||
@Test | ||
public void displaying_build_badges() throws Exception { | ||
givenThat(paul).wasAbleTo( | ||
Navigate.to(jenkins.url()), | ||
HaveAProjectCreated.called("My App").andConfiguredTo( | ||
ExecuteAShellScript.that(Finishes_With_Success), | ||
AddAGroovyPostbuildScript.that(GroovyScriptThat.Adds_A_Badge) | ||
), | ||
ScheduleABuild.of("My App"), | ||
HaveABuildMonitorViewCreated.showingAllTheProjects() | ||
); | ||
|
||
when(paul).attemptsTo(ModifyControlPanelOptions.to(ShowBadges.onTheDashboard())); | ||
|
||
then(paul).should(seeThat(ProjectWidget.of("My App").badges(), | ||
isCurrentlyVisible() | ||
)); | ||
} | ||
} |
This file contains 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 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 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 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 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.