Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] Add config validator for parameter options #2691

Merged
merged 3 commits into from
Feb 9, 2022

Conversation

cweitkamp
Copy link
Contributor

  • Added config validator for parameter options

Depends on #2690

Signed-off-by: Christoph Weitkamp github@christophweitkamp.de

@cweitkamp cweitkamp added enhancement An enhancement or new feature of the Core awaiting other PR Depends on another PR labels Jan 16, 2022
@cweitkamp cweitkamp requested a review from a team as a code owner January 16, 2022 14:00
@kaikreuzer kaikreuzer changed the title [config] Added config validator for parameter options [config] Add config validator for parameter options Jan 29, 2022
}

// Option values are a string, so we can do a simple compare
if (!param.getOptions().stream().map(o -> o.getValue()).anyMatch(v -> v.equals(value.toString()))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use noneMatch

// Option values are a string, so we can do a simple compare
if (!param.getOptions().stream().map(o -> o.getValue()).anyMatch(v -> v.equals(value.toString()))) {
MessageKey messageKey = MessageKey.OPTIONS_VIOLATED;
return new ConfigValidationMessage(param.getName(), messageKey.defaultMessage, messageKey.key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add the list of allowed options here. This might be helpful to correct the setting.

@wborn wborn removed the awaiting other PR Depends on another PR label Feb 6, 2022
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
@cweitkamp cweitkamp force-pushed the feature-config-options-validation branch from 1501b47 to 2e53959 Compare February 7, 2022 14:16
@cweitkamp cweitkamp requested a review from J-N-K February 7, 2022 14:29
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general comment: IMO ConfigDescriptionParameterValidatorFactory should be removed. There is no need for it, it just returns a new instance which could also be achieved by inserting new ... in the map. But maybe we should put that in another PR (like removing the unnecessary checks we talked about in #2690.

// ===========================================================================

@Test
public void assertValidationThrowsNoExceptionForAllowedLimitedParameterOption() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other validations we assert valid parameters pass the validation by adding a valid value in setUp. To keep it consistent, we should do the same here and only keep a separate test for the invalid one.

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Copy link
Member

@wborn wborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the validator!

@wborn wborn merged commit 9cda2c8 into openhab:main Feb 9, 2022
@wborn wborn added this to the 3.3 milestone Feb 9, 2022
@cweitkamp cweitkamp deleted the feature-config-options-validation branch February 9, 2022 08:04
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
GitOrigin-RevId: 9cda2c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants