-
Notifications
You must be signed in to change notification settings - Fork 413
/
ConfigurationAsCodeTest.java
45 lines (35 loc) · 1.74 KB
/
ConfigurationAsCodeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package jenkins.plugins.slack.jcasc;
import hudson.ExtensionList;
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 jenkins.plugins.slack.SlackNotifier;
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 ConfigurationAsCodeTest {
@ClassRule
@ConfiguredWithCode("configuration-as-code.yml")
public static JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule();
@Test
public void should_support_configuration_as_code() {
SlackNotifier.DescriptorImpl slackNotifier = ExtensionList.lookupSingleton(SlackNotifier.DescriptorImpl.class);
assertThat(slackNotifier.getTeamDomain(), is("jenkins-slack-plugin"));
assertThat(slackNotifier.getTokenCredentialId(), is("slack-token"));
}
@Test
public void should_support_configuration_export() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode yourAttribute = getUnclassifiedRoot(context).get("slackNotifier");
String exported = toYamlString(yourAttribute);
String expected = toStringFromYamlFile(this, "configuration-as-code-expected.yml");
assertThat(exported, is(expected));
}
}