-
Notifications
You must be signed in to change notification settings - Fork 125
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 #281 from MCMicS/bug/280
closes #280 DateParameterDefinition is unsupported
- Loading branch information
Showing
8 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/org/codinjutsu/tools/jenkins/view/parameter/DateParameterRenderer.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,29 @@ | ||
package org.codinjutsu.tools.jenkins.view.parameter; | ||
|
||
import org.codinjutsu.tools.jenkins.model.JobParameter; | ||
import org.codinjutsu.tools.jenkins.model.JobParameterType; | ||
import org.codinjutsu.tools.jenkins.view.extension.JobParameterRenderer; | ||
import org.codinjutsu.tools.jenkins.view.extension.JobParameterRenderers; | ||
import org.jetbrains.annotations.NonNls; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
|
||
public class DateParameterRenderer implements JobParameterRenderer { | ||
|
||
@NonNls | ||
private static final String TYPE_CLASS = "me.leejay.jenkins.dateparameter.DateParameterDefinition"; | ||
|
||
static final JobParameterType DATE_PARAMETER = new JobParameterType("DateParameterDefinition", TYPE_CLASS); | ||
|
||
@NotNull | ||
@Override | ||
public JobParameterComponent<String> render(@NotNull JobParameter jobParameter) { | ||
return JobParameterRenderers.createTextField(jobParameter, jobParameter.getDefaultValue()); | ||
} | ||
|
||
@Override | ||
public boolean isForJobParameter(@NotNull JobParameter jobParameter) { | ||
return DATE_PARAMETER.equals(jobParameter.getJobParameterType()); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/test/java/org/codinjutsu/tools/jenkins/view/parameter/DateParameterRendererTest.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,41 @@ | ||
package org.codinjutsu.tools.jenkins.view.parameter; | ||
|
||
import org.codinjutsu.tools.jenkins.model.BuildInJobParameter; | ||
import org.codinjutsu.tools.jenkins.model.JobParameter; | ||
import org.junit.Test; | ||
|
||
import javax.swing.*; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class DateParameterRendererTest implements JobParameterTest { | ||
|
||
private final DateParameterRenderer jobParameterRenderer = new DateParameterRenderer(); | ||
|
||
@Test | ||
public void renderAsInputField() { | ||
JobParameter jobParameter = createJobParameter(DateParameterRenderer.DATE_PARAMETER); | ||
JobParameterComponent<?> jobParameterComponent = jobParameterRenderer.render(jobParameter); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(JTextField.class); | ||
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter); | ||
} | ||
|
||
@Test | ||
public void renderWithDefaultValue() { | ||
final String defaultValue = "2021-05-15"; | ||
JobParameter jobParameter = createJobParameter(DateParameterRenderer.DATE_PARAMETER, defaultValue); | ||
JobParameterComponent<?> jobParameterComponent = jobParameterRenderer.render(jobParameter); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(JTextField.class); | ||
final JTextField textField = (JTextField) jobParameterComponent.getViewElement(); | ||
assertThat(textField.getText()).isEqualTo(defaultValue); | ||
} | ||
|
||
@Test | ||
public void isForJobParameter() { | ||
assertThat(jobParameterRenderer.isForJobParameter(createJobParameter(DateParameterRenderer.DATE_PARAMETER))) | ||
.isTrue(); | ||
assertThat(jobParameterRenderer.isForJobParameter(createJobParameter( | ||
BuildInJobParameter.ChoiceParameterDefinition))).isFalse(); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,28 +51,28 @@ public void renderAsInputField() { | |
|
||
@Test | ||
public void renderAsComboBox() { | ||
JobParameter jobParameter = createJobParameter(GitParameterRenderer.PT_TAG, "master", "tag/v0.13.6"); | ||
JobParameter jobParameter = createJobParameterChoices(GitParameterRenderer.PT_TAG, "master", "tag/v0.13.6"); | ||
JobParameterComponent<?> jobParameterComponent = jobParameterRenderer.render(jobParameter); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class); | ||
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter); | ||
|
||
jobParameter = createJobParameter(GitParameterRenderer.PT_BRANCH, "master", "bug/225"); | ||
jobParameter = createJobParameterChoices(GitParameterRenderer.PT_BRANCH, "master", "bug/225"); | ||
jobParameterComponent = jobParameterRenderer.render(jobParameter); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class); | ||
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter); | ||
|
||
jobParameter = createJobParameter(GitParameterRenderer.PT_BRANCH_TAG, "master", "tag/v0.13.6"); | ||
jobParameter = createJobParameterChoices(GitParameterRenderer.PT_BRANCH_TAG, "master", "tag/v0.13.6"); | ||
jobParameterComponent = jobParameterRenderer.render(jobParameter); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class); | ||
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter); | ||
|
||
jobParameter = createJobParameter(GitParameterRenderer.PT_REVISION, | ||
jobParameter = createJobParameterChoices(GitParameterRenderer.PT_REVISION, | ||
"abcf12345 2020-04-14 21:36 user <[email protected]> sample Revision"); | ||
jobParameterComponent = jobParameterRenderer.render(jobParameter); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class); | ||
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter); | ||
|
||
jobParameter = createJobParameter(GitParameterRenderer.PT_PULL_REQUEST, "master", "pr/226"); | ||
jobParameter = createJobParameterChoices(GitParameterRenderer.PT_PULL_REQUEST, "master", "pr/226"); | ||
jobParameterComponent = jobParameterRenderer.render(jobParameter); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class); | ||
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter); | ||
|
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
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