Skip to content

Commit

Permalink
Add mongo db test
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed May 19, 2019
1 parent da45f8b commit f05fd6a
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.sonyericsson.jenkins.plugins.bfa.jcasc;

import com.sonyericsson.jenkins.plugins.bfa.PluginImpl;
import com.sonyericsson.jenkins.plugins.bfa.db.KnowledgeBase;
import com.sonyericsson.jenkins.plugins.bfa.db.LocalFileKnowledgeBase;
import com.sonyericsson.jenkins.plugins.bfa.db.MongoDBKnowledgeBase;
import com.sonyericsson.jenkins.plugins.bfa.sod.ScanOnDemandVariables;
import hudson.util.Secret;
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.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertThat;

public class ConfigurationAsCodeMongoTest {

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-mongo.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));

MongoDBKnowledgeBase knowledgeBase = (MongoDBKnowledgeBase) plugin.getKnowledgeBase();
assertThat(knowledgeBase.getHost(), is("localhost"));
assertThat(knowledgeBase.getDbName(), is("bfa"));
assertThat(knowledgeBase.isStatisticsEnabled(), is(true));
assertThat(knowledgeBase.getUserName(), is("bfa"));
assertThat(knowledgeBase.getPassword().getPlainText(), is("changeme"));
assertThat(knowledgeBase.isSuccessfulLoggingEnabled(), is(false));

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)
.replaceAll(".+password: .+", ""); // ignore dynamic password secret

String expected = toStringFromYamlFile(this, "jcasc-mongo-expected.yml");

assertThat(exported, is(expected));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
doNotAnalyzeAbortedJob: true
gerritTriggerEnabled: true
globalEnabled: true
graphsEnabled: false
knowledgeBase:
mongoDB:
dbName: "bfa"
enableStatistics: true
host: "localhost"

port: 27017
successfulLogging: false
userName: bfa
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,29 @@
unclassified:
buildFailureAnalyzer:
doNotAnalyzeAbortedJob: true
gerritTriggerEnabled: true
globalEnabled: true
graphsEnabled: false
knowledgeBase:
mongoDB:
dbName: "bfa"
enableStatistics: true
host: "localhost"
userName: bfa
password: changeme
port: 27017
successfulLogging: false
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 f05fd6a

Please sign in to comment.