Skip to content

Commit

Permalink
Merge pull request #281 from MCMicS/bug/280
Browse files Browse the repository at this point in the history
closes #280 DateParameterDefinition is unsupported
  • Loading branch information
MCMicS authored Jun 8, 2021
2 parents b3ea18f + 50b1b49 commit 423ee48
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 15 deletions.
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());
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/JobParameterRenderer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
implementation="org.codinjutsu.tools.jenkins.view.parameter.PersistentParameterRenderer"/>
<buildParameterRenderer implementation="org.codinjutsu.tools.jenkins.view.parameter.ListGitBranchesParameterRenderer" />
<buildParameterRenderer implementation="org.codinjutsu.tools.jenkins.view.parameter.ExtendedChoiceParameterRenderer" />
<buildParameterRenderer implementation="org.codinjutsu.tools.jenkins.view.parameter.DateParameterRenderer" />
</extensions>
</idea-plugin>
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public void renderAsInputField() {

@Test
public void renderAsComboboxIfApiValuesAreAvailable() {
JobParameter jobParameter = createJobParameter(ExtendedChoiceParameterRenderer.PT_SINGLE_SELECT,
JobParameter jobParameter = createJobParameterChoices(ExtendedChoiceParameterRenderer.PT_SINGLE_SELECT,
"Value1", "Selected", "Value3");
JobParameterComponent<?> jobParameterComponent = jobParameterRenderer.render(jobParameter);
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class);
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter);

jobParameter = createJobParameter(ExtendedChoiceParameterRenderer.PT_MULTI_SELECT,
jobParameter = createJobParameterChoices(ExtendedChoiceParameterRenderer.PT_MULTI_SELECT,
"Value1", "Selected", "Value3");
jobParameterComponent = jobParameterRenderer.render(jobParameter);
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,30 @@ public interface JobParameterTest {

@NotNull
default JobParameter createJobParameter(JobParameterType jobParameterType) {
return createJobParameter(jobParameterType, new String [0]);
return createJobParameter(jobParameterType, "");
}

@NotNull
default JobParameter createJobParameter(JobParameterType jobParameterType, String... choices) {
return JobParameter.builder().jobParameterType(jobParameterType)
.name("Test").choices(Arrays.asList(choices)).defaultValue("default").description("Test Parameter")
default JobParameter createJobParameter(JobParameterType jobParameterType, String defaultValue) {
return createJobParameter(jobParameterType, defaultValue, new String [0]);
}

@NotNull
default JobParameter createJobParameterChoices(JobParameterType jobParameterType, String... choices) {
return createJobParameter(jobParameterType, "", choices);
}

@NotNull
default JobParameter createJobParameter(JobParameterType jobParameterType, String defaultValue,
String... choices) {
return createJobParameterBuilder(jobParameterType)
.defaultValue(defaultValue).choices(Arrays.asList(choices))
.build();
}

@NotNull
static JobParameter.JobParameterBuilder createJobParameterBuilder(JobParameterType jobParameterType) {
return JobParameter.builder().jobParameterType(jobParameterType)
.name("Test").description("Test Parameter");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ public void renderAsInputField() {

@Test
public void renderAsComboBox() {
JobParameter jobParameter = createJobParameter(ListGitBranchesParameterRenderer.PT_TAG, "master", "tag/v0.13.6");
JobParameter jobParameter = createJobParameterChoices(ListGitBranchesParameterRenderer.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(ListGitBranchesParameterRenderer.PT_BRANCH, "master", "bug/225");
jobParameter = createJobParameterChoices(ListGitBranchesParameterRenderer.PT_BRANCH, "master", "bug/225");
jobParameterComponent = jobParameterRenderer.render(jobParameter);
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class);
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter);

jobParameter = createJobParameter(ListGitBranchesParameterRenderer.PT_BRANCH_TAG, "master", "tag/v0.13.6");
jobParameter = createJobParameterChoices(ListGitBranchesParameterRenderer.PT_BRANCH_TAG, "master", "tag/v0.13.6");
jobParameterComponent = jobParameterRenderer.render(jobParameter);
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(ComboBox.class);
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void renderLabel() {

@Test
public void renderNode() {
final JobParameter jobParameter = createJobParameter(nodeParameter, "Test", "default", "master");
final JobParameter jobParameter = createJobParameter(nodeParameter, "default", "Test", "default", "master");
JobParameterComponent<?> jobParameterComponent = jobParameterRenderer.render(jobParameter);
final JComponent viewElement = jobParameterComponent.getViewElement();
assertThat(viewElement).isInstanceOf(JComboBox.class);
Expand Down

0 comments on commit 423ee48

Please sign in to comment.