public class Util extends Object
| Constructor and Description |
|---|
Util() |
| Modifier and Type | Method and Description |
|---|---|
static void |
assertLogContains(org.jvnet.hudson.test.LoggerRule logging,
String expectedText)
Checks whether
LoggerRule has recorded the message. |
static void |
assertNotInLog(org.jvnet.hudson.test.LoggerRule logging,
String unexpectedText)
Checks whether
LoggerRule has not recorded the message. |
static String |
convertToJson(String yamlString)
Converts a given yamlString into a JsonString.
|
static org.json.JSONObject |
convertYamlFileToJson(Object clazz,
String yamlFileName)
Converts a YAML file into a json object
|
static io.jenkins.plugins.casc.core.JenkinsConfigurator |
getJenkinsConfigurator()
Gets the Jenkins configurator.
|
static io.jenkins.plugins.casc.model.Mapping |
getJenkinsRoot(io.jenkins.plugins.casc.ConfigurationContext context)
Gets the "jenkins" root mapping.
|
static io.jenkins.plugins.casc.model.Mapping |
getSecurityRoot(io.jenkins.plugins.casc.ConfigurationContext context)
Gets the "security" root mapping.
|
static io.jenkins.plugins.casc.model.Mapping |
getToolRoot(io.jenkins.plugins.casc.ConfigurationContext context)
Gets the "tool" root mapping.
|
static io.jenkins.plugins.casc.model.Mapping |
getUnclassifiedRoot(io.jenkins.plugins.casc.ConfigurationContext context)
Gets the "unclassified" root mapping.
|
static org.everit.json.schema.Schema |
returnSchema()
Retrieves the JSON schema for the running jenkins instance.
|
static String |
toStringFromYamlFile(Object clazz,
String resourcePath)
Reads a resource from the classpath to use in asserting expected export content.
|
static String |
toYamlString(io.jenkins.plugins.casc.model.CNode rootNode)
Converts a given
CNode into a string. |
static List<String> |
validateSchema(org.json.JSONObject jsonSubject)
Validates a given jsonObject against the schema generated for the current live jenkins
instance.
|
public static io.jenkins.plugins.casc.core.JenkinsConfigurator getJenkinsConfigurator()
public static io.jenkins.plugins.casc.model.Mapping getJenkinsRoot(io.jenkins.plugins.casc.ConfigurationContext context)
throws Exception
Example usage:
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode configNode = getJenkinsRoot(context).get("nodes");context - the configuration contextException - something's not right...public static io.jenkins.plugins.casc.model.Mapping getUnclassifiedRoot(io.jenkins.plugins.casc.ConfigurationContext context)
throws Exception
Example usage:
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode configNode = getUnclassifiedRoot(context).get("my-plugin-attribute");context - the configuration contextException - something's not right...public static io.jenkins.plugins.casc.model.Mapping getSecurityRoot(io.jenkins.plugins.casc.ConfigurationContext context)
throws Exception
Example usage:
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode configNode = getSecurityRoot(context).get("GlobalJobDslSecurityConfiguration");context - the configuration contextException - something's not right...public static io.jenkins.plugins.casc.model.Mapping getToolRoot(io.jenkins.plugins.casc.ConfigurationContext context)
throws Exception
Example usage:
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode configNode = getToolRoot(context).get("git");context - the configuration contextException - something's not right...public static String toYamlString(io.jenkins.plugins.casc.model.CNode rootNode) throws IOException
CNode into a string.
Example usage:
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode yourAttribute = getUnclassifiedRoot(context).get("<your-attribute>");
String exported = toYamlString(yourAttribute);rootNode - the CNode to convert to a stringIOException - if exporting to YAML failspublic static String toStringFromYamlFile(Object clazz, String resourcePath) throws URISyntaxException
The resource is expected to be UTF-8 encoded.
Example usage:
toStringFromYamlFile(this, "expected-output.yml");clazz - pass in thisresourcePath - the file name to read, should be in the same package as your test class in resourcesURISyntaxException - if an invalid URI is passed.public static void assertNotInLog(org.jvnet.hudson.test.LoggerRule logging,
String unexpectedText)
LoggerRule has not recorded the message.logging - Logger ruleunexpectedText - Text to checkpublic static void assertLogContains(org.jvnet.hudson.test.LoggerRule logging,
String expectedText)
LoggerRule has recorded the message.logging - Logger ruleexpectedText - Text to checkpublic static String convertToJson(String yamlString)
Converts a given yamlString into a JsonString.
Example Usage:
String jsonString = convertToJson(yourYamlString);
yamlString - the yaml to convertpublic static org.everit.json.schema.Schema returnSchema()
Example Usage:
Schema jsonSchema = returnSchema();
public static List<String> validateSchema(org.json.JSONObject jsonSubject)
Example Usage:
assertThat(validateSchema(convertYamlFileToJson(this, "invalidSchemaConfig.yml")),
contains("#/jenkins/numExecutors: expected type: Number, found: String"));
assertThat(validateSchema(convertYamlFileToJson(this, "validConfig.yml")),
empty());
jsonSubject - the json object that needs to be validatedpublic static org.json.JSONObject convertYamlFileToJson(Object clazz, String yamlFileName) throws URISyntaxException
Example Usage:
JSONObject jsonObject = convertYamlFileToJson(this, "filename");
clazz - the class used for loading resources, normally you want to pass 'this'yamlFileName - the name of the yaml file that needs to be convertedURISyntaxException - if an invalid URI is passed.Copyright © 2016–2021. All rights reserved.