-
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 #370 from MCMicS/issue/251_CascadeChoiceParameter
add Active Choices Parameter (only rendered as text input fields)
- Loading branch information
Showing
12 changed files
with
147 additions
and
17 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
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
48 changes: 48 additions & 0 deletions
48
...main/java/org/codinjutsu/tools/jenkins/view/parameter/ActiveChoicesParameterRenderer.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,48 @@ | ||
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.model.ProjectJob; | ||
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 org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.BiFunction; | ||
|
||
import static org.codinjutsu.tools.jenkins.model.JobParameterType.createTypeForClassPrefix; | ||
|
||
public class ActiveChoicesParameterRenderer implements JobParameterRenderer { | ||
|
||
@NonNls | ||
private static final String TYPE_CLASS_PREFIX = "org.biouno.unochoice."; | ||
|
||
static final JobParameterType CHOICE_PARAMETER = createTypeForClassPrefix("ChoiceParameter", TYPE_CLASS_PREFIX); | ||
|
||
static final JobParameterType CASCADE_CHOICE_PARAMETER = createTypeForClassPrefix("CascadeChoiceParameter", TYPE_CLASS_PREFIX); | ||
|
||
static final JobParameterType DYNAMIC_REFERENCE_PARAMETER = createTypeForClassPrefix("DynamicReferenceParameter", TYPE_CLASS_PREFIX); | ||
|
||
private final Map<JobParameterType, BiFunction<JobParameter, String, JobParameterComponent<String>>> converter = | ||
new HashMap<>(); | ||
|
||
public ActiveChoicesParameterRenderer() { | ||
converter.put(CHOICE_PARAMETER, JobParameterRenderers::createComboBoxIfChoicesExists); | ||
converter.put(CASCADE_CHOICE_PARAMETER, JobParameterRenderers::createComboBoxIfChoicesExists); | ||
converter.put(DYNAMIC_REFERENCE_PARAMETER, JobParameterRenderers::createLabel); | ||
} | ||
|
||
@Override | ||
public @NotNull JobParameterComponent render(@NotNull JobParameter jobParameter, @Nullable ProjectJob projectJob) { | ||
return converter.getOrDefault(jobParameter.getJobParameterType(), JobParameterRenderers::createErrorLabel) | ||
.apply(jobParameter, jobParameter.getDefaultValue()); | ||
} | ||
|
||
@Override | ||
public boolean isForJobParameter(@NotNull JobParameter jobParameter) { | ||
return converter.containsKey(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
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
43 changes: 43 additions & 0 deletions
43
.../java/org/codinjutsu/tools/jenkins/view/parameter/ActiveChoicesParameterRendererTest.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,43 @@ | ||
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 ActiveChoicesParameterRendererTest implements JobParameterTest { | ||
|
||
private final ActiveChoicesParameterRenderer jobParameterRenderer = new ActiveChoicesParameterRenderer(); | ||
|
||
@Test | ||
public void renderAsInputField() { | ||
JobParameter jobParameter = createJobParameter(ActiveChoicesParameterRenderer.CHOICE_PARAMETER); | ||
JobParameterComponent<?> jobParameterComponent = jobParameterRenderer.render(jobParameter, PROJECT_JOB); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(JTextField.class); | ||
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter); | ||
|
||
jobParameter = createJobParameter(ActiveChoicesParameterRenderer.CASCADE_CHOICE_PARAMETER); | ||
jobParameterComponent = jobParameterRenderer.render(jobParameter, PROJECT_JOB); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(JTextField.class); | ||
assertThat(jobParameterComponent.getJobParameter()).isEqualTo(jobParameter); | ||
} | ||
|
||
@Test | ||
public void renderAsLabel() { | ||
JobParameter jobParameter = createJobParameter(ActiveChoicesParameterRenderer.DYNAMIC_REFERENCE_PARAMETER); | ||
JobParameterComponent<?> jobParameterComponent = jobParameterRenderer.render(jobParameter, PROJECT_JOB); | ||
assertThat(jobParameterComponent.getViewElement()).isInstanceOf(JLabel.class); | ||
} | ||
|
||
@Test | ||
public void isForJobParameter() { | ||
assertThat(jobParameterRenderer.isForJobParameter(createJobParameter(ActiveChoicesParameterRenderer.CHOICE_PARAMETER))).isTrue(); | ||
assertThat(jobParameterRenderer.isForJobParameter(createJobParameter(ActiveChoicesParameterRenderer.CASCADE_CHOICE_PARAMETER))).isTrue(); | ||
assertThat(jobParameterRenderer.isForJobParameter(createJobParameter(ActiveChoicesParameterRenderer.DYNAMIC_REFERENCE_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