Search in sources :

Example 1 with BadgeAction

use of com.jenkinsci.plugins.badge.action.BadgeAction in project badge-plugin by jenkinsci.

the class AddBadgeStepTest method addBadge.

private void addBadge(boolean inNode) throws Exception {
    String icon = UUID.randomUUID().toString();
    String text = UUID.randomUUID().toString();
    String link = UUID.randomUUID().toString();
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    String script = "addBadge(icon:\"" + icon + "\",  text:\"" + text + "\",  link:\"" + link + "\")";
    if (inNode) {
        script = "node() {" + script + "}";
    }
    p.setDefinition(new CpsFlowDefinition(script, true));
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    List<BuildBadgeAction> badgeActions = b.getBadgeActions();
    assertEquals(1, badgeActions.size());
    BadgeAction action = (BadgeAction) badgeActions.get(0);
    assertTrue(action.getIconPath().endsWith(icon));
    assertEquals(text, action.getText());
    assertEquals(link, action.getLink());
}
Also used : BuildBadgeAction(hudson.model.BuildBadgeAction) BadgeAction(com.jenkinsci.plugins.badge.action.BadgeAction) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BuildBadgeAction(hudson.model.BuildBadgeAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 2 with BadgeAction

use of com.jenkinsci.plugins.badge.action.BadgeAction in project badge-plugin by jenkinsci.

the class AddBadgeStepTest method addStatusBadge.

private void addStatusBadge(String functionName, String expectedIcon) throws Exception {
    String text = UUID.randomUUID().toString();
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition(functionName + "(\"" + text + "\")", true));
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    List<BuildBadgeAction> badgeActions = b.getBadgeActions();
    assertEquals(1, badgeActions.size());
    BadgeAction action = (BadgeAction) badgeActions.get(0);
    assertEquals(text, action.getText());
    assertTrue(action.getIconPath().endsWith(expectedIcon));
}
Also used : BuildBadgeAction(hudson.model.BuildBadgeAction) BadgeAction(com.jenkinsci.plugins.badge.action.BadgeAction) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BuildBadgeAction(hudson.model.BuildBadgeAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Example 3 with BadgeAction

use of com.jenkinsci.plugins.badge.action.BadgeAction in project badge-plugin by jenkinsci.

the class ShortTextStepTest method addShortText.

@Test
public void addShortText() throws Exception {
    String text = UUID.randomUUID().toString();
    String color = UUID.randomUUID().toString();
    String background = UUID.randomUUID().toString();
    Integer border = new Random().nextInt();
    String borderColor = UUID.randomUUID().toString();
    String link = UUID.randomUUID().toString();
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("addShortText(text:\"" + text + "\",color:\"" + color + "\", background:\"" + background + "\", border:" + border + ", borderColor:\"" + borderColor + "\", link:\"" + link + "\")", true));
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    List<? extends Action> allActions = b.getAllActions();
    List<BuildBadgeAction> badgeActions = b.getBadgeActions();
    assertEquals(1, badgeActions.size());
    BadgeAction action = (BadgeAction) badgeActions.get(0);
    assertEquals(text, action.getText());
    assertEquals(color, action.getColor());
    assertEquals(background, action.getBackground());
    assertEquals(borderColor, action.getBorderColor());
    assertEquals(border + "px", action.getBorder());
    assertNull(action.getIconPath());
    assertEquals(link, action.getLink());
}
Also used : BuildBadgeAction(hudson.model.BuildBadgeAction) BadgeAction(com.jenkinsci.plugins.badge.action.BadgeAction) Random(java.util.Random) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BuildBadgeAction(hudson.model.BuildBadgeAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 4 with BadgeAction

use of com.jenkinsci.plugins.badge.action.BadgeAction in project badge-plugin by jenkinsci.

the class ShortTextStepTest method addShortText_minimal.

@Test
public void addShortText_minimal() throws Exception {
    String text = UUID.randomUUID().toString();
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition("addShortText(text:\"" + text + "\")", true));
    WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    List<BuildBadgeAction> badgeActions = b.getBadgeActions();
    assertEquals(1, badgeActions.size());
    BadgeAction action = (BadgeAction) badgeActions.get(0);
    assertEquals(text, action.getText());
    assertNull(action.getColor());
    assertNull(action.getBackground());
    assertNull(action.getBorderColor());
    assertNull(action.getBorder());
    assertNull(action.getIconPath());
    assertNull(action.getLink());
}
Also used : BuildBadgeAction(hudson.model.BuildBadgeAction) BadgeAction(com.jenkinsci.plugins.badge.action.BadgeAction) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BuildBadgeAction(hudson.model.BuildBadgeAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Aggregations

BadgeAction (com.jenkinsci.plugins.badge.action.BadgeAction)4 BuildBadgeAction (hudson.model.BuildBadgeAction)4 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)4 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)4 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 Test (org.junit.Test)2 Random (java.util.Random)1