Skip to content
Permalink
Browse files

[JENKINS-42505] Add config removal to test. Also improve update test …

…case.
  • Loading branch information...
varyvol committed Mar 6, 2017
1 parent 885bc1c commit d5effee99f041b84aae07fecf7d00056744ed9a2
Showing with 22 additions and 9 deletions.
  1. +22 −9 src/test/java/org/jenkinsci/plugins/configfiles/ConfigFileStoreTest.java
@@ -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());
@@ -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.is((Config) anotherConfig));
Assert.assertNull(store.getById(savedConfig.id));

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

}

0 comments on commit d5effee

Please sign in to comment.
You can’t perform that action at this time.