Search in sources :

Example 1 with NestedComponentModel

use of org.mule.runtime.api.meta.model.nested.NestedComponentModel in project mule by mulesoft.

the class CoreExtensionModelTestCase method errorHandler.

@Test
public void errorHandler() {
    final ConstructModel errorHandlerModel = coreExtensionModel.getConstructModel("errorHandler").get();
    assertThat(errorHandlerModel.allowsTopLevelDeclaration(), is(true));
    assertThat(errorHandlerModel.getStereotype().getType(), is(ERROR_HANDLER.getType()));
    assertThat(errorHandlerModel.getAllParameterModels(), hasSize(1));
    ParameterModel ref = errorHandlerModel.getAllParameterModels().get(0);
    assertThat(ref.getName(), is("ref"));
    assertThat(ref.getType(), is(instanceOf(StringType.class)));
    assertThat(ref.getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(ref.isRequired(), is(false));
    assertThat(ref.getAllowedStereotypes(), hasSize(1));
    assertThat(ref.getAllowedStereotypes().iterator().next().getType(), is(ERROR_HANDLER.getType()));
    assertThat(errorHandlerModel.getNestedComponents(), hasSize(3));
    NestedRouteModel onErrorContinue = (NestedRouteModel) errorHandlerModel.getNestedComponents().get(0);
    verifyOnError(onErrorContinue);
    NestedRouteModel onErrorPropagate = (NestedRouteModel) errorHandlerModel.getNestedComponents().get(1);
    verifyOnError(onErrorPropagate);
    NestedComponentModel onErrorDelegate = (NestedComponentModel) errorHandlerModel.getNestedComponents().get(2);
    assertThat(onErrorDelegate.isRequired(), is(false));
    assertThat(onErrorDelegate.getAllowedStereotypes(), hasSize(1));
    assertThat(onErrorDelegate.getAllowedStereotypes().iterator().next().getType(), is(ON_ERROR.getType()));
    final ConstructModel onError = coreExtensionModel.getConstructModel("onError").get();
    List<ParameterModel> allParameterModels = onError.getAllParameterModels();
    assertThat(allParameterModels, hasSize(1));
    ParameterModel onErrorRef = allParameterModels.get(0);
    assertThat(onErrorRef.getName(), is("ref"));
    assertThat(onErrorRef.getType(), is(instanceOf(DefaultStringType.class)));
    assertThat(onErrorRef.isRequired(), is(true));
    assertThat(onErrorRef.getExpressionSupport(), is(NOT_SUPPORTED));
    assertThat(onErrorDelegate.getAllowedStereotypes(), hasSize(1));
    assertThat(onErrorDelegate.getAllowedStereotypes().iterator().next().getType(), is(ON_ERROR.getType()));
}
Also used : ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) Test(org.junit.Test)

Example 2 with NestedComponentModel

use of org.mule.runtime.api.meta.model.nested.NestedComponentModel in project mule by mulesoft.

the class CoreExtensionModelTestCase method flow.

@Test
public void flow() {
    final ConstructModel flow = coreExtensionModel.getConstructModel("flow").get();
    assertThat(flow.getStereotype().getType(), is(FLOW.getType()));
    assertThat(flow.allowsTopLevelDeclaration(), is(true));
    final List<ParameterModel> paramModels = flow.getAllParameterModels();
    assertThat(paramModels, hasSize(2));
    ParameterModel initialState = paramModels.get(0);
    assertThat(initialState.getName(), is("initialState"));
    assertThat(initialState.getDefaultValue(), is("started"));
    ParameterModel maxConcurrency = paramModels.get(1);
    assertThat(maxConcurrency.getName(), is("maxConcurrency"));
    List<? extends NestableElementModel> nestedComponents = flow.getNestedComponents();
    assertThat(nestedComponents, hasSize(3));
    NestableElementModel source = nestedComponents.get(0);
    assertThat(source.getName(), is("source"));
    assertThat(source.isRequired(), is(false));
    assertThat(source, instanceOf(NestedComponentModel.class));
    assertThat(((NestedComponentModel) source).getAllowedStereotypes(), contains(SOURCE));
    NestableElementModel chain = nestedComponents.get(1);
    assertThat(chain.getName(), is("processors"));
    assertThat(chain.isRequired(), is(true));
    assertThat(chain, instanceOf(NestedChainModel.class));
    assertThat(((NestedChainModel) chain).getAllowedStereotypes().stream().anyMatch(s -> s.getType().equals(PROCESSOR.getType())), is(true));
    NestableElementModel errorHandler = nestedComponents.get(2);
    assertThat(errorHandler.getName(), is("errorHandler"));
    assertThat(errorHandler.isRequired(), is(false));
    assertThat(errorHandler, instanceOf(NestedComponentModel.class));
    assertThat(((NestedComponentModel) errorHandler).getAllowedStereotypes(), contains(ERROR_HANDLER));
}
Also used : OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ErrorModelBuilder.newError(org.mule.runtime.api.meta.model.error.ErrorModelBuilder.newError) DefaultAnyType(org.mule.metadata.api.model.impl.DefaultAnyType) VoidType(org.mule.metadata.api.model.VoidType) Assert.assertThat(org.junit.Assert.assertThat) CPU_LITE(org.mule.runtime.api.meta.model.operation.ExecutionType.CPU_LITE) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) IsCollectionContaining.hasItem(org.hamcrest.core.IsCollectionContaining.hasItem) ArrayType(org.mule.metadata.api.model.ArrayType) TARGET_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME) ON_ERROR(org.mule.runtime.extension.api.stereotype.MuleStereotypes.ON_ERROR) SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.SUPPORTED) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) TypeIdAnnotation(org.mule.metadata.api.annotation.TypeIdAnnotation) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ObjectType(org.mule.metadata.api.model.ObjectType) REQUIRED(org.mule.runtime.api.meta.ExpressionSupport.REQUIRED) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) DefaultObjectType(org.mule.metadata.api.model.impl.DefaultObjectType) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) MuleManifest.getVendorName(org.mule.runtime.core.api.config.MuleManifest.getVendorName) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) StringType(org.mule.metadata.api.model.StringType) Matchers.contains(org.hamcrest.Matchers.contains) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) DefaultNumberType(org.mule.metadata.api.model.impl.DefaultNumberType) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FLOW(org.mule.runtime.extension.api.stereotype.MuleStereotypes.FLOW) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) MuleManifest.getProductVersion(org.mule.runtime.core.api.config.MuleManifest.getProductVersion) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) Matchers.arrayContainingInAnyOrder(org.hamcrest.Matchers.arrayContainingInAnyOrder) TARGET_VALUE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME) TRANSFORMATION(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.TRANSFORMATION) SOURCE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.SOURCE) COMMUNITY(org.mule.runtime.api.meta.Category.COMMUNITY) OBJECT_STORE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.OBJECT_STORE) Iterator(java.util.Iterator) ERROR_HANDLER(org.mule.runtime.extension.api.stereotype.MuleStereotypes.ERROR_HANDLER) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) DefaultBooleanType(org.mule.metadata.api.model.impl.DefaultBooleanType) Test(org.junit.Test) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) MULE_VERSION(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.MULE_VERSION) MuleExtensionModelProvider.getExtensionModel(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.getExtensionModel) PROCESSOR(org.mule.runtime.extension.api.stereotype.MuleStereotypes.PROCESSOR) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) MULE_NAME(org.mule.runtime.core.api.extension.MuleExtensionModelProvider.MULE_NAME) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) SubTypesModel(org.mule.runtime.api.meta.model.SubTypesModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)2 NestedComponentModel (org.mule.runtime.api.meta.model.nested.NestedComponentModel)2 NestedRouteModel (org.mule.runtime.api.meta.model.nested.NestedRouteModel)2 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)2 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Matchers.arrayContainingInAnyOrder (org.hamcrest.Matchers.arrayContainingInAnyOrder)1 Matchers.contains (org.hamcrest.Matchers.contains)1 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)1 Matchers.is (org.hamcrest.Matchers.is)1 IsCollectionWithSize.hasSize (org.hamcrest.collection.IsCollectionWithSize.hasSize)1 IsEmptyCollection.empty (org.hamcrest.collection.IsEmptyCollection.empty)1 IsCollectionContaining.hasItem (org.hamcrest.core.IsCollectionContaining.hasItem)1 Assert.assertThat (org.junit.Assert.assertThat)1 EnumAnnotation (org.mule.metadata.api.annotation.EnumAnnotation)1 TypeIdAnnotation (org.mule.metadata.api.annotation.TypeIdAnnotation)1 ArrayType (org.mule.metadata.api.model.ArrayType)1 ObjectType (org.mule.metadata.api.model.ObjectType)1