Class AbstractRoundTripTest

java.lang.Object
io.jenkins.plugins.casc.misc.junit.jupiter.AbstractRoundTripTest

@WithJenkins public abstract class AbstractRoundTripTest extends Object
Base test to check a complete test of each plugin configuration.

What it does:

  1. Configure the instance with the configResource() implemented.
  2. Check it was configured correctly.
  3. Check the configuration is valid via Web UI.
  4. Apply the configuration via Web UI.
  5. Write the configuration to $JENKINS_HOME/jenkins.yaml.
  6. Restart Jenkins.
  7. Check the stringInLogExpected() is set during the restart.
  8. Check it is still configured correctly after the restart

All the plugin author needs to do is override the methods providing:

  1. The resource with the yaml configuration of the plugin in case they use their own name for the file.
  2. A way to validate the configuration is established.
  3. A string that should be present in the logs (casc logger) that guarantees the config is loaded. Usually a weird text configured.

This is the JUnit5 equivalent of RoundTripAbstractTest

See Also:
  • Field Details

    • tempFolder

      @TempDir public Path tempFolder
  • Constructor Details

    • AbstractRoundTripTest

      public AbstractRoundTripTest()
  • Method Details

    • assertConfiguredAsExpected

      protected abstract void assertConfiguredAsExpected(org.jvnet.hudson.test.JenkinsRule j, String configContent)
      A method to assert if the configuration was correctly loaded. The Jenkins rule and the content of the config supposedly loaded are passed.
      Parameters:
      j - a JenkinsRule instance.
      configContent - expected configuration.
    • configResource

      protected String configResource()
      Return the resource path (yaml file) to be loaded. i.e: If the resource is in the same package of the implementor class, then: my-config.yaml
      Returns:
      the resource name and path.
    • stringInLogExpected

      protected abstract String stringInLogExpected()
      Return the string that should be in the logs of the JCasC logger to verify it's configured after a restart. This string should be unique to avoid interpreting that it was configured successfully, but it wasn't.
      Returns:
      the unique string to be in the logs to certify the configuration was done successfully.
    • roundTripTest

      @Test public void roundTripTest(org.jvnet.hudson.test.JenkinsRule r) throws Throwable
      1. Configure the instance with the configResource() implemented. 2. Check it was configured correctly. 3. Check the configuration is valid via Web UI. 4. Apply the configuration via Web UI. 5. Write the configuration to $JENKINS_HOME/jenkins.yaml. 6. Restart Jenkins. 7. Check the stringInLogExpected() is set during the restart.
      Throws:
      IOException - If an exception is thrown managing resources or files.
      Throwable