Skip to content

Commit

Permalink
fix failing ImmutableFunctionExpression Unit-Test
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Fendt <Florian.Fendt@bosch-si.com>
  • Loading branch information
ffendt committed Feb 26, 2019
1 parent f341b20 commit 9937ee8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ public List<String> getSupportedNames() {
}

@Override
public boolean supports(final String expression) {
public boolean supports(final String expressionName) {

// it is sufficient that the passed in name starts with the function name and an opening parentheses,
// e.g.: default('foo'). the function validates itself whether the remaining part is valid.
return SUPPORTED.stream()
.map(PipelineFunction::getName)
.map(psfName -> psfName.replaceFirst(getPrefix() + ":", ""))
.anyMatch(psfName -> expression.startsWith(psfName + "("));
.anyMatch(psfName -> expressionName.startsWith(psfName + "("));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ final class ImmutablePipeline implements Pipeline {
}

@Override
public Optional<String> execute(final Optional<String> pipelineInput,
final ExpressionResolver expressionResolver) {
public Optional<String> execute(final Optional<String> pipelineInput, final ExpressionResolver expressionResolver) {

Optional<String> stageValue = pipelineInput;
for (final String expression : stageExpressions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public DefaultFunctionSignature getSignature() {
public Optional<String> apply(final Optional<String> value, final String paramsIncludingParentheses,
final ExpressionResolver expressionResolver) {

validateOrThrow(paramsIncludingParentheses);

if (value.isPresent()) {
// if previous stage was non-empty: proceed with that
return value;
Expand All @@ -58,6 +60,13 @@ public Optional<String> apply(final Optional<String> value, final String paramsI
}
}

private void validateOrThrow(final String paramsIncludingParentheses) {
if (!paramsIncludingParentheses.matches(OVERALL_PATTERN_STR)) {
throw PlaceholderFunctionSignatureInvalidException.newBuilder(paramsIncludingParentheses, this)
.build();
}
}

private ResolvedFunctionParameter<String> parseAndResolve(final String paramsIncludingParentheses,
final ExpressionResolver expressionResolver) {

Expand Down

0 comments on commit 9937ee8

Please sign in to comment.