Class RoundTripAbstractTest

java.lang.Object
io.jenkins.plugins.casc.misc.RoundTripAbstractTest

public abstract class RoundTripAbstractTest extends Object
Base test to check a complete test of each plugin configuration. What it makes: 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. 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.
Since:
1.20
  • Field Details

    • r

      public org.jvnet.hudson.test.RestartableJenkinsRule r
    • tempFolder

      public org.junit.rules.TemporaryFolder tempFolder
    • logging

      public org.jvnet.hudson.test.LoggerRule logging
  • Constructor Details

    • RoundTripAbstractTest

      public RoundTripAbstractTest()
  • Method Details

    • assertConfiguredAsExpected

      protected abstract void assertConfiguredAsExpected(org.jvnet.hudson.test.RestartableJenkinsRule 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 RestartableJenkinsRule 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

      public void roundTripTest() throws IOException
      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.