Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed May 16, 2019
1 parent 5027aa6 commit 36e6435
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.sonyericsson.jenkins.plugins.jcasc;

import com.sonyericsson.jenkins.plugins.bfa.PluginImpl;
import com.sonyericsson.jenkins.plugins.bfa.sod.ScanOnDemandVariables;
import io.jenkins.plugins.casc.ConfigurationContext;
import io.jenkins.plugins.casc.ConfiguratorRegistry;
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
import io.jenkins.plugins.casc.model.CNode;
import org.junit.ClassRule;
import org.junit.Test;

import static io.jenkins.plugins.casc.misc.Util.getUnclassifiedRoot;
import static io.jenkins.plugins.casc.misc.Util.toStringFromYamlFile;
import static io.jenkins.plugins.casc.misc.Util.toYamlString;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class ConfigurationAsCodeLocalTest {

private static final String NO_CAUSES_MESSAGE = "No problems were identified. If you know why this problem " +
"occurred, please add a suitable Cause for it.";

@ClassRule
@ConfiguredWithCode("jcasc-local.yml")
public static JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule();

@Test
public void should_support_configuration_as_code() {
PluginImpl plugin = PluginImpl.getInstance();

assertThat(plugin.isDoNotAnalyzeAbortedJob(), is(true));
assertThat(plugin.isGerritTriggerEnabled(), is(true));
assertThat(plugin.isGlobalEnabled(), is(true));
assertThat(plugin.isGraphsEnabled(), is(false));
assertThat(plugin.getKnowledgeBase(), is("localFile"));
assertThat(plugin.getNoCausesMessage(), is(NO_CAUSES_MESSAGE));

assertThat(plugin.getNrOfScanThreads(), is(6));
ScanOnDemandVariables sodVariables = plugin.getSodVariables();
assertThat(sodVariables.getMaximumSodWorkerThreads(), is(4));
assertThat(sodVariables.getMinimumSodWorkerThreads(), is(2));
assertThat(sodVariables.getSodCorePoolNumberOfThreads(), is(6));
assertThat(sodVariables.getSodThreadKeepAliveTime(), is(17));
assertThat(sodVariables.getSodWaitForJobShutdownTimeout(), is(32));

assertThat(plugin.getTestResultCategories(), is("hgjghhlllllaa"));
assertThat(plugin.isTestResultParsingEnabled(), is(true));
}

@Test
public void should_support_configuration_export() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode yourAttribute = getUnclassifiedRoot(context).get("buildFailureAnalyzer");

String exported = toYamlString(yourAttribute);

String expected = toStringFromYamlFile(this, "expected_output.yaml");

assertThat(exported, is(expected));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
buildFailureAnalyzer:
doNotAnalyzeAbortedJob: true
gerritTriggerEnabled: true
globalEnabled: true
graphsEnabled: false
knowledgeBase: "localFile"
maxLogSize: 10
noCausesMessage: "No problems were identified. If you know why this problem occurred,\
\ please add a suitable Cause for it."
nrOfScanThreads: 6
sodVariables:
maximumSodWorkerThreads: 4
minimumSodWorkerThreads: 2
sodCorePoolNumberOfThreads: 6
sodThreadKeepAliveTime: 17
sodWaitForJobShutdownTimeout: 32
testResultCategories: "hgjghhlllllaa"
testResultParsingEnabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
unclassified:
buildFailureAnalyzer:
doNotAnalyzeAbortedJob: true
gerritTriggerEnabled: true
globalEnabled: true
graphsEnabled: false
knowledgeBase: "localFile"
maxLogSize: 10
noCausesMessage: "No problems were identified. If you know why this problem occurred,\
\ please add a suitable Cause for it."
nrOfScanThreads: 6
sodVariables:
maximumSodWorkerThreads: 4
minimumSodWorkerThreads: 2
sodCorePoolNumberOfThreads: 6
sodThreadKeepAliveTime: 17
sodWaitForJobShutdownTimeout: 32
testResultCategories: "hgjghhlllllaa"
testResultParsingEnabled: true

0 comments on commit 36e6435

Please sign in to comment.