Skip to content

Commit

Permalink
[JENKINS-49067] Use of @TestExtension instead of @extension
Browse files Browse the repository at this point in the history
  • Loading branch information
fcojfernandez committed Jan 23, 2018
1 parent 271e9cb commit c8924e0
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 107 deletions.

This file was deleted.

@@ -1,7 +1,11 @@
package org.jenkinsci.lib.configprovider;

import edu.umd.cs.findbugs.annotations.NonNull;
import jenkins.model.Jenkins;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.lib.configprovider.model.ContentType;
import org.jenkinsci.plugins.configfiles.GlobalConfigFiles;
import org.jenkinsci.plugins.configfiles.Messages;
import org.jenkinsci.plugins.configfiles.custom.CustomConfig;
import org.jenkinsci.plugins.configfiles.groovy.GroovyScript;
import org.jenkinsci.plugins.configfiles.json.JsonConfig;
Expand All @@ -11,7 +15,9 @@
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.jvnet.hudson.test.recipes.LocalData;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Created by domi on 17/09/16.
Expand Down Expand Up @@ -82,4 +88,78 @@ public void testDynamicCreationOfConfigs2() {
Assert.assertEquals(savedConfig.newParam3, ExtensionPointTestConfig.TEST_PARAM_VALUE);
Assert.assertNotNull(savedConfig.getProviderId());
}

public static class ExtensionPointTestConfig extends Config {
public static final String TEST_PARAM_VALUE = "DEFAULT_VALUE";
public static final String TEST_NAME_VALUE = "ExtensionPointTestConfig";
public static final String TEST_COMMENT_VALUE = "Test comment";
public static final String TEST_CONTENT_VALUE = "Test content";

private static final long serialVersionUID = 1L;

public String newParam1;
public String newParam2;
public String newParam3;

@DataBoundConstructor
public ExtensionPointTestConfig(String id, String name, String comment, String content) {
super(id, name, comment, content);
newParam1 = TEST_PARAM_VALUE;
newParam2 = TEST_PARAM_VALUE;
newParam3 = TEST_PARAM_VALUE;
}

public ExtensionPointTestConfig(String id, String name, String comment, String content, String providerId) {
super(id, name, comment, content, providerId);
newParam1 = TEST_PARAM_VALUE;
newParam2 = TEST_PARAM_VALUE;
newParam3 = TEST_PARAM_VALUE;
}

public ExtensionPointTestConfig(String id, String name, String comment, String content, String providerId, String newParam1, String newParam2, String newParam3) {
super(id, name, comment, content, providerId);
this.newParam1 = newParam1;
this.newParam2 = newParam2;
this.newParam3 = newParam3;
}

@TestExtension("testDynamicCreationOfConfigs2")
public static class ExtensionPointTestConfigProvider extends AbstractConfigProviderImpl {

public ExtensionPointTestConfigProvider() {
load();
}

@Override
public ContentType getContentType() {
return ContentType.DefinedType.GROOVY;
}

@Override
public String getDisplayName() {
return Messages.groovy_provider_name();
}

@NonNull
@Override
public Config newConfig(@NonNull String id) {
return new ExtensionPointTestConfig(id, TEST_NAME_VALUE, TEST_COMMENT_VALUE, TEST_CONTENT_VALUE, getProviderId(), TEST_PARAM_VALUE, TEST_PARAM_VALUE, TEST_PARAM_VALUE);
}

// ======================
// stuff for backward compatibility
protected transient String ID_PREFIX;

@Override
protected String getXmlFileName() {
return "extension-point-test-config-files.xml";
}

static {
Jenkins.XSTREAM.alias("org.jenkinsci.lib.configprovider.ExtensionPointTestConfigProvider", ExtensionPointTestConfigProvider.class);
}
// ======================
}

}
}

0 comments on commit c8924e0

Please sign in to comment.