diff --git a/modules/spring-config/src/main/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanBaseDefinitionCreator.java b/modules/spring-config/src/main/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanBaseDefinitionCreator.java index 24de05a9a4b..1f2683fd8c5 100644 --- a/modules/spring-config/src/main/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanBaseDefinitionCreator.java +++ b/modules/spring-config/src/main/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanBaseDefinitionCreator.java @@ -33,7 +33,9 @@ protected final boolean handleRequest(Map sp if (isSimpleType(type) // Expressions are String, which are simple values for the spring bean definitions - || isExpressionValue(createBeanDefinitionRequest)) { + || isExpressionValue(createBeanDefinitionRequest) + // Content params are texts within the body + || isContentParam(createBeanDefinitionRequest)) { createBeanDefinitionRequest.getSpringComponentModel().setType(type); return doHandleRequest(createBeanDefinitionRequest, type); } @@ -45,6 +47,10 @@ protected boolean isExpressionValue(R request) { return false; } + protected boolean isContentParam(R request) { + return false; + } + protected abstract boolean doHandleRequest(R createBeanDefinitionRequest, Class type); protected final void setConvertibleBeanDefinition(R createBeanDefinitionRequest, Class type, diff --git a/modules/spring-config/src/main/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanParamDefinitionCreator.java b/modules/spring-config/src/main/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanParamDefinitionCreator.java index cc6b726c3b9..1f7df9ecb46 100644 --- a/modules/spring-config/src/main/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanParamDefinitionCreator.java +++ b/modules/spring-config/src/main/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanParamDefinitionCreator.java @@ -9,6 +9,7 @@ import static org.mule.runtime.core.api.el.ExpressionManager.DEFAULT_EXPRESSION_POSTFIX; import static org.mule.runtime.core.api.el.ExpressionManager.DEFAULT_EXPRESSION_PREFIX; import static org.mule.runtime.dsl.api.xml.parser.XmlApplicationParser.IS_CDATA; +import static org.mule.runtime.extension.api.util.ExtensionModelUtils.isContent; import static java.lang.Boolean.TRUE; @@ -46,6 +47,11 @@ protected boolean isExpressionValue(CreateParamBeanDefinitionRequest request) { return request.getParam().getValue().isLeft(); } + @Override + protected boolean isContentParam(CreateParamBeanDefinitionRequest request) { + return isContent(request.getParam().getModel()); + } + static Object resolveParamValue(final ComponentParameterAst param, boolean disableTrimWhitespaces, boolean disablePojoCdataTrimWhitespaces) { return param.getValue() diff --git a/modules/spring-config/src/test/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanParamDefinitionCreatorTestCase.java b/modules/spring-config/src/test/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanParamDefinitionCreatorTestCase.java index 0348dae9425..49259a59912 100644 --- a/modules/spring-config/src/test/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanParamDefinitionCreatorTestCase.java +++ b/modules/spring-config/src/test/java/org/mule/runtime/config/internal/dsl/spring/SimpleTypeBeanParamDefinitionCreatorTestCase.java @@ -8,12 +8,15 @@ import static org.mule.runtime.api.functional.Either.left; import static org.mule.runtime.api.functional.Either.right; +import static org.mule.runtime.api.meta.model.parameter.ParameterRole.BEHAVIOUR; +import static org.mule.runtime.api.meta.model.parameter.ParameterRole.CONTENT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.mule.runtime.api.meta.model.parameter.ParameterModel; import org.mule.runtime.ast.api.ComponentAst; import org.mule.runtime.ast.api.ComponentParameterAst; import org.mule.runtime.config.internal.dsl.model.SpringComponentModel; @@ -29,12 +32,17 @@ public class SimpleTypeBeanParamDefinitionCreatorTestCase extends AbstractMuleTestCase { + private ParameterModel paramModel; + private SimpleTypeBeanParamDefinitionCreator simpleTypeParamDefinitionCreator; private CreateParamBeanDefinitionRequest createParamDefinitionRequest; private Map springComponentModels; @Before public void setUp() { + paramModel = mock(ParameterModel.class); + when(paramModel.getRole()).thenReturn(CONTENT); + simpleTypeParamDefinitionCreator = new SimpleTypeBeanParamDefinitionCreator(true, true); createParamDefinitionRequest = mock(CreateParamBeanDefinitionRequest.class); SpringComponentModel springComponentModel = new SpringComponentModel(); @@ -66,10 +74,33 @@ public void complexObjectInlineNotHandled() { final ComponentParameterAst param = mock(ComponentParameterAst.class); when(param.getValue()).thenReturn(right(mock(ComponentAst.class))); + final ParameterModel paramModel = mock(ParameterModel.class); + when(paramModel.getRole()).thenReturn(BEHAVIOUR); + when(param.getModel()).thenReturn(paramModel); + when(createParamDefinitionRequest.getParam()).thenReturn(param); boolean result = simpleTypeParamDefinitionCreator.handleRequest(springComponentModels, createParamDefinitionRequest); assertThat("request handled when it must not", result, is(false)); } + @Test + @Issue("W-17475148") + public void staticTextInContentParamHandled() { + SpringComponentModel springComponentModel = createParamDefinitionRequest.getSpringComponentModel(); + springComponentModel.setType(Map.class); + + final ComponentParameterAst param = mock(ComponentParameterAst.class); + when(param.getValue()).thenReturn(right("some static text")); + + final ParameterModel paramModel = mock(ParameterModel.class); + when(paramModel.getRole()).thenReturn(CONTENT); + when(param.getModel()).thenReturn(paramModel); + + when(createParamDefinitionRequest.getParam()).thenReturn(param); + + boolean result = simpleTypeParamDefinitionCreator.handleRequest(springComponentModels, createParamDefinitionRequest); + assertThat("request not handled when it must", result, is(true)); + } + }