Skip to content

Commit

Permalink
W-17475148: Simple type params handler not handling certain expressio…
Browse files Browse the repository at this point in the history
…n param values (#14113)(#14122)

* Addendum
  • Loading branch information
elrodro83 authored Jan 3, 2025
1 parent 2c18f26 commit 973f8f2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ protected final boolean handleRequest(Map<ComponentAst, SpringComponentModel> 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);
}
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.mule.runtime.config.internal.dsl.spring;

import static org.mule.runtime.extension.api.util.ExtensionModelUtils.isContent;

import org.mule.runtime.ast.api.ComponentParameterAst;

/**
Expand All @@ -30,4 +32,9 @@ protected boolean isExpressionValue(CreateParamBeanDefinitionRequest request) {
return request.getParam().getValue().isLeft();
}

@Override
protected boolean isContentParam(CreateParamBeanDefinitionRequest request) {
return isContent(request.getParam().getModel());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,12 +32,17 @@

public class SimpleTypeBeanParamDefinitionCreatorTestCase extends AbstractMuleTestCase {

private ParameterModel paramModel;

private SimpleTypeBeanParamDefinitionCreator simpleTypeParamDefinitionCreator;
private CreateParamBeanDefinitionRequest createParamDefinitionRequest;
private Map<ComponentAst, SpringComponentModel> springComponentModels;

@Before
public void setUp() {
paramModel = mock(ParameterModel.class);
when(paramModel.getRole()).thenReturn(CONTENT);

simpleTypeParamDefinitionCreator = new SimpleTypeBeanParamDefinitionCreator();
createParamDefinitionRequest = mock(CreateParamBeanDefinitionRequest.class);
SpringComponentModel springComponentModel = new SpringComponentModel();
Expand Down Expand Up @@ -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));
}

}

0 comments on commit 973f8f2

Please sign in to comment.