Skip to content

Commit

Permalink
[JENKINS-31458] Reproduced problem in test (passes in 53c86ec but fai…
Browse files Browse the repository at this point in the history
…ls in 600b1f0).
  • Loading branch information
jglick committed Nov 30, 2015
1 parent 6641190 commit c6f66be
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
@@ -0,0 +1,90 @@
/*
* The MIT License
*
* Copyright 2015 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.model;

import java.util.Locale;
import net.sf.json.JSONObject;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Ignore;
import org.junit.Rule;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.StaplerRequest;

public class ParametersDefinitionPropertyTest {

@Rule
public JenkinsRule r = new JenkinsRule();

@Ignore("TODO after 600b1f0 (#1888): NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class hudson.model.ParametersDefinitionPropertyTest$KrazyParameterDefinition")
@Issue("JENKINS-31458")
@Test
public void customNewInstance() throws Exception {
KrazyParameterDefinition kpd = new KrazyParameterDefinition("kpd", "desc", "KrAzY");
FreeStyleProject p = r.createFreeStyleProject();
ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(kpd);
p.addProperty(pdp);
r.configRoundtrip(p);
pdp = p.getProperty(ParametersDefinitionProperty.class);
kpd = (KrazyParameterDefinition) pdp.getParameterDefinition("kpd");
assertEquals("desc", kpd.getDescription());
assertEquals("krazy", kpd.field);
}

public static class KrazyParameterDefinition extends ParameterDefinition {

public final String field;

// not @DataBoundConstructor
public KrazyParameterDefinition(String name, String description, String field) {
super(name, description);
this.field = field;
}

@Override
public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
throw new UnsupportedOperationException();
}

@Override
public ParameterValue createValue(StaplerRequest req) {
throw new UnsupportedOperationException();
}

@TestExtension("customNewInstance")
public static class DescriptorImpl extends ParameterDescriptor {

@Override
public ParameterDefinition newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new KrazyParameterDefinition(formData.getString("name"), formData.getString("description"), formData.getString("field").toLowerCase(Locale.ENGLISH));
}

}

}

}
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2015 CloudBees, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry field="name" title="name">
<f:textbox/>
</f:entry>
<f:entry field="description" title="description">
<f:textarea/>
</f:entry>
<f:entry title="field">
<f:textbox name="field" value="${instance.field.toUpperCase()}"/>
</f:entry>
</j:jelly>

0 comments on commit c6f66be

Please sign in to comment.