Codota Logo
SnippetizerTester
Code IndexAdd Codota to your IDE (free)

How to use
SnippetizerTester
in
org.jenkinsci.plugins.workflow.cps

Best Java code snippets using org.jenkinsci.plugins.workflow.cps.SnippetizerTester (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
LocalDateTime l =
  • Codota Iconnew LocalDateTime()
  • Codota IconLocalDateTime.now()
  • Codota IconDateTimeFormatter formatter;String text;formatter.parseLocalDateTime(text)
  • Smart code suggestions by Codota
}
origin: jenkinsci/workflow-cps-plugin

@Test public void blockSteps() throws Exception {
  st.assertRoundTrip(new ExecutorStep(null), "node {\n    // some block\n}");
  st.assertRoundTrip(new ExecutorStep("linux"), "node('linux') {\n    // some block\n}");
  st.assertRoundTrip(new WorkspaceStep(null), "ws {\n    // some block\n}");
  st.assertRoundTrip(new WorkspaceStep("loc"), "ws('loc') {\n    // some block\n}");
}
origin: jenkinsci/workflow-multibranch-plugin

@Issue("JENKINS-37721")
@Test
public void configRoundTripSCMTrigger() throws Exception {
  List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new SCMTrigger("@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-SCMTrigger': {'scmpoll_spec': '@daily', 'ignorePostCommitHooks': false }\n" +
      "    }}},\n" +
      "  'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" +
      "  '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}";
  new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([pollSCM('@daily')])])", null);
  new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([pollSCM('@daily')])])");
}
origin: jenkinsci/workflow-cps-plugin

/**
 * An example of a step that will fail to generate docs correctly due to a lack of a {@link org.kohsuke.stapler.DataBoundConstructor}.
 */
@Test(expected = NoStaplerConstructorException.class)
public void parallelStepDocs() throws Exception {
  SnippetizerTester.assertDocGeneration(ParallelStep.class);
}
origin: jenkinsci/workflow-multibranch-plugin

@Issue("JENKINS-37219")
@Test
public void snippetGeneratorOverrideIndexing() throws Exception {
  String snippetJson = "{'propertiesMap':\n" +
      "{'stapler-class-bag': 'true', 'jenkins-branch-OverrideIndexTriggersJobProperty': \n" +
      "{'specified': true, 'enableTriggers': true}},\n" +
      "'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" +
      "'$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}";
  new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([overrideIndexTriggers(true)])", null);
}
origin: jenkinsci/junit-plugin

@Test
public void configRoundTrip() throws Exception {
  SnippetizerTester st = new SnippetizerTester(rule);
  JUnitResultsStep step = new JUnitResultsStep("**/target/surefire-reports/TEST-*.xml");
  st.assertRoundTrip(step, "junit '**/target/surefire-reports/TEST-*.xml'");
  step.setAllowEmptyResults(true);
  st.assertRoundTrip(step, "junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'");
  step.setHealthScaleFactor(2.0);
  st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testResults: '**/target/surefire-reports/TEST-*.xml'");
  MockTestDataPublisher publisher = new MockTestDataPublisher("testing");
  step.setTestDataPublishers(Collections.<TestDataPublisher>singletonList(publisher));
  st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'");
}
origin: jenkinsci/workflow-cps-plugin

@Test public void generateSnippet() throws Exception {
  st.assertGenerateSnippet("{'stapler-class':'" + EchoStep.class.getName() + "', 'message':'hello world'}", "echo 'hello world'", null);
  st.assertGenerateSnippet("{'stapler-class':'" + Circle.class.getName() + "'}", "circle {\n    // some block\n}", null);
  st.assertGenerateSnippet("{'stapler-class':'" + Polygon.class.getName() + "', 'n':5}", "polygon(5) {\n    // some block\n}", null);
  st.assertGenerateSnippet("{'stapler-class':'" + CarbonMonoxide.class.getName() + "'}", "detect CO()", null);
}
origin: jenkinsci/workflow-cps-plugin

private static void recurseOnTypes(DescribableModel<?> model, ParameterType type) throws Exception {
  if (type instanceof ErrorType) {
    throw new Exception("could not describe " + model, ((ErrorType) type).getError());
  }
  if (type instanceof ArrayType) {
    recurseOnTypes(model, ((ArrayType)type).getElementType());
  } else if (type instanceof HomogeneousObjectType) {
    recurseOnModel(((HomogeneousObjectType) type).getSchemaType());
  } else if (type instanceof HeterogeneousObjectType) {
    if (((HeterogeneousObjectType) type).getActualType() == Object.class) {
      // See html.groovy#describeType. For example, JENKINS-53917 ChoiceParameterDefinition.choices.
      System.err.println("Ignoring " + model.getType().getName() + " since a parameter is not enumerable");
      return;
    }
    for (Map.Entry<String, DescribableModel<?>> entry : ((HeterogeneousObjectType) type).getTypes().entrySet()) {
      recurseOnModel(entry.getValue());
    }
  }
}
origin: jenkinsci/workflow-cps-plugin

private static void recurseOnModel(DescribableModel<?> model) throws Exception {
  for (DescribableParameter param : model.getParameters()) {
    recurseOnTypes(model, param.getType());
  }
}
origin: jenkinsci/workflow-cps-plugin

/**
 * Recurses through the model of a {@link Describable} class's {@link DescribableModel} and its parameters to verify that doc generation will work.
 *
 * @param describableClass
 *     A {@link Class} implementing {@link Describable}
 * @throws Exception
 *     If any errors are encountered.
 */
@SuppressWarnings("unchecked")
public static void assertDocGeneration(Class<? extends Describable> describableClass) throws Exception {
  DescribableModel<?> model = DescribableModel.of(describableClass);
  assertNotNull(model);
  recurseOnModel(model);
}
origin: jenkinsci/workflow-multibranch-plugin

@Issue("JENKINS-26143")
@Test
public void testChoiceParameterSnippetizer() throws Exception {
  //new SnippetizerTester(r).assertGenerateSnippet();
  new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(Arrays.asList(new ParametersDefinitionProperty(new ChoiceParameterDefinition("paramName", new String[] { "foo", "bar", "baz" }, "")))),
    "properties([parameters([choice(choices: ['foo', 'bar', 'baz'], description: '', name: 'paramName')])])");
}
origin: jenkinsci/workflow-cps-plugin

@Test public void generateSnippetAdvancedDeprecated() throws Exception {
  st.assertGenerateSnippet("{'stapler-class':'" + CatchErrorStep.class.getName() + "'}", "// " + Messages.Snippetizer_this_step_should_not_normally_be_used_in() + "\ncatchError {\n    // some block\n}", null);
}
origin: jenkinsci/workflow-cps-plugin

@Test public void basics() throws Exception {
  st.assertRoundTrip(new EchoStep("hello world"), "echo 'hello world'");
  ReadFileStep s = new ReadFileStep("build.properties");
  st.assertRoundTrip(s, "readFile 'build.properties'");
  s.setEncoding("ISO-8859-1");
  st.assertRoundTrip(s, "readFile encoding: 'ISO-8859-1', file: 'build.properties'");
}
origin: jenkinsci/workflow-multibranch-plugin

@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'}";
  new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([cron('@daily')])])", null);
  new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([cron('@daily')])])");
}
origin: jenkinsci/workflow-multibranch-plugin

@SuppressWarnings("rawtypes")
@Test public void configRoundTripParameters() throws Exception {
  List<JobProperty> properties = Collections.<JobProperty>singletonList(new ParametersDefinitionProperty(new BooleanParameterDefinition("flag", true, null)));
  // TODO *ParameterDefinition.description ought to be defaulted to null:
  new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([parameters([booleanParam(defaultValue: true, name: 'flag')])])");
  StepConfigTester tester = new StepConfigTester(r);
  properties = tester.configRoundTrip(new JobPropertyStep(properties)).getProperties();
  assertEquals(1, properties.size());
  ParametersDefinitionProperty pdp = getPropertyFromList(ParametersDefinitionProperty.class, properties);
  assertNotNull(pdp);
  assertEquals(1, pdp.getParameterDefinitions().size());
  assertEquals(BooleanParameterDefinition.class, pdp.getParameterDefinitions().get(0).getClass());
  BooleanParameterDefinition bpd = (BooleanParameterDefinition) pdp.getParameterDefinitions().get(0);
  assertEquals("flag", bpd.getName());
  assertTrue(bpd.isDefaultValue());
  List<JobProperty> emptyInput = tester.configRoundTrip(new JobPropertyStep(Collections.<JobProperty>emptyList())).getProperties();
  assertEquals(Collections.emptyList(), removeTriggerProperty(emptyInput));
}
origin: jenkinsci/workflow-cps-plugin

@Test public void generateSnippetForBuildTriggerNone() throws Exception {
  FreeStyleProject ds = r.jenkins.createProject(FreeStyleProject.class, "ds0");
  FreeStyleProject us = r.jenkins.createProject(FreeStyleProject.class, "us0");
  st.assertGenerateSnippet("{'stapler-class':'" + BuildTriggerStep.class.getName() + "', 'job':'ds0'}", "build 'ds0'", us.getAbsoluteUrl() + "configure");
}
origin: jenkinsci/workflow-cps-plugin

@Test
public void singleArgStepDocs() throws Exception {
  SnippetizerTester.assertDocGeneration(EchoStep.class);
}
origin: jenkinsci/workflow-cps-plugin

@Test public void buildTriggerStep() throws Exception {
  BuildTriggerStep step = new BuildTriggerStep("downstream");
  st.assertRoundTrip(step, "build 'downstream'");
  step.setParameters(Arrays.asList(new StringParameterValue("branch", "default"), new BooleanParameterValue("correct", true)));
  if (StringParameterDefinition.DescriptorImpl.class.isAnnotationPresent(Symbol.class)) {
    st.assertRoundTrip(step, "build job: 'downstream', parameters: [string(name: 'branch', value: 'default'), booleanParam(name: 'correct', value: true)]");
  } else { // TODO 2.x delete
    st.assertRoundTrip(step, "build job: 'downstream', parameters: [[$class: 'StringParameterValue', name: 'branch', value: 'default'], [$class: 'BooleanParameterValue', name: 'correct', value: true]]");
  }
}
origin: jenkinsci/workflow-multibranch-plugin

@Issue("JENKINS-34464")
@Test
public void configRoundTripReverseBuildTrigger() throws Exception {
  List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new ReverseBuildTrigger("some-job", Result.UNSTABLE))));
  String snippetJson = "{'propertiesMap': {\n" +
      "    'stapler-class-bag': 'true',\n" +
      "    'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'triggers': {\n" +
      "      'stapler-class-bag': 'true',\n" +
      "      'jenkins-triggers-ReverseBuildTrigger': { 'threshold': 'UNSTABLE', 'upstreamProjects': 'some-job'}\n" +
      "    }}},\n" +
      "  'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" +
      "  '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}";
  new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([upstream(threshold: 'UNSTABLE', upstreamProjects: 'some-job')])])", null);
  new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([upstream(threshold: 'UNSTABLE', upstreamProjects: 'some-job')])])");
}
origin: jenkinsci/workflow-multibranch-plugin

@SuppressWarnings("rawtypes")
@Test public void configRoundTripBuildDiscarder() throws Exception {
  List<JobProperty> properties = Collections.<JobProperty>singletonList(new BuildDiscarderProperty(new LogRotator(1, 2, -1, 3)));
  // TODO structural form of LogRotator is awful; confusion between integer and string types, and failure to handle default values:
  new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '3', daysToKeepStr: '1', numToKeepStr: '2'))])");
  StepConfigTester tester = new StepConfigTester(r);
  properties = tester.configRoundTrip(new JobPropertyStep(properties)).getProperties();
  assertEquals(1, properties.size());
  BuildDiscarderProperty bdp = getPropertyFromList(BuildDiscarderProperty.class, properties);
  assertNotNull(bdp);
  BuildDiscarder strategy = bdp.getStrategy();
  assertNotNull(strategy);
  assertEquals(LogRotator.class, strategy.getClass());
  LogRotator lr = (LogRotator) strategy;
  assertEquals(1, lr.getDaysToKeep());
  assertEquals(2, lr.getNumToKeep());
  assertEquals(-1, lr.getArtifactDaysToKeep());
  assertEquals(3, lr.getArtifactNumToKeep());
}
origin: jenkinsci/workflow-cps-plugin

@Issue("JENKINS-29739")
@Test public void generateSnippetForBuildTriggerSingle() throws Exception {
  FreeStyleProject ds = r.jenkins.createProject(FreeStyleProject.class, "ds1");
  FreeStyleProject us = r.jenkins.createProject(FreeStyleProject.class, "us1");
  ds.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("key", "")));
  String snippet;
  if (StringParameterDefinition.DescriptorImpl.class.isAnnotationPresent(Symbol.class)) {
    snippet = "build job: 'ds1', parameters: [string(name: 'key', value: 'stuff')]";
  } else { // TODO 2.x delete
    snippet = "build job: 'ds1', parameters: [[$class: 'StringParameterValue', name: 'key', value: 'stuff']]";
  }
  st.assertGenerateSnippet("{'stapler-class':'" + BuildTriggerStep.class.getName() + "', 'job':'ds1', 'parameter': {'name':'key', 'value':'stuff'}}", snippet, us.getAbsoluteUrl() + "configure");
}
org.jenkinsci.plugins.workflow.cpsSnippetizerTester

Javadoc

Test harness to test Snippetizer.

Most used methods

  • assertRoundTrip
    Given a fully configured Step, make sure the output from the snippetizer matches the expected value.
  • <init>
    This helper requires JenkinsRule.
  • assertGenerateSnippet
    Tests a form submitting part of snippetizer.
  • assertDocGeneration
    Recurses through the model of a Describable class's DescribableModel and its parameters to verify th
  • recurseOnModel
  • recurseOnTypes

Popular in Java

  • Making http requests using okhttp
  • setRequestProperty (URLConnection)
  • runOnUiThread (Activity)
  • setContentView (Activity)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • PrintWriter (java.io)
    Prints formatted representations of objects to a text-output stream. This class implements all of th
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • BitSet (java.util)
    This class implements a vector of bits that grows as needed. Each component of the bit set has a boo
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now