PipelineFunctionParameterResolverFactory { static SingleParameterResolver forStringOrPlaceholderParameter() { return STRING_OR_PLACEHOLDER_PARAMETER_RESOLVER; } private  PipelineFunctionParameterResolverFactory();   }
@Test public void singleStringResolverAcceptsDoubleQuotes() { final PipelineFunctionParameterResolverFactory.SingleParameterResolver parameterResolver = PipelineFunctionParameterResolverFactory.forStringOrPlaceholderParameter(); final String params = "(\"" + KNOWN_VALUE + "\")"; assertThat(parameterResolver.apply(params, expressionResolver, DUMMY)).contains(KNOWN_VALUE); verifyNoInteractions(expressionResolver); }
@Test public void singleStringResolverAcceptsSingleQuotes() { final PipelineFunctionParameterResolverFactory.SingleParameterResolver parameterResolver = PipelineFunctionParameterResolverFactory.forStringOrPlaceholderParameter(); final String params = "(\'" + KNOWN_VALUE + "\')"; assertThat(parameterResolver.apply(params, expressionResolver, DUMMY)).contains(KNOWN_VALUE); verifyNoInteractions(expressionResolver); }
@Test public void singleResolverThrowsExceptionOnMultipleParameters() { final PipelineFunctionParameterResolverFactory.SingleParameterResolver parameterResolver = PipelineFunctionParameterResolverFactory.forStringOrPlaceholderParameter(); final String paramsDoubleQuoted = "(\"" + KNOWN_VALUE + "\", \"otherValue\")"; final String paramsSingleQuoted = "(\'" + KNOWN_VALUE + "\', \'otherValue\')"; final String paramsPlaceholders = "(" + KNOWN_PLACEHOLDER + ", topic:full)"; assertThatExceptionOfType(PlaceholderFunctionSignatureInvalidException.class) .isThrownBy(() -> parameterResolver.apply(paramsDoubleQuoted, expressionResolver, DUMMY)); assertThatExceptionOfType(PlaceholderFunctionSignatureInvalidException.class) .isThrownBy(() -> parameterResolver.apply(paramsSingleQuoted, expressionResolver, DUMMY)); assertThatExceptionOfType(PlaceholderFunctionSignatureInvalidException.class) .isThrownBy(() -> parameterResolver.apply(paramsPlaceholders, expressionResolver, DUMMY)); verifyNoInteractions(expressionResolver); }
@Test public void singleResolverResolvesPlaceholder() { final PipelineFunctionParameterResolverFactory.SingleParameterResolver parameterResolver = PipelineFunctionParameterResolverFactory.forStringOrPlaceholderParameter(); final String params = "(" + KNOWN_PLACEHOLDER + ")"; when(expressionResolver.resolveAsPipelineElement(anyString())) .thenReturn(PipelineElement.resolved(KNOWN_VALUE)); assertThat(parameterResolver.apply(params, expressionResolver, DUMMY)).contains(KNOWN_VALUE); verify(expressionResolver).resolveAsPipelineElement(KNOWN_PLACEHOLDER); }
@Test public void singleResolverAllowsWhitespaceInStrings() { final PipelineFunctionParameterResolverFactory.SingleParameterResolver parameterResolver = PipelineFunctionParameterResolverFactory.forStringOrPlaceholderParameter(); final String value = " " + KNOWN_VALUE + " "; final String stringSingle = "(\'" + value + "\')"; final String stringDouble = "(\"" + value + "\")"; assertThat(parameterResolver.apply(stringSingle, expressionResolver, DUMMY)).contains(value); assertThat(parameterResolver.apply(stringDouble, expressionResolver, DUMMY)).contains(value); }
@Test public void singleResolverAllowsWhitespaceBetweenParentheses() { final PipelineFunctionParameterResolverFactory.SingleParameterResolver parameterResolver = PipelineFunctionParameterResolverFactory.forStringOrPlaceholderParameter(); final String stringSingle = "( \'" + KNOWN_VALUE + "\' )"; final String stringDouble = "( \"" + KNOWN_VALUE + "\" )"; final String stringPlaceholder = "( " + KNOWN_PLACEHOLDER + " )"; when(expressionResolver.resolveAsPipelineElement(anyString())).thenReturn( PipelineElement.resolved(KNOWN_VALUE)); assertThat(parameterResolver.apply(stringSingle, expressionResolver, DUMMY)).contains(KNOWN_VALUE); assertThat(parameterResolver.apply(stringDouble, expressionResolver, DUMMY)).contains(KNOWN_VALUE); assertThat(parameterResolver.apply(stringPlaceholder, expressionResolver, DUMMY)).contains(KNOWN_VALUE); verify(expressionResolver).resolveAsPipelineElement(KNOWN_PLACEHOLDER); }
@Test public void singlePlaceholderResolverReturnsPlaceholderIfNotResolvable() { final PipelineFunctionParameterResolverFactory.SingleParameterResolver parameterResolver = PipelineFunctionParameterResolverFactory.forStringOrPlaceholderParameter(); final String stringPlaceholder = "( " + KNOWN_PLACEHOLDER + " )"; when(expressionResolver.resolveAsPipelineElement(anyString())).thenReturn(PipelineElement.unresolved()); assertThat(parameterResolver.apply(stringPlaceholder, expressionResolver, DUMMY)).isEmpty(); verify(expressionResolver).resolveAsPipelineElement(KNOWN_PLACEHOLDER); }