Skip to content

Commit

Permalink
Merge pull request #136 from abayer/jenkins-34464
Browse files Browse the repository at this point in the history
[JENKINS-34464] Bump structs version, add test for result roundtrip
  • Loading branch information
abayer committed May 25, 2017
2 parents 21e1ef1 + 0adc311 commit 448fe7a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -103,7 +103,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.6</version>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -29,6 +29,7 @@
import hudson.model.BooleanParameterValue;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.StringParameterDefinition;
import hudson.model.StringParameterValue;
import hudson.tasks.ArtifactArchiver;
Expand All @@ -45,6 +46,7 @@
import org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStep;
import org.jenkinsci.plugins.workflow.support.steps.input.InputStep;
import org.jenkinsci.plugins.workflow.testMetaStep.Colorado;
import org.jenkinsci.plugins.workflow.testMetaStep.EchoResultStep;
import org.jenkinsci.plugins.workflow.testMetaStep.Hawaii;
import org.jenkinsci.plugins.workflow.testMetaStep.Island;
import org.jenkinsci.plugins.workflow.testMetaStep.MonomorphicData;
Expand Down Expand Up @@ -307,6 +309,12 @@ public void monomorphicListSymbol() throws Exception {
st.assertRoundTrip(monomorphicStep, "monomorphListSymbolStep([monomorphSymbol(firstArg: 'one', secondArg: 'two'), monomorphSymbol(firstArg: 'three', secondArg: 'four')])");
}

@Issue("JENKINS-34464")
@Test
public void resultRoundTrips() throws Exception {
st.assertRoundTrip(new EchoResultStep(Result.UNSTABLE), "echoResult 'UNSTABLE'");
}

@Test
public void noArgStepDocs() throws Exception {
SnippetizerTester.assertDocGeneration(PwdStep.class);
Expand Down
@@ -0,0 +1,72 @@
package org.jenkinsci.plugins.workflow.testMetaStep;

import hudson.Extension;
import hudson.model.Result;
import hudson.model.TaskListener;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.Set;

public class EchoResultStep extends Step implements Serializable {

private Result result;

@DataBoundConstructor
public EchoResultStep(Result result) {
this.result = result;
}

public Result getResult() {
return result;
}

@Override
public StepExecution start(StepContext context) throws Exception {
return new EchoResultStepExecution(this, context);
}

@Extension
public static final class DescriptorImpl extends StepDescriptor {
@Override
public String getFunctionName() {
return "echoResult";
}

@Override
public Set<? extends Class<?>> getRequiredContext() {
return Collections.singleton(TaskListener.class);
}
}

public static class EchoResultStepExecution extends StepExecution {
private final EchoResultStep step;

public EchoResultStepExecution(EchoResultStep s, StepContext context) {
super(context);
this.step = s;
}

@Override
public boolean start() throws Exception {
TaskListener listener = getContext().get(TaskListener.class);

if (listener != null)
listener.getLogger().println("Result is " + step.getResult());

return true;
}

@Override
public void stop(Throwable cause) throws Exception {
}
}

private static final long serialVersionUID = 1L;

}

0 comments on commit 448fe7a

Please sign in to comment.