package org.jenkinsci.plugins.mktmpio;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyString;

public class MktmpioDescriptorTest {
    @Rule
    public final JenkinsRule j = new JenkinsRule().withNewHome();

    @Test
    public void testDefaults() throws Exception {
        MktmpioDescriptor config = getDescriptor();
        config.setToken("");
        config.setServer("");
        assertThat(config.getToken(), isEmptyString());
        assertThat(config.getServer(), is(Mktmpio.DEFAULT_SERVER));
        config.setToken("something");
        assertThat(config.getToken(), is("something"));
        config.setServer("something-else");
        assertThat(config.getServer(), is("something-else"));
    }

    private MktmpioDescriptor getDescriptor() {
        return (MktmpioDescriptor) j.jenkins.getDescriptor(Mktmpio.class);
    }
}

@@ -33,16 +33,54 @@
 tmpio;%0A%0A
+import hudson.model.FreeStyleProject;%0A
 import o
@@ -88,16 +88,21 @@
 g.junit.
+Class
 Rule;%0Aim
@@ -352,16 +352,21 @@
  %7B%0A    @
+Class
 Rule%0A   
@@ -373,16 +373,23 @@
  public 
+static 
 final Je
@@ -504,16 +504,22 @@
         
+final 
 MktmpioD
@@ -871,24 +871,24 @@
 ing-else%22);%0A
-
         asse
@@ -944,16 +944,759 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testGlobalConfigRoundTrip() throws Exception %7B%0A        final MktmpioDescriptor config = getDescriptor();%0A        final String server = config.getServer();%0A        final String token = config.getToken();%0A        j.configRoundtrip();%0A        assertThat(config.getServer(), is(server));%0A        assertThat(config.getToken(), is(token));%0A    %7D%0A%0A    @Test%0A    public void testJobConfigRoundTrip() throws Exception %7B%0A        FreeStyleProject p = j.createFreeStyleProject();%0A        Mktmpio before = new Mktmpio(%22redis%22);%0A        p.getBuildWrappersList().add(before);%0A        j.configRoundtrip(p);%0A        Mktmpio after = p.getBuildWrappersList().get(Mktmpio.class);%0A        j.assertEqualBeans(before, after, %22dbs%22);%0A    %7D%0A%0A
     priv

add basic config round trip tests