Skip to content

Commit

Permalink
Merge pull request #34 from varyvol/JENKINS-42505
Browse files Browse the repository at this point in the history
[JENKINS-42505] Improve test for config update/removal
  • Loading branch information
imod committed Mar 14, 2017
2 parents 9e8f0a4 + a04d4f9 commit dbda755
Showing 1 changed file with 22 additions and 9 deletions.
@@ -1,31 +1,29 @@
package org.jenkinsci.plugins.configfiles;

import com.cloudbees.hudson.plugins.folder.Folder;
import org.hamcrest.Matchers;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.custom.CustomConfig;
import org.jenkinsci.plugins.configfiles.folder.FolderConfigFileAction;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.IOException;

/**
* Created by domi on 18/01/17.
*/
public class ConfigFileStoreTest {

private static final String CONFIG_ID = "myid";

@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void testSaveGlobalConfigFiles() {

GlobalConfigFiles store = j.getInstance().getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
Assert.assertTrue(store.getConfigs().isEmpty());

CustomConfig config = new CustomConfig("myid", "name", "comment", "content");
CustomConfig config = new CustomConfig(CONFIG_ID, "name", "comment", "content");
store.save(config);

Assert.assertEquals(1, store.getConfigs().size());
Expand All @@ -34,14 +32,29 @@ public void testSaveGlobalConfigFiles() {
Assert.assertEquals("comment", savedConfig.comment);
Assert.assertEquals("content", savedConfig.content);

config = new CustomConfig("myid", "new name", "new comment", "new content");
CustomConfig anotherConfig = new CustomConfig("anotherid", "name", "comment", "content");
store.save(anotherConfig);

Assert.assertEquals(2, store.getConfigs().size());

// Update config. Check the correct config is updated with proper values
config = new CustomConfig(CONFIG_ID, "new name", "new comment", "new content");
store.save(config);

savedConfig = store.getConfigs().iterator().next();
Assert.assertEquals(1, store.getConfigs().size());
Assert.assertEquals(2, store.getConfigs().size());
savedConfig = store.getById(CONFIG_ID);
Assert.assertEquals("new name", savedConfig.name);
Assert.assertEquals("new comment", savedConfig.comment);
Assert.assertEquals("new content", savedConfig.content);

// Remove config. Check the correct one is removed
store.remove(savedConfig.id);
Assert.assertEquals(1, store.getConfigs().size());
Assert.assertThat(store.getById(anotherConfig.id), Matchers.<Config>is(anotherConfig));
Assert.assertNull(store.getById(savedConfig.id));

store.remove(anotherConfig.id);
Assert.assertEquals(0, store.getConfigs().size());
}

}

0 comments on commit dbda755

Please sign in to comment.