Search in sources :

Example 16 with ParameterDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration in project mule by mulesoft.

the class ClusterSupportEnricherTestCase method assertEnrichment.

private void assertEnrichment(boolean runsOnPrimaryNodeOnly, boolean parameterAdded, boolean defaultParameterValue) {
    enricher.enrich(extensionLoadingContext);
    verify(sourceDeclaration).setRunsOnPrimaryNodeOnly(runsOnPrimaryNodeOnly);
    if (parameterAdded) {
        ArgumentCaptor<ParameterDeclaration> captor = ArgumentCaptor.forClass(ParameterDeclaration.class);
        verify(parameterGroup).addParameter(captor.capture());
        ParameterDeclaration parameter = captor.getValue();
        assertThat(parameter.getName(), equalTo(PRIMARY_NODE_ONLY_PARAMETER_NAME));
        assertThat(parameter.getDefaultValue(), is(defaultParameterValue));
    } else {
        verify(parameterGroup, never()).addParameter(any());
    }
}
Also used : ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)

Example 17 with ParameterDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration in project mule by mulesoft.

the class ExtensionsTestUtils method mockParameters.

public static ParameterGroupDeclaration mockParameters(ParameterizedDeclaration declaration, String groupName, ParameterDeclaration... parameters) {
    ParameterGroupDeclaration group = mock(ParameterGroupDeclaration.class);
    when(group.getName()).thenReturn(groupName);
    when(declaration.getParameterGroups()).thenReturn(asList(group));
    when(declaration.getParameterGroup(groupName)).thenReturn(group);
    List<ParameterDeclaration> params = new ArrayList<>(asList(parameters));
    when(group.getParameters()).thenReturn(params);
    when(declaration.getAllParameters()).thenReturn(params);
    return group;
}
Also used : ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) ArrayList(java.util.ArrayList) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)

Example 18 with ParameterDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration in project mule by mulesoft.

the class BackPressureDeclarationEnricher method addBackPressureParameter.

private void addBackPressureParameter(ExtensionDeclaration extensionDeclaration, SourceDeclaration sourceDeclaration, BackPressureStrategyModelProperty property) {
    ParameterDeclaration parameter = new ParameterDeclaration(BACK_PRESSURE_STRATEGY_PARAMETER_NAME);
    parameter.setDescription(BACK_PRESSURE_STRATEGY_PARAMETER_DESCRIPTION);
    parameter.setRequired(false);
    parameter.setDefaultValue(property.getDefaultMode());
    parameter.setExpressionSupport(NOT_SUPPORTED);
    parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB).build());
    MetadataType type = BaseTypeBuilder.create(JAVA).stringType().id(format("%s-%s-backPressureStrategy", extensionDeclaration.getName(), sourceDeclaration.getName())).with(new EnumAnnotation<>(property.getSupportedModes().stream().map(BackPressureMode::name).toArray(String[]::new))).build();
    parameter.setType(type, false);
    sourceDeclaration.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter);
}
Also used : EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) MetadataType(org.mule.metadata.api.model.MetadataType) BackPressureMode(org.mule.runtime.extension.api.runtime.source.BackPressureMode) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)

Example 19 with ParameterDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration in project mule by mulesoft.

the class BooleanParameterDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclaration extensionDeclaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    new DeclarationWalker() {

        @Override
        protected void onParameter(ParameterizedDeclaration owner, ParameterGroupDeclaration parameterGroup, ParameterDeclaration declaration) {
            declaration.getType().accept(new MetadataTypeVisitor() {

                @Override
                public void visitBoolean(BooleanType booleanType) {
                    declaration.setRequired(false);
                    if (declaration.getDefaultValue() == null && !declaration.isConfigOverride()) {
                        declaration.setDefaultValue(valueOf(FALSE));
                    }
                }
            });
        }
    }.walk(extensionDeclaration);
}
Also used : ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) ParameterizedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration) BooleanType(org.mule.metadata.api.model.BooleanType) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ConfigOverride(org.mule.runtime.extension.api.annotation.param.ConfigOverride) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ConfigOverride(org.mule.runtime.extension.api.annotation.param.ConfigOverride)

Example 20 with ParameterDeclaration

use of org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration in project mule by mulesoft.

the class JavaDeclarationDelegateTestCase method assertParameter.

private void assertParameter(List<ParameterDeclaration> parameters, String name, String description, MetadataType metadataType, boolean required, ExpressionSupport expressionSupport, Object defaultValue) {
    ParameterDeclaration param = findParameter(parameters, name);
    assertThat(param, is(notNullValue()));
    assertThat(param.getName(), equalTo(name));
    assertThat(param.getDescription(), equalTo(description));
    assertParameterType(metadataType, param);
    assertThat(param.isRequired(), is(required));
    assertThat(param.getExpressionSupport(), is(expressionSupport));
    assertThat(param.getDefaultValue(), equalTo(defaultValue));
}
Also used : ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)

Aggregations

ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)28 Test (org.junit.Test)18 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)15 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)9 ConfigurationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration)4 ParameterGroupDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration)3 PathModel (org.mule.runtime.api.meta.model.display.PathModel)3 List (java.util.List)2 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 ObjectType (org.mule.metadata.api.model.ObjectType)2 StringType (org.mule.metadata.api.model.StringType)2 ClassInformationAnnotation (org.mule.metadata.java.api.annotation.ClassInformationAnnotation)2 ImportedTypeModel (org.mule.runtime.api.meta.model.ImportedTypeModel)2 ConnectionProviderDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration)2 SourceDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)2 ClassValueModel (org.mule.runtime.api.meta.model.display.ClassValueModel)2 Reference (org.mule.runtime.api.util.Reference)2 IdempotentDeclarationWalker (org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker)2 BigDecimal (java.math.BigDecimal)1