Skip to content

Commit

Permalink
removed ditto prefix from channel variable in DittoChannelValueValida…
Browse files Browse the repository at this point in the history
…tor;

Signed-off-by: Stefan Maute <stefan.maute@bosch.io>
  • Loading branch information
Stefan Maute committed Sep 23, 2021
1 parent 2cc6c3d commit f148112
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.eclipse.ditto.base.model.exceptions.DittoHeaderInvalidException;

/**
* This validator checks if a normalized CharSequence is equal to {@value #DITTO_CHANNEL_TWIN} or
* {@value #DITTO_CHANNEL_LIVE}.
* This validator checks if a normalized CharSequence is equal to {@value #CHANNEL_TWIN} or
* {@value #CHANNEL_LIVE}.
* Normalized in this context means trimmed and converted to lower case.
* Normalization is temporarily conducted by this class for validation only.
*
Expand All @@ -30,8 +30,8 @@
@Immutable
final class DittoChannelValueValidator extends AbstractHeaderValueValidator {

static final String DITTO_CHANNEL_TWIN = "twin";
static final String DITTO_CHANNEL_LIVE = "live";
static final String CHANNEL_TWIN = "twin";
static final String CHANNEL_LIVE = "live";

private DittoChannelValueValidator() {
super(String.class::equals);
Expand All @@ -50,11 +50,12 @@ static DittoChannelValueValidator getInstance() {
protected void validateValue(final HeaderDefinition definition, final CharSequence value) {
final String normalizedValue = normalize(value);

if (!DITTO_CHANNEL_TWIN.equals(normalizedValue) && !DITTO_CHANNEL_LIVE.equals(normalizedValue)) {
throw DittoHeaderInvalidException.newInvalidTypeBuilder(definition, value, "ditto-channel")
if (!CHANNEL_TWIN.equals(normalizedValue) && !CHANNEL_LIVE.equals(normalizedValue)) {
throw DittoHeaderInvalidException.newInvalidTypeBuilder(definition, value,
DittoHeaderDefinition.CHANNEL.getKey())
.description(MessageFormat.format("The value must either be <{0}> or <{1}>.",
DITTO_CHANNEL_TWIN,
DITTO_CHANNEL_LIVE))
CHANNEL_TWIN,
CHANNEL_LIVE))
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static ValueValidator getMetadataHeadersValidator() {

/**
* Returns a validator for checking if a normalized CharSequence is equal to
* {@value DittoChannelValueValidator#DITTO_CHANNEL_TWIN} or {@value DittoChannelValueValidator#DITTO_CHANNEL_LIVE}.
* {@value DittoChannelValueValidator#CHANNEL_TWIN} or {@value DittoChannelValueValidator#CHANNEL_LIVE}.
* Normalized in this context means trimmed and converted to lower case.
* Normalization is temporarily conducted by the returned validator for validation only.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public static final class ParameterizedValueValidationTest {
@Parameterized.Parameters(name = "value: {0}, expected valid: {1}")
public static List<Object[]> parameters() {
return Arrays.asList(new Object[][]{
{DittoChannelValueValidator.DITTO_CHANNEL_TWIN, true},
{DittoChannelValueValidator.DITTO_CHANNEL_LIVE, true},
{DittoChannelValueValidator.CHANNEL_TWIN, true},
{DittoChannelValueValidator.CHANNEL_LIVE, true},
{"foo", false},
{" twin", true},
{"live ", true},
Expand Down

0 comments on commit f148112

Please sign in to comment.