Skip to content

Commit

Permalink
Merge pull request #28 from abayer/jenkins-37477
Browse files Browse the repository at this point in the history
Test for JENKINS-37477
  • Loading branch information
abayer committed Aug 28, 2016
2 parents 80120a5 + 4d8bf28 commit 42c3b10
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -69,7 +69,7 @@ THE SOFTWARE.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-job</artifactId>
<version>2.4</version>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -188,7 +188,7 @@ THE SOFTWARE.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>workflow-job</artifactId>
<version>2.4</version>
<version>2.6</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
Expand Up @@ -201,5 +201,4 @@ public Collection<? extends Descriptor<?>> getPropertyDescriptors() {
}

}

}
Expand Up @@ -36,6 +36,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import hudson.triggers.TimerTrigger;
import hudson.triggers.Trigger;
Expand All @@ -51,22 +52,31 @@
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.structs.describable.ArrayType;
import org.jenkinsci.plugins.structs.describable.DescribableModel;
import org.jenkinsci.plugins.structs.describable.DescribableParameter;
import org.jenkinsci.plugins.structs.describable.ErrorType;
import org.jenkinsci.plugins.structs.describable.HeterogeneousObjectType;
import org.jenkinsci.plugins.structs.describable.HomogeneousObjectType;
import org.jenkinsci.plugins.structs.describable.ParameterType;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.SnippetizerTester;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty;
import org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty;
import org.jenkinsci.plugins.workflow.properties.MockTrigger;
import org.jenkinsci.plugins.workflow.job.properties.MockTrigger;
import org.jenkinsci.plugins.workflow.steps.StepConfigTester;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import static org.junit.Assert.*;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.kohsuke.stapler.NoStaplerConstructorException;

import static org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject;

Expand Down Expand Up @@ -298,6 +308,70 @@ public class JobPropertyStepTest {
assertEquals("[null, false, null]", MockTrigger.startsAndStops.toString());
}

@Issue("JENKINS-37477")
@Test
public void generateHelpTrigger() throws Exception {
DescribableModel<?> model = new DescribableModel(PipelineTriggersJobProperty.class);

assertNotNull(model);

recurseOnModel(model);
}

/**
* TODO: Move to workflow-cps test classes somewhere.
*/
private void recurseOnTypes(ParameterType type) throws Exception {
// For the moment, only care about types with @DataBoundConstructors.
if (type instanceof ErrorType && !(((ErrorType)type).getError() instanceof NoStaplerConstructorException)) {
throw ((ErrorType)type).getError();
}

if (type instanceof ArrayType) {
recurseOnTypes(((ArrayType)type).getElementType());
} else if (type instanceof HomogeneousObjectType) {
recurseOnModel(((HomogeneousObjectType) type).getSchemaType());
} else if (type instanceof HeterogeneousObjectType) {
for (Map.Entry<String, DescribableModel<?>> entry : ((HeterogeneousObjectType) type).getTypes().entrySet()) {
recurseOnModel(entry.getValue());
}
}
}

/**
* TODO: Move to workflow-cps test classes somewhere.
*/
private void recurseOnModel(DescribableModel<?> model) throws Exception {
for (DescribableParameter param : model.getParameters()) {
recurseOnTypes(param.getType());
}
}


@Issue("JENKINS-37477")
@Test
public void configRoundTripTrigger() throws Exception {
List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new TimerTrigger("@daily"))));
String snippetJson = "{'propertiesMap': {\n" +
" 'stapler-class-bag': 'true',\n" +
" 'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'triggers': {\n" +
" 'stapler-class-bag': 'true',\n" +
" 'hudson-triggers-TimerTrigger': {'spec': '@daily'}\n" +
" }}},\n" +
" 'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" +
" '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}";

if (TimerTrigger.DescriptorImpl.class.isAnnotationPresent(Symbol.class)) {
new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties [pipelineTriggers([cron('@daily')])]", null);
// TODO: JENKINS-29711 like other roundtrip tests here.
//new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties [pipelineTriggers([cron('@daily')])]");
} else {
new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties [pipelineTriggers([[$class: 'TimerTrigger', spec: '@daily']])]", null);
// TODO: JENKINS-29711 like other roundtrip tests here.
//new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties [pipelineTriggers([[$class: 'TimerTrigger', spec: '@daily']])]");
}
}

@Issue("JENKINS-37005")
@Test
public void noPropertiesWarnings() throws Exception {
Expand Down

0 comments on commit 42c3b10

Please sign in to comment.