Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from wolfs/hetero-radio
[JENKINS-22583] Added hetero-radio to Ui-Samples with roundtrip-test
- Loading branch information
Showing
4 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/resources/jenkins/plugins/ui_samples/HeteroList/HeteroRadioEntry/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
The MIT License | ||
Copyright 2013 Jesse Glick. | ||
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 title="Hetero-Choice"> | ||
<f:hetero-radio field="entry" descriptors="${descriptor.entryDescriptors}" /> | ||
</f:entry> | ||
</j:jelly> |
55 changes: 55 additions & 0 deletions
55
src/test/java/jenkins/plugins/ui_samples/HeteroListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package jenkins.plugins.ui_samples; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.collect.ImmutableList; | ||
import hudson.XmlFile; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class HeteroListTest { | ||
|
||
public static final String CONFIGURE_URL = "configure"; | ||
public static final String CONFIG_FORM_NAME = "config"; | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void Hetero_Radio_Roundtrip() throws Exception { | ||
HeteroList.Entry firstRadioEntry = new HeteroList.HeteroRadioEntry(new HeteroList.SimpleEntry("first")); | ||
HeteroList.Entry secondRadioEntry = new HeteroList.HeteroRadioEntry(new HeteroList.SimpleEntry("second")); | ||
|
||
List<HeteroList.Entry> savedEntries = configRoundtrip(firstRadioEntry, secondRadioEntry); | ||
|
||
assertThat(savedEntries).extracting("entry.text").containsExactly("first", "second"); | ||
} | ||
|
||
private List<HeteroList.Entry> configRoundtrip(HeteroList.Entry... entries) throws Exception { | ||
HeteroList heteroList = new HeteroList(); | ||
XmlFile configFile = heteroList.getConfigFile(); | ||
heteroList.setConfig(new HeteroList.Config(ImmutableList.copyOf(entries))); | ||
configFile.write(heteroList); | ||
long savedManually = configFile.getFile().lastModified(); | ||
|
||
configRoundtrip(heteroList); | ||
long savedViaWebInterface = configFile.getFile().lastModified(); | ||
|
||
assertThat(savedManually).isLessThan(savedViaWebInterface); | ||
|
||
HeteroList saved = new HeteroList(); | ||
|
||
return saved.getConfig().getEntries(); | ||
} | ||
|
||
private void configRoundtrip(UISample uiSample) throws Exception { | ||
j.submit(j.createWebClient().goTo(getUiSampleConfigureUrl(uiSample)).getFormByName(CONFIG_FORM_NAME)); | ||
} | ||
|
||
private String getUiSampleConfigureUrl(UISample uiSample) { | ||
return Joiner.on('/').join(new Root().getUrlName(), uiSample.getUrlName(), CONFIGURE_URL); | ||
} | ||
} |