Search in sources :

Example 1 with SourceCallbackModel

use of org.mule.runtime.api.meta.model.source.SourceCallbackModel in project mule by mulesoft.

the class InputParametersTypeModelValidator method validate.

@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problems) {
    final Set<Class<?>> validatedTypes = new HashSet<>();
    new IdempotentExtensionWalker() {

        @Override
        public void onOperation(OperationModel model) {
            model.getAllParameterModels().forEach(parameterModel -> validateJavaType(model, parameterModel.getType(), problems, validatedTypes));
        }

        @Override
        public void onSource(SourceModel model) {
            validateCallback(model, model.getSuccessCallback());
            validateCallback(model, model.getErrorCallback());
            validateCallback(model, model.getTerminateCallback());
        }

        private void validateCallback(SourceModel model, Optional<SourceCallbackModel> callback) {
            callback.ifPresent(cb -> cb.getAllParameterModels().forEach(parameterModel -> validateJavaType(model, parameterModel.getType(), problems, validatedTypes)));
        }
    }.walk(extensionModel);
    extensionModel.getSubTypes().forEach(subTypesModel -> getClassForValidation(subTypesModel.getBaseType()).filter(validatedTypes::contains).ifPresent(type -> {
        subTypesModel.getSubTypes().forEach(subtype -> validateSubtypesHaveGetters(extensionModel, subtype, problems, validatedTypes));
    }));
}
Also used : Optional.empty(java.util.Optional.empty) StereotypeTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.StereotypeTypeAnnotation) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) NamedObject(org.mule.runtime.api.meta.NamedObject) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashSet(java.util.HashSet) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ArrayType(org.mule.metadata.api.model.ArrayType) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) Problem(org.mule.runtime.extension.api.loader.Problem) Collectors.toSet(java.util.stream.Collectors.toSet) IntrospectionUtils.getFieldsWithGetters(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldsWithGetters) TypeUtils(org.mule.runtime.extension.api.declaration.type.TypeUtils) ExtensionModelValidator(org.mule.runtime.extension.api.loader.ExtensionModelValidator) ObjectType(org.mule.metadata.api.model.ObjectType) ProblemsReporter(org.mule.runtime.extension.api.loader.ProblemsReporter) Collection(java.util.Collection) Set(java.util.Set) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ExtensionMetadataTypeUtils.getType(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getType) SourceCallbackModel(org.mule.runtime.api.meta.model.source.SourceCallbackModel) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) NameUtils.getComponentModelTypeName(org.mule.runtime.extension.api.util.NameUtils.getComponentModelTypeName) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) SourceCallbackModel(org.mule.runtime.api.meta.model.source.SourceCallbackModel) HashSet(java.util.HashSet) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 2 with SourceCallbackModel

use of org.mule.runtime.api.meta.model.source.SourceCallbackModel in project mule by mulesoft.

the class NameClashModelValidatorTestCase method sourceWithRepeatedParameterNameAmongCallbacks.

@Test
public void sourceWithRepeatedParameterNameAmongCallbacks() {
    SourceCallbackModel errorCallBack = mock(SourceCallbackModel.class);
    when(errorCallBack.getAllParameterModels()).thenReturn(asList(simpleConnectionProviderParam));
    when(sourceModel.getErrorCallback()).thenReturn(of(errorCallBack));
    SourceCallbackModel successCallback = mock(SourceCallbackModel.class);
    when(successCallback.getAllParameterModels()).thenReturn(asList(simpleConnectionProviderParam));
    when(sourceModel.getSuccessCallback()).thenReturn(of(successCallback));
    validate();
}
Also used : SourceCallbackModel(org.mule.runtime.api.meta.model.source.SourceCallbackModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with SourceCallbackModel

use of org.mule.runtime.api.meta.model.source.SourceCallbackModel in project mule by mulesoft.

the class NameClashModelValidatorTestCase method sourceWithRepeatedParameterNameAmongCallbackAndSource.

@Test
public void sourceWithRepeatedParameterNameAmongCallbackAndSource() {
    exception.expect(IllegalModelDefinitionException.class);
    ParameterModel offending = getParameter(SIMPLE_PARAM_NAME, String.class);
    SourceCallbackModel sourceCallbackModel = mock(SourceCallbackModel.class);
    mockParameters(sourceCallbackModel, simpleConfigParam);
    ParameterGroupModel group = mock(ParameterGroupModel.class);
    when(group.getName()).thenReturn(DEFAULT_GROUP_NAME);
    when(group.getModelProperty(ParameterGroupModelProperty.class)).thenReturn(empty());
    when(group.isShowInDsl()).thenReturn(false);
    when(group.getParameterModels()).thenReturn(asList(offending));
    SourceModel sourceModel = new ImmutableSourceModel(SOURCE_NAME, "", false, false, asList(group), emptyList(), null, null, of(sourceCallbackModel), empty(), empty(), false, false, false, null, SOURCE, emptySet(), emptySet(), emptySet());
    when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel));
    validate();
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ImmutableSourceModel(org.mule.runtime.extension.api.model.source.ImmutableSourceModel) ImmutableSourceModel(org.mule.runtime.extension.api.model.source.ImmutableSourceModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) SourceCallbackModel(org.mule.runtime.api.meta.model.source.SourceCallbackModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with SourceCallbackModel

use of org.mule.runtime.api.meta.model.source.SourceCallbackModel in project mule by mulesoft.

the class NameClashModelValidatorTestCase method sourceWithRepeatedParameterNameWithinCallback.

@Test
public void sourceWithRepeatedParameterNameWithinCallback() {
    exception.expect(IllegalModelDefinitionException.class);
    ParameterModel offending = getParameter(SIMPLE_PARAM_NAME, String.class);
    SourceCallbackModel sourceCallbackModel = mock(SourceCallbackModel.class);
    mockParameters(sourceCallbackModel, simpleConnectionProviderParam, offending);
    when(sourceModel.getErrorCallback()).thenReturn(of(sourceCallbackModel));
    validate();
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) SourceCallbackModel(org.mule.runtime.api.meta.model.source.SourceCallbackModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

SourceCallbackModel (org.mule.runtime.api.meta.model.source.SourceCallbackModel)4 Test (org.junit.Test)3 SmallTest (org.mule.tck.size.SmallTest)3 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)2 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)2 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Set (java.util.Set)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 ArrayType (org.mule.metadata.api.model.ArrayType)1 JAVA (org.mule.metadata.api.model.MetadataFormat.JAVA)1 MetadataType (org.mule.metadata.api.model.MetadataType)1 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)1 ObjectType (org.mule.metadata.api.model.ObjectType)1 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)1 NamedObject (org.mule.runtime.api.meta.NamedObject)1